1
我無法從kerasKeras圖像數據生成器沒有發現文件發現錯誤?
import os
import keras as K
from keras.preprocessing.image import ImageDataGenerator
def save_images_from_generator(maximal_nb_of_images, generator):
nb_of_images_processed = 0
for x, _ in generator:
nb_of_images += x.shape[0]
if nb_of_images <= maximal_nb_of_images:
for image_nb in range(x.shape[0]):
your_custom_save(x[image_nb]) # your custom function for saving images
else:
break
Gen=ImageDataGenerator(featurewise_center=True,
samplewise_center=False,
featurewise_std_normalization=False,
samplewise_std_normalization=False,
zca_whitening=True,
rotation_range=90,
width_shift_range=0.2,
height_shift_range=0.1,
shear_range=0.5,
zoom_range=0.2,
channel_shift_range=0.1,
fill_mode='nearest',
cval=0.,
horizontal_flip=True,
vertical_flip=True,
rescale=None,
preprocessing_function=None)
if __name__ == '__main__':
save_images_from_generator(40,Gen.flow_from_directory('C:\\Users\\aanilil\\PycharmProjects\\untitled\\images_input', target_size=(150, 150),class_mode=None,save_prefix='augm',save_to_dir='C:\\Users\\aanilil\\PycharmProjects\\untitled\\im_output\\'))
輸出
Using TensorFlow backend.
Found 0 images belonging to 0 classes.
Found 0 images belonging to 0 classes.
Found 0 images belonging to 0 classes.
Found 0 images belonging to 0 classes.
Found 0 images belonging to 0 classes.
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.3.2\helpers\pydev\pydevd.py", line 1578, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.3.2\helpers\pydev\pydevd.py", line 1015, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.3.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/aanilil/PycharmProjects/untitled/generate_data_from_folder.py", line 35, in <module>
save_images_from_generator(40,Gen.flow_from_directory('C:\\Users\\aanilil\\PycharmProjects\\untitled\\images_input', target_size=(150, 150),class_mode=None,save_prefix='augm',save_to_dir='C:\\Users\\aanilil\\PycharmProjects\\untitled\\im_output\\'))
File "C:/Users/aanilil/PycharmProjects/untitled/generate_data_from_folder.py", line 7, in save_images_from_generator
for x, _ in generator:
File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\keras\preprocessing\image.py", line 727, in __next__
return self.next(*args, **kwargs)
File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\keras\preprocessing\image.py", line 950, in next
index_array, current_index, current_batch_size = next(self.index_generator)
File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\keras\preprocessing\image.py", line 710, in _flow_index
current_index = (self.batch_index * batch_size) % n
ZeroDivisionError: integer division or modulo by zero
運行簡單的數據生成代碼,當我做一個操作系統。 listdir同時我得到像這樣
os.listdir('C:\\Users\\aanilil\\PycharmProjects\\untitled\\images_input')
['download (1).png', 'download.jpg', 'download.png', 'images.jpg']
所以有輸入文件夾的圖像的輸出,它仍然拋出取出保存到任何文件錯誤發現