简体   繁体   中英

Read data directly from folders for training in keras

I am doing super resolution with resnet in keras and I have split my data into train and test (70-30) and from the test data 20% for validation.i am trying to read the data with datagen.flow_from_directory but its showing 0 images for 0 classes .The main issue is i dont have classes. I only have high resolution images and low resolution images. The high resolution images goes to output and the low resolution images goes to input. How can i load the data without separating them in classess

from keras.preprocessing.image import ImageDataGenerator
import os

train_dir =  r'G:\\images\\train'

train_datagen = ImageDataGenerator(rescale=1./255)


train_generator = train_datagen.flow_from_directory(train_dir)

To resolve 0 images for 0 classes , notice that a common mistake is that the target folder you specify has no subdirectory . ImageDataGenerator splits data to classes, based on each subdirectory under the directory you specify as it's first argument. So, you should have at least one subdirectory under the target.

Furthermore, the generator should label them in order to feed them to your network. By default it uses categorical method as a 2D one-hot encoded labels. But if you want your labels in other ways, set class_mode argument. For example for autoencoders that inputs has no label, you should specify it as class_mode=input .

Base on the docs here , class_mode should be one of these:

  • categorical will be 2D one-hot encoded labels, (Default Mode)
  • binary will be 1D binary labels,
  • sparse will be 1D integer labels,
  • input will be images identical to input images (mainly used to work with autoencoders).
  • None , no labels are returned (the generator will only yield batches of image data, which is useful to use with model.predict() )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM