keras img_to_array()错误未知数据格式:无

时间:2019-03-19 10:56:43

标签: python keras

我正在尝试训练一个可以在此处找到的浅层CNN(错误引用的行#不会完全匹配)

https://github.com/whydna/Deep-Learning-For-Computer-Vision/blob/master/shallownet_animals.py

但是在运行时出现以下错误

 $ python shallownet_animals.py --dataset ../datasets/animals/
 Using TensorFlow backend.
 [INFO] loading images...
 Traceback (most recent call last):
   File "shallownet_animals.py", line 35, in <module>
     (data, labels) = sdl.load(imagePaths, verbose=500)
  File "/home/swartz/dev/dl4cv/SB_Code/chapter12-first_cnn/pyimagesearch/datasets/simpledatasetloader.py", line 34, in load
     image = p.preprocess(image)
  File "/home/swartz/dev/dl4cv/SB_Code/chapter12-first_cnn/pyimagesearch/preprocessing/imagetoarraypreprocessor.py", line 12, in preprocess
     return img_to_array(image, data_format=self.dataFormat)
  File "/usr/lib/python2.7/dist-packages/keras_preprocessing/image/utils.py", line 278, in img_to_array
     raise ValueError('Unknown data_format: %s' % data_format)
ValueError: Unknown data_format: None

iap = ImageToArrayPreprocessor()行在其初始设置中将默认数据格式设置为None

 class ImageToArrayPreprocessor:
     def __init__(self, dataFormat=None):
         # store the image data format
         self.dataFormat = dataFormat

所以这似乎是问题所在。但是,从我正在阅读的书中,这是有意为之的,因此Keras使用keras.json文件中的默认数据格式,在我的情况下为"image_data_format": "channels_last"。我的Keras版本是2.2.4。任何想法为什么这不起作用?任何帮助将不胜感激!

(而且:我已经将此文件与预先安装的CIFAR-10装载机cifar10.load_data()配合使用,所以我有一些生命力证明)

0 个答案:

没有答案