C5 W1 A3: Jazz Improvisation with LSTM (Problem and Tips)

Hello,

I do know why but every time I run the code I get this error


NameError Traceback (most recent call last)
in
----> 1 model = djmodel(Tx=30, LSTM_cell=LSTM_cell, densor=densor, reshaper=reshaper)

in djmodel(Tx, LSTM_cell, densor, reshaper)
42 x = Lambda(lambda z:X[:,t,:])(X)
43 # Step 2.B: Use reshaper to reshape x to be (1, n_values) (≈1 line)
—> 44 x = reshapor(x)
45 # Step 2.C: Perform one step of the LSTM_cell
46 a, _, c = LSTM_cell(inputs=x, initial_state=[a, c])

NameError: name ‘reshapor’ is not defined

I do not know what to do. Can anybody help me?

3 Likes

The comment (hint) talks about “reshaper”, the error message (and code) says “reshapor”

This is the best I have come up with

START CODE HERE

{mentor edit: code removed}

Hey @eag , learners are not supposed to publicly post code on Discourse. I understand in some cases the only way to help is to look at the code, in that scenario, please wait for a mentor to reach out to you, asking for it.

Next time if you post code publicly your post may be deleted.

Thanks
Happy learning!

Now changing by reshaper I get the model summary model but not the model loss. This is the error `Test failed
Expected value

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

does not match the input value:

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

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

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

AssertionError: Error in test
`

2 Likes

Hello eag, Did you get through this error?
I am getting same error.
Can you help me out if you have already solved it?

1 Like

I am afraid I am as stuck as you my friend. I even tried to look up in the literature on the website Papers with Code. But I did not even find a snippet to figure out the solution.

I also have this problem with TensorOpLayer, there was another post 3 days ago, but no peer mentors responded yet.

3 Likes

I had this exact same failed Test Case just now.

My error was - I was using Lambda for step 2A. I replaced this with regular python splicing, and everything then passed. So… give that a try. Maybe that works for you as well.

1 Like

Just use the normal np way to slice it. I had the same error msg, after spending hours seeking a solution, finally solved it by re-running the whole notebook :upside_down_face:.

4 Likes

Use this x = (lambda z:X[:,t,:])(X) instead of x = Lambda(lambda z:X[:,t,:])(X)

12 Likes

It works. Thank you. But now I am stuck with this x = tf.math.argmax(out,axis=-1) x = tf.one_hot(x, n_values) in the next exercise.

I’m stuck with the same place (djmodel)… I did not use the ‘lambda’ script myself - but using it did not help. So, the problem appears at UNIT TEST with the warning:
AttributeError: The layer “reshape” has multiple inbound nodes, with different output shapes. Hence the notion of “output shape” is ill-defined for the layer. Use get_output_shape_at(node_index) instead.

All of a sudden, it works now (on a different computer – but how could that matter?)

2 Likes

Exactly the same problem:
I am using normal numpy slicing: x = X[:,t,:]
image

3 Likes

Dear mentor,

After trying a lot, I got that function “def music_inference_model(LSTM_cell, densor, Ty=100):” works properly. I see that many of my colleges have some problems with that function. In fact, the instructions of the exercises need major details, I had to search a lot in google to code that function. However, I have an error with this line “inference_summary = summary(inference_model)”, which is part of the proporcionated code for this course. The following error is displayed: " AttributeError: The layer “lstm_1” has multiple inbound nodes, with different output shapes. Hence the notion of “output shape” is ill-defined for the layer. Use get_output_shape_at(node_index) instead."

After that, my output in the line “results, indices = predict_and_sample(inference_model, x_initializer, a_initializer, c_initializer)” differs from the expected output.

Finally, in the excersices from 3.2 - Generate Music, I have the following error "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Using a basic midi to wav parser you can have a rough idea about the audio clip generated by this model. The parser is very limited.".

Please help me to solve this problems, Thanks in advance

5 Likes

@alvaro.ortega I was getting exactly the same AttributeError. I noticed that another post had the problem go away when run on another computer. I did a save/checkpoint the restarted the kernel and ran each of the modules and it worked. I even got a bit of midi music output.

1 Like

I am still in the same place

Hey @TMosh @edwardyu , can you please provide help here ? Thanks.

1 Like

Hi @eag,
Could you post what error message you got, as well as Traceback?
BTW, if your TraceBack is same as this, please DM me your implement.

2 Likes

Hi all,

I have the same issue as @hafezgh. Did someone find any solution for that ?

Thanks in advance.

2 Likes