I am using flow_from_directory
in ImageDataGenerator
from keras
to train my convolution neural network. I downloaded the ILSVRC2012 images from this link and I am trying to train and validate my network. The training folder has images categorized in corresponding folders, but the validation images are not categorized into folders, which is not letting me use flow_from_directory
to test the validation accuracy. Is there any easy way of categorizing the validation data into corresponding folders?

- 879
- 2
- 9
- 19
3 Answers
I tried with the below link of git code.
- https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh
- https://github.com/pytorch/examples/tree/master/imagenet
This shell script worked for me to convert validation directory into sub directories where images categorized into corresponding folders. Try to convert your validation directory into respective images categorized directories and give that parent directory of subdirectories as input to your code.
Thanks

- 1,303
- 1
- 7
- 13
You can use the libraries mxnet and gluon to classify the imagenet validation data in respective folders.
See https://gluon-cv.mxnet.io/build/examples_datasets/imagenet.html.
Then yuo can use the keras validation data generator.

- 11
- 2
-
Add the relevant content from the link to your answer to help clarify your solution. – Grant Miller Jun 15 '18 at 02:33
I'm doing a finetuning in two classes, first you need create something like that in your code
path_directory = "../images/"
path_classes_name = ['class_0','class_2',...,'class_999']
full list in order
image.ImageDataGenerator(rescale=0).flow_from_directory(path_directory, target_size=(244, 244), batch_size= 128, class_mode='categorical', shuffle=True,classes=path_classes_name)
after this the path_directory
need by organized exactly the blog.keras say. Keras will make the magic for you!
Tip: Don't forget then create the folders in order and with synset
name (something like n04111531
)! Not the name literal of classes =]

- 1
- 1

- 27
- 4
-
My training images are already categorized into folders (like `n02231487`) and I am using `train_generator = train_datagen.flow_from_directory('.imagenet/train', target_size=(224,224), batch_size=100, class_mode='categorical')` for training. But the validation data is not classified into folders. They are present as individual images (like `ILSVRC2012_val_00016633.JPEG`). I need to classify them in respective folders to create a validation data generator. – Prabaha Jul 25 '17 at 15:53
-
The data was download from this file http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_img_train.tar ?because the classes is sliced in subtars files when I downloaded the file. Then you can unpack safely and not mix the files – Glauco Roberto Jul 26 '17 at 16:32
-
I know that. But the [validation images](http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_img_val.tar) are not categorized. I need them categorized. – Prabaha Jul 26 '17 at 18:11