ImportError:无法导入名称get_uid 2

时间:2017-10-15 17:49:26

标签: python keras

我正在使用Python 2.7,使用keras 1.2.2

from sklearn.datasets import load_files   
import numpy as np
from keras.utils import np_utils
from glob import glob

# define function to load train, test, and validation datasets
def load_dataset(path):
    data = load_files(path)
    dog_files = np.array(data['filenames'])
    dog_targets = np_utils.to_categorical(np.array(data['target']), 133)
    return dog_files, dog_targets

# load train, test, and validation datasets
train_files, train_targets = load_dataset('dogImages/train')
valid_files, valid_targets = load_dataset('dogImages/valid')
test_files, test_targets = load_dataset('dogImages/test')

# load list of dog names
dog_names = [item[20:-1] for item in sorted(glob("dogImages/train/*/"))]

# print statistics about the dataset
print('There are %d total dog categories.' % len(dog_names))
print('There are %d total dog images.\n' % len(np.hstack([train_files, valid_files, test_files])))
print('There are %d training dog images.' % len(train_files))
print('There are %d validation dog images.' % len(valid_files))
print('There are %d test dog images.'% len(test_files))

我收到以下错误:

ImportErrorTraceback (most recent call last)
<ipython-input-10-c760281b33b0> in <module>()
      1 from sklearn.datasets import load_files
      2 import numpy as np
----> 3 from keras.utils import np_utils
      4 from glob import glob
      5 

C:\Users\ElPanda\Anaconda2\lib\site-packages\keras\__init__.py in <module>()
      1 from __future__ import absolute_import
----> 2 from . import backend
      3 from . import datasets
      4 from . import engine
      5 from . import layers

C:\Users\ElPanda\Anaconda2\lib\site-packages\keras\backend\__init__.py in <module>()
      8 from .common import set_epsilon
      9 from .common import set_floatx
---> 10 from .common import get_uid
     11 from .common import cast_to_floatx
     12 from .common import image_dim_ordering

ImportError: cannot import name get_uid

我没有看到任何类似的问题,比如适当的答案。任何帮助都会很棒,会在你的婚礼上演奏口琴!

1 个答案:

答案 0 :(得分:0)

我遇到了类似的错误。如果使用tensorflow,它可能与后端的tensorflow版本有关。以下版本对我有用。

Python ver 2.7

Keras ver 1.2.2

Tensorflow ver 1.3.0

Tensorflow ver 1.4.0在我的情况下不起作用。