我尝试使用3个标签对图像进行分类。训练样本为6000,验证样本包含5000个图像。批量大小为10,时期数为30。
在keras中执行代码时,在第一个纪元的训练期间,解释器在599/600步时给出以下错误。
以下是代码片段:
model.fit_generator(
train_generator,
steps_per_epoch=nb_train_samples // batch_size,
epochs=epochs,
validation_data=validation_generator,
validation_steps=nb_validation_samples // batch_size)
model.save_weights('weights_img.h5')
model.save('model_img.h5')
解释器出现以下错误:
599/600 [============================>.] - ETA: 0s - loss: 0.2541 - acc: 0.9122Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site- packages\keras\utils\data_utils.py", line 555, in get
inputs = self.queue.get(block=True).get()
File "C:\Program Files\Python36\lib\multiprocessing\pool.py", line 608, in get
raise self._value
File "C:\Program Files\Python36\lib\multiprocessing\pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "C:\Program Files\Python36\lib\site- packages\keras\utils\data_utils.py", line 392, in get_index
return _SHARED_SEQUENCES[uid][i]
File "C:\Program Files\Python36\lib\site- packages\keras\preprocessing\image.py", line 800, in __getitem__
return self._get_batches_of_transformed_samples(index_array)
File "C:\Program Files\Python36\lib\site- packages\keras\preprocessing\image.py", line 1148, in _get_batches_of_transformed_samples
interpolation=self.interpolation)
File "C:\Program Files\Python36\lib\site- packages\keras\preprocessing\image.py", line 355, in load_img
img = img.convert('RGB')
File "C:\Program Files\Python36\lib\site-packages\PIL\Image.py", line 877, in convert
self.load()
File "C:\Program Files\Python36\lib\site-packages\PIL\ImageFile.py", line 233, in load
"(%d bytes not processed)" % len(b))
OSError: image file is truncated (26 bytes not processed)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File ".\dataset.py", line 80, in <module>
validation_steps=nb_validation_samples // batch_size)
File "C:\Program Files\Python36\lib\site- packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Program Files\Python36\lib\site-packages\keras\models.py", line 1256, in fit_generator
initial_epoch=initial_epoch)
File "C:\Program Files\Python36\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Program Files\Python36\lib\site-packages\keras\engine\training.py", line 2195, in fit_generator
workers=0)
File "C:\Program Files\Python36\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Program Files\Python36\lib\site- packages\keras\engine\training.py", line 2310, in evaluate_generator
generator_output = next(output_generator)
File "C:\Program Files\Python36\lib\site-packages\keras\utils\data_utils.py", line 561, in get
six.raise_from(StopIteration(e), e)
File "<string>", line 3, in raise_from
StopIteration: image file is truncated (26 bytes not processed)