Grader is having an issue compiling my code

Every time I submit my code i get the result from the grader cack as “Grader output
Can’t compile the student’s code. load_data() got an unexpected keyword argument ‘path’”. This has not happened with any other lab, it is keeping me from passing the course.

Not sure what it means so I’m not sure how to address the issue.
Thank you

If you’ve not changed the path from where data is loaded, consider reaching out to coursera technical support.

Hi Ian,

I’ve bee checking the code for this assignment and I believe there could be an error.

Where it says:

    mnist = tf.keras.datasets.mnist
    (training_images, training_labels), (test_images, test_labels) = mnist.load_data(path=path)

it should rather say:

    mnist = tf.keras.datasets.mnist
    (training_images, training_labels), (test_images, test_labels) = mnist.load_data()

Would you mind give a try? If it works as expected, let me know and I’ll open an issue for this to be fixed.

Best,

Thank you for your response, but this did not fix my issue, the error has not changed with resubmission.

Hi @Ian_Kuhl,

Ummm…

Which TF version are you using? I’m testing with TF 2.6.0 and you need no path parameter.

You can try this as well:

mnist = tf.keras.datasets.mnist
    (training_images, training_labels), (test_images, test_labels) = mnist.load_data(path="mnist.npz")

Best,

Hi @german.mesa
Thanks so much but he new code also did not work
The importing tf automatically version 1.14.0 of tensorflow

thanks!

Hi @Ian_Kuhl,

I’m checking the assignment with your TF version and - with those changes I mentioned - work like a champ.

Changing:

mnist.load_data(path=path)

by

mnist.load_data()

should do the trick.

To be in the safe side, would you please paste your code for train_mnist_conv here so I could gave it a look?

Best,

Hi @german.mesa,
There is no change in the grader’s output when I implemented that change either. it still reads out “Can’t compile the student’s code. load_data() got an unexpected keyword argument ‘path’”.

This is the code I have been submitting repeatedly trying to get a different grader output:

GRADED FUNCTION: train_mnist_conv

def train_mnist_conv():
# Please write your code only where you are indicated.
# please do not remove model fitting inline comments.

# YOUR CODE STARTS HERE
class myCallback(tf.keras.callbacks.Callback):
    def on_epoch_end(self, epoch, logs={}):
        if(logs.get('accuracy') is not None and logs.get('accuracy')>0.998):
            print("good enough accuracy")
            self.model.stop_training =True
# YOUR CODE ENDS HERE




mnist = tf.keras.datasets.mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data(path=path)

# YOUR CODE STARTS HERE

mnist = tf.keras.datasets.fashion_mnist
(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train = x_train.reshape(60000, 28, 28, 1)
callbacks = myCallback()
x_train = x_train/255.0
x_test = x_test/255.0
# YOUR CODE ENDS HERE

model = tf.keras.models.Sequential([
    # YOUR CODE STARTS HERE
    tf.keras.layers.Conv2D(64, (3,3), activation ='relu', input_shape=(28, 28, 1)),
    tf.keras.layers.MaxPooling2D(2,2),
    
    tf.keras.layers.Flatten(input_shape=(28,28)),
    
    #tf.keras.layers.Dense(512, activation=tf.nn.relu),
    #tf.keras.layers.Dense(256, activation=tf.nn.relu),
    tf.keras.layers.Dense(64, activation=tf.nn.relu),
    
    tf.keras.layers.Dense(10, activation=tf.nn.softmax)
     # YOUR CODE ENDS HERE
])

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
# model fitting
history = model.fit(x_train, y_train, epochs=20, callbacks=[callbacks]
    # YOUR CODE STARTS HERE

    # YOUR CODE ENDS HERE
)
# model fitting
return history.epoch, history.history['acc'][-1]

Thank you for your continued support!
Ian Kuhl

Hi @Ian_Kuhl,

Ok, I see the issue now…

You need to define a variable path so you can use later in the call. Then, you define your callback function. Additionally, you don’t need to explicitly call for ending the process with:

self.model.stop_training =True

If you notice that callback function is not interrupting the flow, it’s because you need to replace “accuracy” by “acc”. This is related to the TF version and it’s already been commented in other areas in the wall.

Code would be then similar to:

# YOUR CODE STARTS HERE
class myCallback(tf.keras.callbacks.Callback):
    def on_epoch_end(self, epoch, logs={}):
        if(logs.get('acc') is not None and logs.get('acc')>0.998):
            print("good enough accuracy")

# Variable set to MNIST location
path="mnist.npz"

# YOUR CODE ENDS HERE

mnist = tf.keras.datasets.mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data(path=path)

# YOUR CODE STARTS HERE

Check the code after this change. You have already loaded the MNIST dataset and I can see other area where you load the dataset a second time. :wink:

Give it a try and let me know how it goes,

Best

I think there is also an issue with the input shape at the Flatten layer, the images are no longer 28,28,1 but should be 13,13,1 and does it not work also if you do not precise the input shape?
Thibaud