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.
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.
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.
You do not require to import libs which are already import at the beginning of the notebook
grader-required-cell
GRADED CLASS: myCallback
START CODE HERE
import tensorflow as tf
import keras
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:
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.
grader-required-cell
GRADED FUNCTION: train_mnist
def train_mnist(x_train, y_train):(THIS STATEMENT IS NOT THERE IN YOUR NOTEBOOK)
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
When I said history = model.fit , 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
history = model.fit(THIS CODE WHAT YOU WROTE IS CORRECT])
Click Help on the right side top corner, Then Update lab, then get the latest version.
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.