Autograder fails on Music Inference Model due to internal layer count (outputs are correct)

Hi! My Music Inference Model assignment is working correctly: I get 50 outputs, each with shape (None, 90), and the predictions also have the correct shape.

Here are my prints from the notebook:

Outputs = 50

Single output shape = (None, 90)
len(pred) = 50
pred[0].shape = (1, 90)

AssertionError Traceback (most recent call last)
in
37
38 inference_summary = summary(inference_model)
—> 39 comparator(inference_summary, music_inference_model_out)

~/work/W1A3/test_utils.py in comparator(learner, instructor)
18 def comparator(learner, instructor):
19 if len(learner) != len(instructor):
—> 20 raise AssertionError(“Error in test. The lists contain a different number of elements”)
21 for index, a in enumerate(instructor):
22 b = learner[index]

AssertionError: Error in test. The lists contain a different number of elements

The outputs and shapes are correct.
Could you please review my notebook ? Thanks

Deep Learning Specialization – Course 5, Week 1, Music Inference Model

The key is to understand what that test is actually checking. It’s not the shape of your outputs: it’s the number of layers in your actual model, right? So the next step is to print the “summary” of both your model and the expected one to figure out where to look for the issue.

They gave you logic to print the summary of your model, but it’s not in a very convenient form. Here’s my code that gives you a more useful output:

print("Generated model:")
for index, a in enumerate(summary(inference_model)):
    print(f"layer {index}: {a}")

Here’s my output from that code cell with code that passes the test and the grader:

Generated model:
layer 0: ['InputLayer', [(None, 1, 90)], 0]
layer 1: ['InputLayer', [(None, 64)], 0]
layer 2: ['InputLayer', [(None, 64)], 0]
layer 3: ['LSTM', [(None, 64), (None, 64), (None, 64)], 39680, [(None, 1, 90), (None, 64), (None, 64)], 'tanh']
layer 4: ['Dense', (None, 90), 5850, 'softmax']
layer 5: ['TensorFlowOpLayer', [(None,)], 0]
layer 6: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 7: ['RepeatVector', (None, 1, 90), 0, 1]
layer 8: ['TensorFlowOpLayer', [(None,)], 0]
layer 9: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 10: ['RepeatVector', (None, 1, 90), 0, 1]
layer 11: ['TensorFlowOpLayer', [(None,)], 0]
layer 12: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 13: ['RepeatVector', (None, 1, 90), 0, 1]
layer 14: ['TensorFlowOpLayer', [(None,)], 0]
layer 15: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 16: ['RepeatVector', (None, 1, 90), 0, 1]
layer 17: ['TensorFlowOpLayer', [(None,)], 0]
layer 18: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 19: ['RepeatVector', (None, 1, 90), 0, 1]
layer 20: ['TensorFlowOpLayer', [(None,)], 0]
layer 21: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 22: ['RepeatVector', (None, 1, 90), 0, 1]
layer 23: ['TensorFlowOpLayer', [(None,)], 0]
layer 24: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 25: ['RepeatVector', (None, 1, 90), 0, 1]
layer 26: ['TensorFlowOpLayer', [(None,)], 0]
layer 27: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 28: ['RepeatVector', (None, 1, 90), 0, 1]
layer 29: ['TensorFlowOpLayer', [(None,)], 0]
layer 30: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 31: ['RepeatVector', (None, 1, 90), 0, 1]
layer 32: ['TensorFlowOpLayer', [(None,)], 0]
layer 33: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 34: ['RepeatVector', (None, 1, 90), 0, 1]
layer 35: ['TensorFlowOpLayer', [(None,)], 0]
layer 36: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 37: ['RepeatVector', (None, 1, 90), 0, 1]
layer 38: ['TensorFlowOpLayer', [(None,)], 0]
layer 39: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 40: ['RepeatVector', (None, 1, 90), 0, 1]
layer 41: ['TensorFlowOpLayer', [(None,)], 0]
layer 42: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 43: ['RepeatVector', (None, 1, 90), 0, 1]
layer 44: ['TensorFlowOpLayer', [(None,)], 0]
layer 45: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 46: ['RepeatVector', (None, 1, 90), 0, 1]
layer 47: ['TensorFlowOpLayer', [(None,)], 0]
layer 48: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 49: ['RepeatVector', (None, 1, 90), 0, 1]
layer 50: ['TensorFlowOpLayer', [(None,)], 0]
layer 51: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 52: ['RepeatVector', (None, 1, 90), 0, 1]
layer 53: ['TensorFlowOpLayer', [(None,)], 0]
layer 54: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 55: ['RepeatVector', (None, 1, 90), 0, 1]
layer 56: ['TensorFlowOpLayer', [(None,)], 0]
layer 57: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 58: ['RepeatVector', (None, 1, 90), 0, 1]
layer 59: ['TensorFlowOpLayer', [(None,)], 0]
layer 60: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 61: ['RepeatVector', (None, 1, 90), 0, 1]
layer 62: ['TensorFlowOpLayer', [(None,)], 0]
layer 63: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 64: ['RepeatVector', (None, 1, 90), 0, 1]
layer 65: ['TensorFlowOpLayer', [(None,)], 0]
layer 66: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 67: ['RepeatVector', (None, 1, 90), 0, 1]
layer 68: ['TensorFlowOpLayer', [(None,)], 0]
layer 69: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 70: ['RepeatVector', (None, 1, 90), 0, 1]
layer 71: ['TensorFlowOpLayer', [(None,)], 0]
layer 72: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 73: ['RepeatVector', (None, 1, 90), 0, 1]
layer 74: ['TensorFlowOpLayer', [(None,)], 0]
layer 75: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 76: ['RepeatVector', (None, 1, 90), 0, 1]
layer 77: ['TensorFlowOpLayer', [(None,)], 0]
layer 78: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 79: ['RepeatVector', (None, 1, 90), 0, 1]
layer 80: ['TensorFlowOpLayer', [(None,)], 0]
layer 81: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 82: ['RepeatVector', (None, 1, 90), 0, 1]
layer 83: ['TensorFlowOpLayer', [(None,)], 0]
layer 84: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 85: ['RepeatVector', (None, 1, 90), 0, 1]
layer 86: ['TensorFlowOpLayer', [(None,)], 0]
layer 87: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 88: ['RepeatVector', (None, 1, 90), 0, 1]
layer 89: ['TensorFlowOpLayer', [(None,)], 0]
layer 90: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 91: ['RepeatVector', (None, 1, 90), 0, 1]
layer 92: ['TensorFlowOpLayer', [(None,)], 0]
layer 93: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 94: ['RepeatVector', (None, 1, 90), 0, 1]
layer 95: ['TensorFlowOpLayer', [(None,)], 0]
layer 96: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 97: ['RepeatVector', (None, 1, 90), 0, 1]
layer 98: ['TensorFlowOpLayer', [(None,)], 0]
layer 99: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 100: ['RepeatVector', (None, 1, 90), 0, 1]
layer 101: ['TensorFlowOpLayer', [(None,)], 0]
layer 102: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 103: ['RepeatVector', (None, 1, 90), 0, 1]
layer 104: ['TensorFlowOpLayer', [(None,)], 0]
layer 105: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 106: ['RepeatVector', (None, 1, 90), 0, 1]
layer 107: ['TensorFlowOpLayer', [(None,)], 0]
layer 108: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 109: ['RepeatVector', (None, 1, 90), 0, 1]
layer 110: ['TensorFlowOpLayer', [(None,)], 0]
layer 111: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 112: ['RepeatVector', (None, 1, 90), 0, 1]
layer 113: ['TensorFlowOpLayer', [(None,)], 0]
layer 114: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 115: ['RepeatVector', (None, 1, 90), 0, 1]
layer 116: ['TensorFlowOpLayer', [(None,)], 0]
layer 117: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 118: ['RepeatVector', (None, 1, 90), 0, 1]
layer 119: ['TensorFlowOpLayer', [(None,)], 0]
layer 120: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 121: ['RepeatVector', (None, 1, 90), 0, 1]
layer 122: ['TensorFlowOpLayer', [(None,)], 0]
layer 123: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 124: ['RepeatVector', (None, 1, 90), 0, 1]
layer 125: ['TensorFlowOpLayer', [(None,)], 0]
layer 126: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 127: ['RepeatVector', (None, 1, 90), 0, 1]
layer 128: ['TensorFlowOpLayer', [(None,)], 0]
layer 129: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 130: ['RepeatVector', (None, 1, 90), 0, 1]
layer 131: ['TensorFlowOpLayer', [(None,)], 0]
layer 132: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 133: ['RepeatVector', (None, 1, 90), 0, 1]
layer 134: ['TensorFlowOpLayer', [(None,)], 0]
layer 135: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 136: ['RepeatVector', (None, 1, 90), 0, 1]
layer 137: ['TensorFlowOpLayer', [(None,)], 0]
layer 138: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 139: ['RepeatVector', (None, 1, 90), 0, 1]
layer 140: ['TensorFlowOpLayer', [(None,)], 0]
layer 141: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 142: ['RepeatVector', (None, 1, 90), 0, 1]
layer 143: ['TensorFlowOpLayer', [(None,)], 0]
layer 144: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 145: ['RepeatVector', (None, 1, 90), 0, 1]
layer 146: ['TensorFlowOpLayer', [(None,)], 0]
layer 147: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 148: ['RepeatVector', (None, 1, 90), 0, 1]
layer 149: ['TensorFlowOpLayer', [(None,)], 0]
layer 150: ['TensorFlowOpLayer', [(None, 90)], 0]
layer 151: ['RepeatVector', (None, 1, 90), 0, 1]

The theory would be that if you try that, the number of layers will not be 151. :nerd_face:

Hi Mentor,

Here is the output of my model summary after running the notebook:

Generated model:
layer 0: [‘InputLayer’, [(None, 1, 90)], 0]
layer 1: [‘InputLayer’, [(None, 64)], 0]
layer 2: [‘InputLayer’, [(None, 64)], 0]
layer 3: [‘LSTM’, [(None, 64), (None, 64), (None, 64)], 39680, [(None, 1, 90), (None, 64), (None, 64)], ‘tanh’]
layer 4: [‘Dense’, (None, 90), 5850, ‘softmax’]
layer 5: [‘Lambda’, (None,), 0]
layer 6: [‘Lambda’, (None, 90), 0]
layer 7: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 8: [‘Lambda’, (None,), 0]
layer 9: [‘Lambda’, (None, 90), 0]
layer 10: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 11: [‘Lambda’, (None,), 0]
layer 12: [‘Lambda’, (None, 90), 0]
layer 13: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 14: [‘Lambda’, (None,), 0]
layer 15: [‘Lambda’, (None, 90), 0]
layer 16: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 17: [‘Lambda’, (None,), 0]
layer 18: [‘Lambda’, (None, 90), 0]
layer 19: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 20: [‘Lambda’, (None,), 0]
layer 21: [‘Lambda’, (None, 90), 0]
layer 22: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 23: [‘Lambda’, (None,), 0]
layer 24: [‘Lambda’, (None, 90), 0]
layer 25: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 26: [‘Lambda’, (None,), 0]
layer 27: [‘Lambda’, (None, 90), 0]
layer 28: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 29: [‘Lambda’, (None,), 0]
layer 30: [‘Lambda’, (None, 90), 0]
layer 31: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 32: [‘Lambda’, (None,), 0]
layer 33: [‘Lambda’, (None, 90), 0]
layer 34: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 35: [‘Lambda’, (None,), 0]
layer 36: [‘Lambda’, (None, 90), 0]
layer 37: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 38: [‘Lambda’, (None,), 0]
layer 39: [‘Lambda’, (None, 90), 0]
layer 40: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 41: [‘Lambda’, (None,), 0]
layer 42: [‘Lambda’, (None, 90), 0]
layer 43: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 44: [‘Lambda’, (None,), 0]
layer 45: [‘Lambda’, (None, 90), 0]
layer 46: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 47: [‘Lambda’, (None,), 0]
layer 48: [‘Lambda’, (None, 90), 0]
layer 49: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 50: [‘Lambda’, (None,), 0]
layer 51: [‘Lambda’, (None, 90), 0]
layer 52: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 53: [‘Lambda’, (None,), 0]
layer 54: [‘Lambda’, (None, 90), 0]
layer 55: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 56: [‘Lambda’, (None,), 0]
layer 57: [‘Lambda’, (None, 90), 0]
layer 58: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 59: [‘Lambda’, (None,), 0]
layer 60: [‘Lambda’, (None, 90), 0]
layer 61: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 62: [‘Lambda’, (None,), 0]
layer 63: [‘Lambda’, (None, 90), 0]
layer 64: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 65: [‘Lambda’, (None,), 0]
layer 66: [‘Lambda’, (None, 90), 0]
layer 67: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 68: [‘Lambda’, (None,), 0]
layer 69: [‘Lambda’, (None, 90), 0]
layer 70: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 71: [‘Lambda’, (None,), 0]
layer 72: [‘Lambda’, (None, 90), 0]
layer 73: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 74: [‘Lambda’, (None,), 0]
layer 75: [‘Lambda’, (None, 90), 0]
layer 76: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 77: [‘Lambda’, (None,), 0]
layer 78: [‘Lambda’, (None, 90), 0]
layer 79: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 80: [‘Lambda’, (None,), 0]
layer 81: [‘Lambda’, (None, 90), 0]
layer 82: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 83: [‘Lambda’, (None,), 0]
layer 84: [‘Lambda’, (None, 90), 0]
layer 85: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 86: [‘Lambda’, (None,), 0]
layer 87: [‘Lambda’, (None, 90), 0]
layer 88: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 89: [‘Lambda’, (None,), 0]
layer 90: [‘Lambda’, (None, 90), 0]
layer 91: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 92: [‘Lambda’, (None,), 0]
layer 93: [‘Lambda’, (None, 90), 0]
layer 94: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 95: [‘Lambda’, (None,), 0]
layer 96: [‘Lambda’, (None, 90), 0]
layer 97: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 98: [‘Lambda’, (None,), 0]
layer 99: [‘Lambda’, (None, 90), 0]
layer 100: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 101: [‘Lambda’, (None,), 0]
layer 102: [‘Lambda’, (None, 90), 0]
layer 103: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 104: [‘Lambda’, (None,), 0]
layer 105: [‘Lambda’, (None, 90), 0]
layer 106: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 107: [‘Lambda’, (None,), 0]
layer 108: [‘Lambda’, (None, 90), 0]
layer 109: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 110: [‘Lambda’, (None,), 0]
layer 111: [‘Lambda’, (None, 90), 0]
layer 112: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 113: [‘Lambda’, (None,), 0]
layer 114: [‘Lambda’, (None, 90), 0]
layer 115: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 116: [‘Lambda’, (None,), 0]
layer 117: [‘Lambda’, (None, 90), 0]
layer 118: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 119: [‘Lambda’, (None,), 0]
layer 120: [‘Lambda’, (None, 90), 0]
layer 121: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 122: [‘Lambda’, (None,), 0]
layer 123: [‘Lambda’, (None, 90), 0]
layer 124: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 125: [‘Lambda’, (None,), 0]
layer 126: [‘Lambda’, (None, 90), 0]
layer 127: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 128: [‘Lambda’, (None,), 0]
layer 129: [‘Lambda’, (None, 90), 0]
layer 130: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 131: [‘Lambda’, (None,), 0]
layer 132: [‘Lambda’, (None, 90), 0]
layer 133: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 134: [‘Lambda’, (None,), 0]
layer 135: [‘Lambda’, (None, 90), 0]
layer 136: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 137: [‘Lambda’, (None,), 0]
layer 138: [‘Lambda’, (None, 90), 0]
layer 139: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 140: [‘Lambda’, (None,), 0]
layer 141: [‘Lambda’, (None, 90), 0]
layer 142: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 143: [‘Lambda’, (None,), 0]
layer 144: [‘Lambda’, (None, 90), 0]
layer 145: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 146: [‘Lambda’, (None,), 0]
layer 147: [‘Lambda’, (None, 90), 0]
layer 148: [‘RepeatVector’, (None, 1, 90), 0, 1]
layer 149: [‘Lambda’, (None,), 0]
layer 150: [‘Lambda’, (None, 90), 0]
layer 151: [‘RepeatVector’, (None, 1, 90), 0, 1]

When I run the test, I get the following error:

Test failed at index 5
Expected value [‘TensorFlowOpLayer’, [(None,)], 0]
does not match the input value: [‘Lambda’, (None,), 0]

My model generates 151 layers, which matches the expected number, but at some indices I see ‘Lambda’ layers instead of ‘TensorFlowOpLayer’. The outputs and shapes are all correct, and my code matches the assignment instructions.

Is this difference in layer types possibly due to the TensorFlow/Keras version used in the notebook? Please let me know if I need to make further changes Thanks!

The question is, why do you have Lambda layers at all?

2 Likes

Yes, that’s the question. Looking at the position of those Lambda layers, it looks like it is the layers that do the “argmax” and the “one hot” operations. They specifically told you the TF functions to use for those in the instructions. It might be worth another careful look at the instructions for this section. Or maybe you did use those TF operations, but somehow managed to express it as a “Lambda” function? There should be nothing that forces you to do that …

1 Like

One more question: you are running this on the Coursera website, right? And you haven’t done anything to load a different version of TF, I hope …

If you are running this locally and with the latest TF, then all bets are off.

Thank you for your help and comments!
I adjusted my implementation according to your recommendations, avoiding unnecessary Lambda layers, and now the assignment passes all tests.
Appreciate your support!

3 Likes

That’s great news! Thanks for confirming.

1 Like