我尝试过转学,然后我得到了#34;没有属性' image_data_generator'"错误。这个错误意味着什么?
您可以通过以下方式重现我的错误。
*重现步骤
$ cd /tmp
$ git clone --branch no-attribute-error https://github.com/y-zono/btc-bch-ml.git
$ cd btc-bch-ml
$ docker build -t model-builder .
$ docker run -v /tmp/btc-bch-ml/docker:/docker -d -it model-builder
$ docker exec -it CONTAINER_ID /bin/bash
# cd /docker
# python3 ./train-predict.py
Traceback (most recent call last):
File "./train-predict.py", line 62, in <module>
history = model.fit_generator(img_itr_train, steps_per_epoch=steps_per_epoch, epochs=n_epoch)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/_impl/keras/engine/training.py", line 1598, in fit_generator
initial_epoch=initial_epoch)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/_impl/keras/engine/training_generator.py", line 162, in fit_generator
generator_output = next(output_generator)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/_impl/keras/utils/data_utils.py", line 613, in get
six.raise_from(StopIteration(e), e)
File "<string>", line 3, in raise_from
StopIteration: 'ImageDataGenerator' object has no attribute 'image_data_generator'
*注
Tensorflow版本是&#34; tensorflow-1.8.0&#34;
我将所有代码和培训数据发布到github中。
https://github.com/y-zono/btc-bch-ml/blob/no-attribute-error/docker/train-predict.py#L62
答案 0 :(得分:2)
当使用tensorflow1.8时,出现了同样的错误。如果删除传递给ImageDatagenerator的预处理功能,则您的代码可以使用,但是,您必须以其他方式对图像进行预处理。
答案 1 :(得分:1)
更改
idg_train = ImageDataGenerator(rescale=1/255.,
shear_range=0.1,
zoom_range=0.1,
horizontal_flip=True,
preprocessing_function=preprocess_input)
到
idg_train = ImageDataGenerator(rescale=1/255.,
shear_range=0.1,
zoom_range=0.1,
horizontal_flip=True)
答案 2 :(得分:0)
我想我已经解决了你的问题。由于其中一个import语句,因此发生此问题。我建议你更换
from tensorflow.python.keras.applications.resnet50 import preprocess_input
到
from keras.preprocessing.image import ImageDataGenerator
这在我尝试的时候有效。如果你还面临问题,请告诉我。
答案 3 :(得分:0)
我在tensorflow-1.8.0中遇到了相同的问题。最快的方法是创建一个包含您的预处理功能的空类,并将其传递给ImageDataGenerator实例的image_data_generator对象:
def preprocess_input(im_array):
return im_array/255-.5
class foo(object):
pass
imgen = ImageDataGenerator(preprocessing_function='pass anything')
imgen.image_data_generator = foo
imgen.image_data_generator.preprocessing_function = preprocess_input
flowgen = imgen.flow_from_directory('/tmp/training_folder/')
flowgen.__getitem__(0)[0] #check result
另一种解决方法是通过删除tensorflow/python/keras/_impl/keras/preprocessing/image.py
第672行来修复image_data_generator
中的源代码