from keras.preprocessing.image import ImageDataGenerator
test_datagen = ImageDataGenerator(rescale=1. / 255)
test_gen = test_datagen.flow_from_directory(test_dir,
target_size=target_size,
batch_size=batch_size,
class_mode='binary')
model = #defined elsewhere
model.evaluate_generator(test_gen)
Results in the exception:
TypeError Traceback (most recent call last)
~\.virtualenvs\ML-WTkM-kxU\lib\site-packages\keras\utils\data_utils.py in get(self)
577 while self.is_running():
--> 578 inputs = self.queue.get(block=True).get()
579 self.queue.task_done()
C:\Python36\Lib\multiprocessing\pool.py in get(self, timeout)
643 else:
--> 644 raise self._value
645
C:\Python36\Lib\multiprocessing\pool.py in worker(inqueue, outqueue, initializer, initargs, maxtasks, wrap_exception)
118 try:
--> 119 result = (True, func(*args, **kwds))
120 except Exception as e:
~\.virtualenvs\ML-WTkM-kxU\lib\site-packages\keras\utils\data_utils.py in get_index(uid, i)
400 """
--> 401 return _SHARED_SEQUENCES[uid][i]
402
~\.virtualenvs\ML-WTkM-kxU\lib\site-packages\keras_preprocessing\image.py in __getitem__(self, idx)
1262 self.batch_size * (idx + 1)]
-> 1263 return self._get_batches_of_transformed_samples(index_array)
1264
~\.virtualenvs\ML-WTkM-kxU\lib\site-packages\keras_preprocessing\image.py in _get_batches_of_transformed_samples(self, index_array)
1734 interpolation=self.interpolation)
-> 1735 x = img_to_array(img, data_format=self.data_format)
1736 params = self.image_data_generator.get_random_transform(x.shape)
~\.virtualenvs\ML-WTkM-kxU\lib\site-packages\keras_preprocessing\image.py in img_to_array(img, data_format)
409 # but original PIL image has format (width, height, channel)
--> 410 x = np.asarray(img, dtype=backend.floatx())
411 if len(x.shape) == 3:
~\.virtualenvs\ML-WTkM-kxU\lib\site-packages\numpy\core\numeric.py in asarray(a, dtype, order)
491 """
--> 492 return array(a, dtype, copy=False, order=order)
493
TypeError: float() argument must be a string or a number, not 'JpegImageFile'
The above exception was the direct cause of the following exception:
StopIteration Traceback (most recent call last)
<ipython-input-4-162faf28a7af> in <module>()
----> 1 model.evaluate_generator(test_gen)
~\.virtualenvs\ML-WTkM-kxU\lib\site-packages\keras\legacy\interfaces.py in wrapper(*args, **kwargs)
89 warnings.warn('Update your `' + object_name +
90 '` call to the Keras 2 API: ' + signature, stacklevel=2)
---> 91 return func(*args, **kwargs)
92 wrapper._original_function = func
93 return wrapper
~\.virtualenvs\ML-WTkM-kxU\lib\site-packages\keras\engine\training.py in evaluate_generator(self, generator, steps, max_queue_size, workers, use_multiprocessing, verbose)
1478 workers=workers,
1479 use_multiprocessing=use_multiprocessing,
-> 1480 verbose=verbose)
1481
1482 @interfaces.legacy_generator_methods_support
~\.virtualenvs\ML-WTkM-kxU\lib\site-packages\keras\engine\training_generator.py in evaluate_generator(model, generator, steps, max_queue_size, workers, use_multiprocessing, verbose)
307
308 while steps_done < steps:
--> 309 generator_output = next(output_generator)
310 if not hasattr(generator_output, '__len__'):
311 raise ValueError('Output of generator should be a tuple '
~\.virtualenvs\ML-WTkM-kxU\lib\site-packages\keras\utils\data_utils.py in get(self)
582 except Exception as e:
583 self.stop()
--> 584 six.raise_from(StopIteration(e), e)
585
586 def _send_sequence(self):
~\.virtualenvs\ML-WTkM-kxU\lib\site-packages\six.py in raise_from(value, from_value)
StopIteration: float() argument must be a string or a number, not 'JpegImageFile'
@dareal-andre I had the same error. It was because one of my jpeg images was corrupt. Not a problem with keras (other than hard to decode error message).
Try $ jpeginfo -c /image/folder/path/*.jpg | grep 'WARNING' to find corrupt images.
My Images are all OK, I am still getting this error please help!
I have the same issue, but with 'TiffImageFile'. My script runs in one anaconda environment, but not in another. The keras version is 2.1.5 in both environments, tensorflow is 1.05 in the 'good' environment, 1.10 in the 'bad' environment. I'm sure there are other differences between the two environments.
TypeError: float() argument must be a string or a number, not 'TiffImageFile'
I am facing this type of problem? How did you people solve it? I think it is similar types of error
I have the same issue, but with 'TiffImageFile'. My script runs in one anaconda environment, but not in another. The keras version is 2.1.5 in both environments, tensorflow is 1.05 in the 'good' environment, 1.10 in the 'bad' environment. I'm sure there are other differences between the two environments.
did you solve it? I am facing same problem.
No, unfortunately the only way for me is to clone the good environment.
On Sun, Feb 16, 2020, 08:22 Chiranjibi Sitaula notifications@github.com
wrote:
I have the same issue, but with 'TiffImageFile'. My script runs in one
anaconda environment, but not in another. The keras version is 2.1.5 in
both environments, tensorflow is 1.05 in the 'good' environment, 1.10 in
the 'bad' environment. I'm sure there are other differences between the two
environments.did you solve it? I am facing same problem.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/keras-team/keras/issues/10668?email_source=notifications&email_token=ANN2EKBDCA7F3HTJIGTFUDDRDDSTHA5CNFSM4FJZZMHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL37V4Q#issuecomment-586676978,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ANN2EKDRZSVEYPVUQUS6WLLRDDSTHANCNFSM4FJZZMHA
.
Most helpful comment
@dareal-andre I had the same error. It was because one of my jpeg images was corrupt. Not a problem with keras (other than hard to decode error message).
Try
$ jpeginfo -c /image/folder/path/*.jpg | grep 'WARNING'to find corrupt images.