Keras: TypeError: float() argument must be a string or a number error at generator_output = next(output_generator)

Created on 19 Aug 2017  路  2Comments  路  Source: keras-team/keras

I'm using ImageDataGenerator(rescale=0).flow_from_directory, Keras-2.0.6 and doing a finetuning in Imagenet without modifications. But the message is always StopIteration without any other information.

` File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(self.__args, *self.__kwargs)
File "/home/glauco/.local/lib/python2.7/site-packages/keras/utils/data_utils.py", line 568, in data_generator_task
generator_output = next(self._generator)
File "/home/glauco/.local/lib/python2.7/site-packages/keras/preprocessing/image.py", line 1034, in next
x = img_to_array(img, data_format=self.data_format)
File "/home/glauco/.local/lib/python2.7/site-packages/keras/preprocessing/image.py", line 290, in img_to_array
x = np.asarray(img, dtype=K.floatx())
File "/home/glauco/.local/lib/python2.7/site-packages/numpy/core/numeric.py", line 531, in asarray
return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number'

stale

All 2 comments

Hi @fchollet when the function load_img return a uncompleted image the x = np.asarray(img, dtype=K.floatx()) in function img_to_array broken.
https://github.com/fchollet/keras/blob/5e61e79ec59a098636b4fe87b1e67790b5c0b683/keras/preprocessing/image.py#L333

Images like that screen shot 2017-08-21 at 18 06 18 broke the execution, but not explicit the error. The image is not complete and generate the error. Send the original file of image there
7060201795_f182bd10a2_b-224x224_resized.jpeg.zip

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.

Was this page helpful?
0 / 5 - 0 ratings