C5 W1 A3 (Jazz Improvisation) Programming Assignment: Error executing code

I am getting below error while executing code for Exercise 1 (djmodel). I am unable fix it. Kindly help.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-6e06a9870a31> in <module>
      1 ### YOU CANNOT EDIT THIS CELL
      2 
----> 3 model = djmodel(Tx=30, LSTM_cell=LSTM_cell, densor=densor, reshaper=reshaper)

<ipython-input-6-1a09a2cd603e> in djmodel(Tx, LSTM_cell, densor, reshaper)
     64     # Step 3: Create model instance
     65     #model = Model(inputs=[X, a0, c0], outputs=outputs)
---> 66     model = Model(inputs=[X, a0, c0], outputs=outputs)
     67 
     68     ### END CODE HERE ###

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in __new__(cls, *args, **kwargs)
    240       # Functional model
    241       from tensorflow.python.keras.engine import functional  # pylint: disable=g-import-not-at-top
--> 242       return functional.Functional(*args, **kwargs)
    243     else:
    244       return super(Model, cls).__new__(cls, *args, **kwargs)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
    455     self._self_setattr_tracking = False  # pylint: disable=protected-access
    456     try:
--> 457       result = method(self, *args, **kwargs)
    458     finally:
    459       self._self_setattr_tracking = previous_value  # pylint: disable=protected-access

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/functional.py in __init__(self, inputs, outputs, name, trainable)
    113     #     'arguments during initialization. Got an unexpected argument:')
    114     super(Functional, self).__init__(name=name, trainable=trainable)
--> 115     self._init_graph_network(inputs, outputs)
    116 
    117   @trackable.no_automatic_dependency_tracking

/opt/conda/lib/python3.7/site-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
    455     self._self_setattr_tracking = False  # pylint: disable=protected-access
    456     try:
--> 457       result = method(self, *args, **kwargs)
    458     finally:
    459       self._self_setattr_tracking = previous_value  # pylint: disable=protected-access

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/functional.py in _init_graph_network(self, inputs, outputs)
    140 
    141     if any(not hasattr(tensor, '_keras_history') for tensor in self.outputs):
--> 142       base_layer_utils.create_keras_history(self._nested_outputs)
    143 
    144     self._validate_graph_inputs_and_outputs()

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer_utils.py in create_keras_history(tensors)
    189       the raw Tensorflow operations.
    190   """
--> 191   _, created_layers = _create_keras_history_helper(tensors, set(), [])
    192   return created_layers
    193 

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer_utils.py in _create_keras_history_helper(tensors, processed_ops, created_layers)
    224                        'op wrapping. Please wrap these ops in a Lambda layer: '
    225                        '\n\n```\n{example}\n```\n'.format(example=example))
--> 226     op = tensor.op  # The Op that created this Tensor.
    227     if op not in processed_ops:
    228       # Recursively set `_keras_history`.

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in op(self)
   1213   def op(self):
   1214     raise AttributeError(
-> 1215         "Tensor.op is meaningless when eager execution is enabled.")
   1216 
   1217   @property

AttributeError: Tensor.op is meaningless when eager execution is enabled.

I suspect there is an error in your code in djmodel() that computes the “outputs” variable.

Tom is right. Please read the instructions and your code again for Step 2 (2.A, 2.B, 2.C, 2.D, and 2.E).

Thanks, I figured out the issue in my previous code and managed to get that piece of code working. I am however, getting following error while running comparator, although it seems that I have implemented each step correctly:

Test failed at index 2
Expected value

[‘Reshape’, (None, 1, 90), 0]

does not match the input value:

[‘TensorFlowOpLayer’, [(None, 90)], 0]

AssertionError Traceback (most recent call last)
in
3 # UNIT TEST
4 output = summary(model)
----> 5 comparator(output, djmodel_out)

~/work/W1A3/test_utils.py in comparator(learner, instructor)
24 “\n\n does not match the input value: \n\n”,
25 colored(f"{b}", “red”))
—> 26 raise AssertionError(“Error in test”)
27 print(colored(“All tests passed!”, “green”))
28

AssertionError: Error in test

Please check direct message from me for further instruction.

To conclude:

Google is your friend to learn how to create an empty list and how to append something.

Hi saifkhanenger, I’m getting the same error. I’m creating an empty list using outputs= and I’m appending the output “out” using outputs.append(out). Any guidance would be much appreciated Regards, Harry

Solved it!

1 Like