When creating a post, please add:
-
Week # 2
-
Link to the classroom item you are referring to: https://www.coursera.org/learn/advanced-learning-algorithms/programming/zgeR8/practice-lab-neural-networks-for-binary-classification/lab?path=%2Fnotebooks%2FC2_W1_Assignment.ipynb
-
Description : AttributeError Traceback (most recent call last)
/tmp/ipython-input-1222274547.py in <cell line: 0>() 2 from public_tests import * 3 ----> 4 test_c1(model)
/content/public_tests.py in test_c1(target)
8 assert len(target.layers) == 3, \
9 f"Wrong number of layers. Expected 3 but got {len(target.layers)}"
---> 10 assert target.input.shape.as_list() == [None, 400], \
11 f"Wrong input shape. Expected [None, 400] but got {target.input.shape.as_list()}"
12 i = 0
/usr/local/lib/python3.11/dist-packages/keras/src/ops/operation.py in input(self)
274 Input tensor or list of input tensors.
275 """
--> 276 return self._get_node_attribute_at_index(0, "input_tensors", "input")
277
278 @property
/usr/local/lib/python3.11/dist-packages/keras/src/ops/operation.py in _get_node_attribute_at_index(self, node_index, attr, attr_name)
305 """
306 if not self._inbound_nodes:
--> 307 raise AttributeError(
308 f"The layer {self.name} has never been called "
309 f"and thus has no defined {attr_name}."
AttributeError: The layer my_model has never been called and thus has no defined input.
Hi,
I’m working on the Week 1 Assignment for Course 2 (“Neural Networks for Binary Classification”) and I’m having trouble passing the first unit test:
python
CopiarEditar
from public_tests import * test_c1(model)
I believe the issue is with how I’m building the Keras model. The test seems to expect:
-
Input shape:
(400,)(flattened 20x20 image) -
3 Dense layers, all with sigmoid activation:
-
Layer 1: 25 units
-
Layer 2: 15 units
-
Layer 3: 1 unit (output)
-
-
No extra layers (Flatten, Dropout, etc.)
Here’s my current model code:
python
CopiarEditar
{mentor edit: code removed}
Question:
Even with this structure, test_c1(model) still fails. Could someone please clarify the exact requirements for the model to pass this test, or point out what I might be missing?
Thanks in advance!
German Ardila


