TF Advanced Technique C3_W4_Lab_1 error

Hi experts,
When running TF Advance Techniques C3W4 Lab 1 (Class Activation Maps with Fashion MNIST) after training the model, and executing the follow cell:

cam_model  = Model(inputs=model.input,outputs=(model.layers[-3].output,model.layers[-1].output))
cam_model.summary()

Got the following error:

---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-27-fe19a5d35706> in <cell line: 2>()
      1 # same as previous model but with an additional output
----> 2 cam_model  = Model(inputs=model.input,outputs=(model.layers[-3].output,model.layers[-1].output))
      3 # model.summary()
      4 # cam_model  = Model( inputs=model.input, outputs=( [model.layers[-3].output, model.layers[-1].output] ) )
      5 cam_model.summary()

1 frames

/usr/local/lib/python3.10/dist-packages/keras/src/ops/operation.py in _get_node_attribute_at_index(self, node_index, attr, attr_name)
    283         """
    284         if not self._inbound_nodes:
--> 285             raise ValueError(
    286                 f"The layer {self.name} has never been called "
    287                 f"and thus has no defined {attr_name}."

ValueError: The layer sequential_4 has never been called and thus has no defined input.

There is a typo in that cell which should be referencing model.inputs with a missing trailing ‘s’:


cam_model  = Model(inputs=model.inputs,outputs=(model.layers[-3].output,model.layers[-1].output))
cam_model.summary()

Just realized similar typo with Lab 2 as well.

Hi @Mun_Chung_Wong

First I would like to confirm your query belongs to the correct category mentions as per your selection as mentions C3_W4 but the course you have select is course 2 of this specialisation.

Also mention if it is graded lab or ungraded lab. Also please let us the lab2 which you are having issue similar to mentioned in your comment.

Also if you are running the assignment codes in coursera provided environment or running the codes locally in Colab.

Regards
DP

Hi DP,

Thanks for your reply.

I have indeed selected the wrong course number for the reported issue.

It’s for course 3 Advanced Computer Vision with Tensorflow, and week 4:

  • Lab 1: Ungraded Lab: Class Activation Maps with Fashion MNIST, second
    cell in the section titled Generate the Class Activation Map.
  • Lab 2: Ungraded Lab: Cats vs. Dogs Class Activation Maps, first cell in the
    section titled Building the CAM model.

I have now fixed up the course and week number for my post.

Rgds,
MCW

I just checked the github repo of the ungraded lab and there is no trailing s there, you might have added that by mistake!

Gent,

the learner has added the ‘s’ to the model input for he is believing it is typo and it should be recalled as model.inputs

1 Like

@Mun_Chung_Wong

are running the lab assignments in your local colab environment?

Hi DP,

Yes I ran both ungraded lab notebooks and other assignments on Colab
when course instructions indicated so.

So, as per original post specifically for these 2 labe for TF Advanced
Technique C3_W4_Lab1 and C3_W4_Lab2, the issue appears to be that the
new model cam_model is created with inputs paraneter assigned to the
trained model.input which should have been model.inputs.

Rgds,
MCW

@Mun_Chung_Wong when I asked running the lab in colab, I meant to ask if you used the colab link provided in the programme assignment page in the course ?

But in case you saved the labs and then opened the labs in colab.google, then you are working on your local colab directory. The reason I stated this because of the error you got indicates of this as the inputs needs to be recalled separately when it comes to sequential layer when it comes to running codes locally.

But in case you are running codes in course provided colab as mentioned early. Then also you see the inputs are recalled with function model to the assigned input in cam model. So basically in the cam model, input is mentioned as inputs. if you see the instructions cam model is using a previous model, so the inputs in cam model is using the input recalled previously.

Hi DP,

Thanks for clarifying.

I need to reiterate that it’s not the graded assignment that I am having issue
with. It’s the 2 ungraded labs.

So for ungraded lab 1 and 2, I followed the Coursera course provided Colab
link, ie for Lab 1:

Lab 2 link:

As both are ungraded labs, I never saved a copy on Google drive and worked
from the saved local copies on the drive.

For graded assignment, I saved a copy where/when the instructions clearly
indicate to do so.

Rgds,
MCW

1 Like

ok thanks @Mun_Chung_Wong for clarifying on this, let me check back my ungraded labs.

Until then I want you to check in the ungraded labs what version of tensorflow is being used? if it is a latest one then let me know

Hi DP,

TF version 2.17.0:

Thanks,
MCW

now can you confirm if tensorflow and keras Version in your system are matching with the labs version!!!

Hi DP,

My MacOS has different version of Keras, but TF is same 2.17.0:

Is TF 2.17.0 the default now for Colab?

The reason I ask is that it’s also giving me another compatibility with tensorflow_hub/keras_layer in lab 3 for which I will start a different post on it.

Rgds,
MCW

Okay apologies @Mun_Chung_Wong it does seem running the codes with model.inputs resolve the issue as I just check the labs myself and what you are stating seems to be true adding model.inputs resolves the issue, I have notified the L.T of the course.

I am tagging him here @chris.favilla for him to have a look at your post too.

Regards
DP

Hi DP,

Thanks for verifying. Appreciate it.

Also, you probably already knew this.

When I rolled back tensorflow, keras and tf-keras to 2.15.0 as per your suggestion to my other post, then the lab 1 and 2 problematic cell runs just fine, i,e:

# same as previous model but with an additional output
cam_model  = Model(inputs=model.input,outputs=(model.layers[-3].output,model.layers[-1].output))
cam_model.summary()

To summarize it all with my own experience and observation is as following:

  • tensorflow, keras and tf-keras all at 2.15.0, following work:

# same as previous model but with an additional output
cam_model  = Model(inputs=model.input,outputs=(model.layers[-3].output,model.layers[-1].output))
cam_model.summary()

and following also works:

# same as previous model but with an additional output
cam_model  = Model(inputs=model.inputs,outputs=(model.layers[-3].output,model.layers[-1].output))
cam_model.summary()
  • Current Colab default of tensorflow 2.17.0, keras 3.4.1 and tf-keras 2.17.0, following works:
# same as previous model but with an additional output
cam_model  = Model(inputs=model.inputs,outputs=(model.layers[-3].output,model.layers[-1].output))
cam_model.summary()

but following does not work:

# same as previous model but with an additional output
cam_model  = Model(inputs=model.input,outputs=(model.layers[-3].output,model.layers[-1].output))
cam_model.summary()

Rgds,
MCW

1 Like

Hi MCW! Thank you for reporting these! The TF and Keras versions are now pinned to v2.15 so other learners won’t run into the same issue.

1 Like