I’m afraid I’m not following what we are doing on each of those two chunks of code.

Can someone explain what we are doing there?

Thanks a lot.

PS: I already reported that line “base_model = tf.keras.applications.MobileNetV2(…)” is giving error of type ([Errno 99] Cannot assign requested address). It seems to be solved by trying the loading several times. However, the line “tf.keras.applications.mobilenet_v2.decode_predictions(pred.numpy(), top=2)” is also giving that same error.

This uses the trainable parameters and basically training the image batches based on the features

where as

for pred, when we set base_model. trainable=False, we only freeze trainable parameters . BatchNormalization will still record its moving average if we don’t set training=False for the BatchNormalization.

So basically pred has is the output of variable of the image batch where the parameters have been used as you know var = tf.variable() defines a variable that is trainable.

Can you share a screenshot of the error you are mentioning here, do not share any codes just the error output.

for this error resolution, can you try the below steps.

remove all the files from the file ==> open options, and then get a fresh copy, re-do the assignment, then refer the saved copy to write your codes again. let me know if the error with http works.

To get a fresh copy,

Click file, then select open. You will find all the files related to the assignment. Here if you have saved a copy of your notebook with renaming other than what was mentioned. Then go ahead and delete the assignment notebook by selecting the particular notebook.

Once deleted, you will find 404 not found image on your browser. Then close the browser.

Open the assignment page again, when you open you will find 404 not found.

At this time, click on the right hand top corner Before Grades, where you will find Reboot. Click reboot.

Then click the same on the right hand top corner, then click Get latest version and then Update lab.

Invoking __call__ outside the scope of model.fit and gradient tape (where weights can be changed by calling optimizer.apply_gradients explicitly) will not update model weights. Here’s some code to prove that:

def check(input_batch, use_vars = False):
from copy import deepcopy
print(f"base_model.trainable = {base_model.trainable}")
befores = deepcopy(base_model.weights)
if use_vars:
pred = base_model(tf.Variable(preprocess_input(input_batch)))
else:
pred = base_model(preprocess_input(input_batch))
print("are predictions the same as features?", tf.equal(pred, feature_batch).numpy().all())
for before, after in zip(befores, base_model.weights):
assert np.array_equal(before.numpy(), after.numpy())
assert before is not after
check(image_batch)
check(image_batch, use_vars=True)

Output:

base_model.trainable = True
are predictions the same as features? True
base_model.trainable = True
are predictions the same as features? True