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

Here’s my code for the music_inference_model:

{code removed by mentor}

I am getting this error:

AssertionError                            Traceback (most recent call last)
<ipython-input-29-7ced16cd24e3> in <module>
      3 # UNIT TEST
      4 inference_summary = summary(inference_model)
----> 5 comparator(inference_summary, music_inference_model_out)

~/work/W1A3/ in comparator(learner, instructor)
     16 def comparator(learner, instructor):
     17     if len(learner) != len(instructor):
---> 18         raise AssertionError("Error in test. The lists contain a different number of elements")
     19     for index, a in enumerate(instructor):
     20         b = learner[index]

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

Can someone help me, as to what is wrong? Tried several things, but can’t get past this assignment

Hi @chandank

Welcome to the community.

What course are you referring to? It turns out that you posted in the general category.

Best regards

Thanks @elirod! I will move it to DLS Course 5, and @chandank, please post in the right category next time :wink:

Let’s go through the error message:

This tells us the test is just comparing the lengths of your output, which is learner, which is inference_summary, to the model answer, which is music_inference_model_out, and as the message said, they have different lengths.

So, to precisely find out where the problem is, I recommend you to do a visual check on the elements in both lists - inference_summary and music_inference_model_out, pair by pair, to find out where starts to go wrong.

Now, I know the list in the model answer has over 150 items, so it will be a nightmare, but we can write some code to aid ourselves.

for i in range(max(len(inference_summary), len(music_inference_model_out))):
    print(f'layer number: {i}')

This is the basic version, it still requires you to visually compare each pair of items, but you can improve it to make Python do the comparison for you, by using the == operator. Check this out for how it works, or google for more. You can ask Python to only print the items if the comparison is failed, because, in this way, you read a lot less.

You find the first pair of different items, you know which layer it is, you find out why yours is different, and then you can fix it.

Lastly, if you decide to use, in your assignment notebook, my inspection code above or a modified version of it, please remember to remove it after your inspection work is finished, because leaving it there may interfere with the autograder and fail your submission.

Good luck!

PS: we can’t share assignment work here, so I have to remove it for you.

1 Like

Thank you for your support. @rmwkwok

Have a nice learning @chandank

I ran into this exact issue and had to dig around for quite some time. My mistake was, instead of using the globally defined layers: reshaper, densor, LSTM_cell, I was defining those layers by myself directly from the keras.layers module. Although the parameters were exactly the same, the test case passed after I used the globally defined layers (why though? Not sure).

1 Like