Callback Assignment

Hello. When I run by callback, the return history code is giving me SyntaxError: ‘return’ outside function. Can someone please help me on what I am doing wrong. My callback is giving me Reached 99% accuracy so cancelling training! but I have a problem with the return history.

Thank you

1 Like

Hi @Philani_Hlophe

Welcome to the community.

What course are you attending to?

1 Like

Hello Elirod.

Introduction to TensorFlow for Artificial Intelligence, Machine Learning, and Deep Learning

1 Like

Thanks for the update.

I’ll move your query to the right space in order to you to get a proper support.

1 Like

Can you share the screenshot of the error you are getting. Do not share any part of the grader code.

1 Like

Hi @Philani_Hlophe
Thanks for posting,
As other mentors mentioned, please share a screen shot and/or the lab that you are trying to do so we can better guide you through it.


1 Like

Thanks for the help @Deepti_Prasad

1 Like

Hello Philani,

history =])

and then run model training.(also remove that print(history))

Also kindly remove that image as that has grader code used for assignment assessment and sharing that on public post would be against community guideline for Code of Conduct.


1 Like

Happy to help!! Elirod.


1 Like

Hello Deepti_Prasad.

Thank you very much for your assistance

1 Like

Is your issue resolved?

1 Like

Hi Deepti_Prasad

When I run the code now, it is not responding

That is the error I am getting after getting the message “99% reached so cancelling training!”


Kindly DM me your codes or send your notebook via personal DM. Click on my name and then message

Hello Philani,

  1. You do not require to import libs which are already import at the beginning of the notebook

GRADED CLASS: myCallback
import tensorflow as tf
import keras

  1. Also your logs code is incorrect in def statement. It should be logs=None
    if logs.get(‘accuracy’) is not None and logs.get(‘accuracy’) > 0.99:

  2. you edited metadata outside of ##START AND END CODE HERE in the grader cell for (which will cause you failing your grader). I highly recommend you to re-do assignment if there is any editing outside of START and END CODE HERE in order to prevent failing your assignment.

GRADED FUNCTION: train_mnist
def train_mnist(x_train, y_train):(THIS STATEMENT IS NOT THERE IN YOUR NOTEBOOK)

  1. You dataset x_train and y_train is already loaded in the notebook, so the below codes were not required

NOT REQUIRED train_mnist = tf.keras.datasets.mnist

NOT REQUIRED (x_train, y_train), _ = tf.keras.datasets.mnist.load_data(path=data_path)

NOT REQUIRED x_train = x_train / 255.0

  1. When I said history = , I meant this way. Writing the same sentence or code twice is confusing your module.

#Fit the model for 10 epochs adding the callbacks
#and save the training history

Do these corrections and run the cell.



Hello Deepti

How can I get a fresh workbook?

I think messing up with grader cell ruined the workbook for me

Hello Philani,

  1. Click Help on the right side top corner, Then Update lab, then get the latest version.

  2. if by any chance step 1 doesn’t get you a fresh copy then follow the below steps

first click file, then open file, here select all the files and delete them.
Now you will find a 404 error on your screen.
At this time, click on the Help which is at the right top corner.
Next, Click reboot.
After you have rebooted, click help again, Updated lab, then Get the latest version.
You will have a fresh copy of the assignment.

Make sure to keep/download a copy of the assignment you have done already, in case you want to copy your codes for doing your assignment again.

Let me know, if your issue was resolved.


Thank you Deepti.

is your issue resolved?