### Keras错误 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,~\anaconda3\envs\myenv\lib\site-packages\keras\__init__.py in <module>     19 """     20 # pylint: disable=unused-import---> 21 from tensorflow.python import tf2     22 from keras import distribute     23 ~\anaconda3\envs\myenv\lib\site-packages\tensorflow\__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 ~\anaconda3\envs\myenv\lib\site-packages\tensorflow\python\__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~\anaconda3\envs\myenv\lib\site-packages\tensorflow\python\keras\__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~\anaconda3\envs\myenv\lib\site-packages\tensorflow\python\keras\models.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~\anaconda3\envs\myenv\lib\site-packages\tensorflow\python\keras\engine\training_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~\anaconda3\envs\myenv\lib\site-packages\tensorflow\python\keras\engine\training_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~\anaconda3\envs\myenv\lib\site-packages\scipy\__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~\anaconda3\envs\myenv\lib\site-packages\scipy\_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)~\anaconda3\envs\myenv\lib\ctypes\__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 = handleOSError: [WinError 126] The specified module could not be found

这是我的代码。

## 使用Python和Keras进行数据增强## 什么是数据增强?## 在数据增强中,我们从一张图片创建更多的图片from keras.preprocessing.Image import ImageDataGenerator, array_to_img, img_to_array, load_imgdatagen = 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') ## 这是一个PIL图像x = img_to_array(img) ## 这是一个形状为(3,150,150)的numpy数组x = x.reshape((1,) + x.shape) ## 这是一个形状为(1,3,150,150)的numpy数组## 下面的.flow()命令生成一批随机变换的图像## 并将结果保存到'preview/'目录i=0for batch in datagen.flow(x, batch_size=1,                        save_to_dir='preview', save_prefix='dog',                        save_format='jpeg'):    i+=1    if i>20:        break # 否则生成器循环将无限进行

回答:

这对我来说会起作用

卸载Tensorflow和Keras,然后重新安装它们,答案在下面的链接中

查看stackoverflow.com/questions/53328808/… – 你的Tensorflow和Keras包组合有问题

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注