简体   繁体   中英

Keras Error OSError: [WinError 126] The specified module could not be found

I am learning deep learning, in this, I am learning data augmentation using python and Keras. Data Augmentation is used for creating more images from one image, so I write the below code it will give me the error I don't understand what is the error. can anyone tell me how to resolve this issue? below is the error

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 = handle

OSError: [WinError 126] The specified module could not be found

and this one is my code.

## 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

It will work for me

Uninstall the Tensorflow and Keras and install them again, the answer is in the below link

See stackoverflow.com/questions/53328808/… – you have a mixed-up constellation of Tensorflow and Keras packages

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM