Keras Error OSError: [WinError 126]指定的模块无法找到



我正在学习深度学习,在这里,我正在学习使用python和Keras进行数据增强。数据增强用于从一个图像创建更多的图像,所以我写下面的代码,它会给我错误,我不明白什么是错误。谁能告诉我如何解决这个问题?下面是错误

OSError: [WinError 126] The specified module could not be found
OSError                                   Traceback (most recent call last)
<ipython-input-4-c3f56c851248> in <module>
4 ## In data augmentation we create more images from one image
5 
----> 6 from keras.preprocessing.Image import ImageDataGenerator, array_to_img, img_to_array, load_img
7 datagen = imageDataGenerator(
8     rotation_range=40,
~anaconda3envsmyenvlibsite-packageskeras__init__.py in <module>
19 """
20 # pylint: disable=unused-import
---> 21 from tensorflow.python import tf2
22 from keras import distribute
23 
~anaconda3envsmyenvlibsite-packagestensorflow__init__.py in <module>
39 import sys as _sys
40 
---> 41 from tensorflow.python.tools import module_util as _module_util
42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
43 
~anaconda3envsmyenvlibsite-packagestensorflowpython__init__.py in <module>
46 from tensorflow.python import data
47 from tensorflow.python import distribute
---> 48 from tensorflow.python import keras
49 from tensorflow.python.feature_column import feature_column_lib as feature_column
50 from tensorflow.python.layers import layers
~anaconda3envsmyenvlibsite-packagestensorflowpythonkeras__init__.py in <module>
23 
24 # See b/110718070#comment18 for more details about this import.
---> 25 from tensorflow.python.keras import models
26 
27 from tensorflow.python.keras.engine.input_layer import Input
~anaconda3envsmyenvlibsite-packagestensorflowpythonkerasmodels.py in <module>
23 from tensorflow.python.keras.engine import sequential
24 from tensorflow.python.keras.engine import training
---> 25 from tensorflow.python.keras.engine import training_v1
26 from tensorflow.python.keras.engine.base_layer import AddMetric
27 from tensorflow.python.keras.engine.base_layer import Layer
~anaconda3envsmyenvlibsite-packagestensorflowpythonkerasenginetraining_v1.py in <module>
44 from tensorflow.python.keras.engine import base_layer
45 from tensorflow.python.keras.engine import training as training_lib
---> 46 from tensorflow.python.keras.engine import training_arrays_v1
47 from tensorflow.python.keras.engine import training_distributed_v1
48 from tensorflow.python.keras.engine import training_eager_v1
~anaconda3envsmyenvlibsite-packagestensorflowpythonkerasenginetraining_arrays_v1.py in <module>
35 
36 try:
---> 37   from scipy.sparse import issparse  # pylint: disable=g-import-not-at-top
38 except ImportError:
39   issparse = None
~anaconda3envsmyenvlibsite-packagesscipy__init__.py in <module>
134 
135     # Allow distributors to run custom init code
--> 136     from . import _distributor_init
137 
138     from scipy._lib import _pep440
~anaconda3envsmyenvlibsite-packagesscipy_distributor_init.py in <module>
57             os.chdir(libs_path)
58             for filename in glob.glob(os.path.join(libs_path, '*dll')):
---> 59                 WinDLL(os.path.abspath(filename))
60         finally:
61             os.chdir(owd)
~anaconda3envsmyenvlibctypes__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
362 
363         if handle is None:
--> 364             self._handle = _dlopen(self._name, mode)
365         else:
366             self._handle = handle
OSError: [WinError 126] The specified module could not be found

这是我的代码。

## Data Augmentation using python and keras
## What is data Augmentation??
## In data augmentation we create more images from one image
from keras.preprocessing.Image import ImageDataGenerator, array_to_img, img_to_array, load_img
datagen = imageDataGenerator(
rotation_range=40,
widht_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest')
img = load_img('Deep learning/CNN Work/Data Augmentation using python and keras/2.jpg') ## This is a PIL Image
x = img_to_array(img) ## this is a numpy array with shape(3,150,150)
x = x.reshape((1,) + x.shape) ## this is a numpy array with shape(1,3,150,150)

## The .floe() command below generates batches of randomly transformed images
## and save the result to the 'preview/' directory 
i=0
for batch in datagen.flow(x, batch_size=1,
save_to_dir='preview', save_prefix='dog',
save_format='jpeg'):
i+=1
if i>20:
break # otherwise the generator loop would indefinitely

它会为我工作

卸载Tensorflow和Keras并重新安装,答案在下面的链接

参见stackoverflow.com/questions/53328808/…-你有一个混合的Tensorflow和Keras包的星座

最新更新