UPDATE 2 Finally problem solved
ImageDataGenerstion().flow_from_directory()
expect your data in a subdirectory. For example in my case: my data should be in "data/train/cotton/"
cotton directory and my path providing variable should look like trainPath = "data/train"
. It expect you to put each class data in different respective directory.
For more detail, visit first answer for this Question
UPDATE
Didn't got solution yet. Previously I was providing data path as data/train
, but actually it should be as data/train/
, so I'm changing it as mentioned here in question below.
Question
I'm training a keras image-processing model on custom data. I'm getting help from youtube , here in first tutorial it is just loading images, making batches using ImageDataGenerator().flow_from_directory()
and plotting images with label specified.
my code is
trainPath = "data/train/"
trainBatch = ImageDataGenerator().flow_from_director(directory=trainPath, target_size=(224,224), classes=["cotton"], batch_size=10)
imgs, lables = next(trainBatch)
When I execute last line, it gives error
imgs, lables = next(trainBatch)
Traceback (most recent call last):
File "C:\Users\Haier\AppData\Local\Programs\Python\Python36\lib\site-packages\IPython\core\interactiveshell.py", line 3296, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-20-4b8b727474cb>", line 1, in <module>
imgs, lables = next(trainBatch)
File "C:\Users\Haier\AppData\Local\Programs\Python\Python36\lib\site-packages\keras_preprocessing\image\iterator.py", line 100, in __next__
return self.next(*args, **kwargs)
File "C:\Users\Haier\AppData\Local\Programs\Python\Python36\lib\site-packages\keras_preprocessing\image\iterator.py", line 109, in next
index_array = next(self.index_generator)
File "C:\Users\Haier\AppData\Local\Programs\Python\Python36\lib\site-packages\keras_preprocessing\image\iterator.py", line 85, in _flow_index
current_index = (self.batch_index * self.batch_size) % self.n
ZeroDivisionError: integer division or modulo by zero
I got some understanding of error form stack overflow Question, here person asked question stated this error arise when you've empty data folder. But I've 36 images in my data folder.
What I thought is, it is not reaching or getting to my data/train
folder. What else should have done?
Your assistance will be great help for me.