Week 4: Handling Complex Images - Happy or Sad Dataset

The code works well in Jupyter NoteBook .

When uploaded to Coursea Platform, However I get the error: There was a problem compiling the code from your notebook. Details:
name ‘gen’ is not defined

Any recommendations?

Well, the error says the gen variable is not defined so I would start checking the ‘gen’ variable.

I checked with gen variable. I notebooks works well. However on coursea platform upload I received the error.

I tried different way including def gen(): no success. Are you able to provide best way to define “gen”. I see where person say : You need to define the variable inside the model function.

I am trying to figure out how do define ‘gen’ any reference material you can share.

from tensorflow.keras.preprocessing.image import ImageDataGenerator

GRADED FUNCTION: image_generator

def image_generator():

# 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="./data/",
                                                    target_size=(150, 150),
### END CODE HERE# Save your generator in a variable

return train_generator

gen= image_generator()

1 Like

Im not actually familiar with the assignment, I just pointed out what I saw from the error. But if somebody says it should be inside the model function then you should try and place it inside the function where the model is defined…

Also keep in mind as someone posted here that the coursera API’s might not be updated to the latest versions.

Still no success. Do you know the code to define “gen”.
I did everything right like the other users.
There was a problem compiling the code from your notebook. Details:
name ‘gen’ is not defined

Week 4: Handling Complex Images - Happy or Sad Dataset

Tried running it but I dont have the data folders. Why dont you do the entire assignment in the coursera environment instead of doing it on jupyter notebook then copying to coursera, if that’s what you are doing as far as I understand! Another option would be to reset your coursera notebook and redo the assignment, if you say you code is like everybody’s else then I would try resetting.

Thanks for your support. Solved.

This was the issue. Notebook metadata is corrupt. Please refresh your workspace and try again.
See Refresh your Lab Workspace section here
If you’ve already done this, contact coursera help

Please see this link to learn more about grader metadata.