I am helpless no one is helping me please help me with which directory do i need to use i feel helpless

hey can you please help me with which directory to i need to enter over here as i cannot understand it at all i am trying it for a long time and my whole course is complete and whole code is done
i just cannot figure out which directory do i need to use
no one is helping me and i just feel helpless

from tensorflow.keras.preprocessing.image import ImageDataGenerator

GRADED FUNCTION: image_generator

def image_generator():
### START CODE HERE

# Instantiate the ImageDataGenerator class.
# Remember to set the rescale argument.
train_datagen = ImageDataGenerator(rescale=1/255)

# Specify the method to load images from a directory and pass in the appropriate arguments:
# - directory: should be a relative path to the directory containing the data
# - targe_size: set this equal to the resolution of each image (excluding the color dimension)
# - batch_size: number of images the generator yields when asked for a next batch. Set this to 10.
# - class_mode: How the labels are represented. Should be one of "binary", "categorical" or "sparse".
#               Pick the one that better suits here given that the labels are going to be 1D binary labels.
train_generator = train_datagen.flow_from_directory(directory=,
                                                    target_size=(150, 150),
                                                    batch_size=128,
                                                    class_mode='binary')
### END CODE HERE

return train_generator

please help me with the name of the directory i need to use so the code is functional

Notice that the inline documentation for directory describes the parameter as a relative path to the directory containing the data

That means relative to the directory where the Python code is being executed. If you use the File-Open menu option on the notebook you should be able to find the data directory. Relative means the path description will start with ./ with the dot standing for current working directory.

1 Like

Hi @ARNAV_BATRA , in addition to what @ai_curious said, you can add a print (just for debug) inside your image_generator() function with two variables: one that shows the current path and the other with the directory value you are passing. Comparing the two variables, you can see if the directory argument is correct. Please, after fixed, don’t forget to remove the print.

1 Like

there are 2 directories given 1 for happy 1 for sad which one should i use
its like this

from tensorflow.keras.preprocessing.image import load_img

happy_dir = “./data/happy/”
sad_dir = “./data/sad/”

print(“Sample happy image:”)
plt.imshow(load_img(f"{os.path.join(happy_dir, os.listdir(happy_dir)[0])}"))
plt.show()

print("\nSample sad image:")
plt.imshow(load_img(f"{os.path.join(sad_dir, os.listdir(sad_dir)[0])}"))
plt.show()

which one sshould i enter

@ai_curious please guide me

there are 2 directories given 1 for happy 1 for sad which one should i use
its like this

from tensorflow.keras.preprocessing.image import load_img

happy_dir = “./data/happy/”
sad_dir = “./data/sad/”

print(“Sample happy image:”)
plt.imshow(load_img(f"{os.path.join(happy_dir, os.listdir(happy_dir)[0])}"))
plt.show()

print("\nSample sad image:")
plt.imshow(load_img(f"{os.path.join(sad_dir, os.listdir(sad_dir)[0])}"))
plt.show()

which one sshould i enter

Maybe you should review the ImageDataGenerator lecture video. https://www.coursera.org/learn/introduction-tensorflow/lecture/kqRHk/understanding-imagedatagenerator

Note at the 1:00 mark where he says “… One feature of the image generator is that you can point it at a directory and then the sub-directories of that will automatically generate labels for you.”

Seems like that could prove useful here…

See also the TF documentation at

tf.keras.preprocessing.image.ImageDataGenerator  |  TensorFlow Core v2.8.0 and the script linked from that page Updated to the Keras 2.0 API. · GitHub

what both mentors meant that if you open the file section === open===then === data===happy and sad.

So this means your directory is data and that should be your directory code.

even I am student like you, and I tried with different codes and eventually got the answer.

Hope it helps!!! Happy learning