-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
flow_from_directory seems to find no images #3946
Comments
My entire bad. Completely forgot to create subdirs. Found my error exploring the source code of Directory Iterator class. |
I'm having this problem now...How did you fix it? what was the problem wrt subdirs? UPDATE: Also fixed it through subdirs. The path needs to be to a folder (that contains the images) as opposed to directly to the images. Just in case some one else googles this. |
How did you solve it? My path is already a folder; what do you mean? |
The path needs to be to a folder, that contains folders, that contains the images. |
I have it in a folder that contains folders of pictures. Still, it doesn't read my image. Why is that? |
look carefully at the file structure in the beginning of https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html. good luck! |
Ok, thank you. I fixed it. Now, I get this error: "model.fit_generator(
|
follow the instructions in the link i sent. as the error suggests, you need to compile the model before you can train it(i,e give the net the settings under which to train). |
Yes, I followed all the instructions on the link but still I get this error. Here is my code: from keras.models import Sequential import numpy as np model = Sequential() model.add(Convolution2D(32, 3, 3, border_mode='valid', dim_ordering='tf', input_shape=(150, 200, 4))) model.add(Convolution2D(64, 3, 3, border_mode='valid')) model.add(Flatten()) train_datagen = ImageDataGenerator( test_datagen = ImageDataGenerator(rescale=1./255) train_generator = train_datagen.flow_from_directory( validation_generator = test_datagen.flow_from_directory( model.fit_generator(train_generator, 12, 1, validation_generator, 4) model.save_weights('thesis.h5') # always save your weights after training or during training Where's the problem? How can I give the net the settings beforehand? |
@zahrasorour , you need to compile the model using model.compile before |
Getting the same issue (using Keras and Tensorflow), any help would be greatly appreciated. My directory is set to be folder/folder/images - for both training and testing data. I made a loop to test the different depths/nb_layers in a Resnet, as well as some hyper parameters like learning rate, batch size, etc. The test went from 4, 6, 8, 10 - all the way to 20, then gave me output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None I don't understand why it can work for a handful of the iterations, then fail. I read here to update keras to 2.0, but was told not to change the version of keras by my boss. I read here to convert all labels to a numpy array, but keras documentation states this already happens to labels while using the 'categorical' attribute in flow_from_directory Then I read here to put my train_generator in a function, then create an infinite while loop and yield the results, but this results in the data to be loaded over and over at the start of the program. "Found 350 images belonging to 7 classes" (repeated 10 times), which then results in an error "output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: <keras.preprocessing.image.DirectoryIterator object at 0x0000000063494BE0>" Here's my stack trace for the original error: Traceback (most recent call last): File "", line 1, in File "C:\Users\paul\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile File "C:\Users\paul.\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 89, in execfile File "K:/Manufacturing Operations/Yield/Tools_Yield/PythonScripts/AI/ISL_DI/Resnet/resISL_Depth.py", line 233, in File "C:\Users\paul\AppData\Roaming\Python\Python35\site-packages\keras\engine\training.py", line 1481, in fit_generator ValueError: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None Here's the code other than vars `rep=0 for i in range(retrainings + 1):
|
Maybe someone needs this, it took me quite a lot to find out:
Add 'gif' and it will work smooth. |
Thank you @HectorAnadon . |
import keras validation_generator = test_datagen.flow_from_directory( |
Hi @Hs1000 !!
Also for deep dive, one must remember that ImageDataGenerator.flow_from_directory was created keeping in mind the good ol' image classification problem. So flow_from_directory() receives a folder name where different folder resides containing the images(traversal of nested sub directories). What most people tend to do is directly pass the the folder which contains the images. Happy Coding!! |
To anyone coming here from Google because you're using
|
Thank you for replying i need to know how i can display or predict the
image whose path i had provided
…On Wed, Jun 27, 2018 at 10:57 AM, Adamya Tripathi ***@***.***> wrote:
Hi @Hs1000 <https://github.com/Hs1000> !!
I guess your path( "C:\Users\user\Downloads\Research\New folder") has the
images.
You need to get those images and store it in a new folder inside the 'New
Folder' so your path must look like - C:\Users\user\Downloads\Research\New
folder\Sub_Dir_Containing_Images' . Then you must pass the same path
again. Remember don't change the path!
validation_generator = test_datagen.flow_from_directory(
r'C:\Users\user\Downloads\Research\New folder', ## No change in the path
target_size=(28,28),
batch_size=32,
class_mode='binary')
Also for deep dive, one must remember that
*ImageDataGenerator.flow_from_directory* was created keeping in mind the
good ol' image classification problem. So *flow_from_directory()*
receives a folder name where different folder resides containing the
images(traversal of nested sub directories). What most people tend to do is
directly pass the the folder which contains the images.
Happy Coding!!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3946 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AkSY7FrdYAZLUg5Ew3kqM9m59WL-FcgCks5uAxevgaJpZM4KMgpW>
.
|
how come they don't give the option to manipulate this list and that gif is not there by default? |
for anaconda users, please dont do this in tensorflow/keras folder but in keras' own folder, this happens when you're too lazy to check and search using windows search finally, this won't solve the problem completely, gif is a 1 channel image, but keras is still reading it as 3 channel image, which create problem for targets of binary masks |
!mkdir '/content/train/'dog |
I almost pulled all my hairs out for this error and it turns out it needed a new folder inside the given directory. |
How did i solve it? My path is already a folder.I have it in a folder that contains folders of pictures. Still, it doesn't read my image. Why is that? train_path = 'D:\data\Train_Data\egg' Found 0 images belonging to 106 classes. |
It doesn't work in google colab. It gives me you have 0 images but when the directory with images exist |
I have the message shows that the image found, and I set the save_to_dir. but I found nothing in my save_to_dir that I set! how could that happen? |
Thanks for the clear explanation |
Does this work with any file extension. Tried reading .pgm images but got the error This works fine with .jpg images |
I think this should be fixed: when labels are passed manually with a list, it should not expect a folder that contains a folder with the images. Instead it should just be the specified folder |
True got it sorted this way only was struggling for past 2 days |
train_dir="WarsawDataSet\train" learning_rate = 0.0001 train_datagen = ImageDataGenerator(
train_dataset = train_datagen.flow_from_directory(
val_dataset = validation_datagen.flow_from_directory( Not able to access images .Dont understand whts going wrong . Plz help me resolve this |
Try giving path till \DataSet, also just fiddle a bit with folder structure and the path you give, you'll get it eventually, and check version of keras this is a really old thread |
Traceback (most recent call last): I'm getting this error , i'm not able to find this error |
from keras.models import Sequential train_data_dir = 'data/train' train_generator = train_datagen.flow_from_directory( val_generator = val_datagen.flow_from_directory( emotion_model = Sequential() emotion_model.add(Conv2D(32, kernel_size=(3,3), activation='relu', input_shape = (48,48,1))) emotion_model.add(Conv2D(128, kernel_size=(3,3), activation='relu')) emotion_model.add(Flatten()) emotion_model.compile(loss='categorical_crossentropy',optimizer=Adam(lr=0.0001, decay=1e-6),metrics=['accuracy']) emotion_model_info = emotion_model.fit_generator( emotion_model.save_weights('model.h5') this is my code |
Hello
I'm running into this issue using the latest version of Keras (1.1.0). I also tried to use version 1.0.0 and 1.0.1 and it's the same.
Whenever I try to use the data augmentation ImageDataGenerator, it seems that the method flow_from_directory can't find any image in my folders.
Here's my model code:
Here's my data augmentation code: (error is located here)
I followed this tutorial (even corrected some mistakes with the dimension ordering)
https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html
After solving a lot of errors, I'm stuck to the point where the method flow_ffrom_directory finds no image in my folders, thus generating a null output:
I even tried to modify the number of images in my folder but there seems to be nothing I could do.
The text was updated successfully, but these errors were encountered: