W2_Ex-8_Merge all functions into a model

Hi,
I have been able to code all the exercises successfully (All tests Passed). However, I am getting the following error while merging all functions into a model

Thanks
Pradeep

1 Like

That means there is a bug in your model function, not in your propagate function. You are passing mismatching (incorrect) arguments to propagate. So either the w value or the X value is the wrong shape. Your logic for passing X_train down looks correct, so my guess is that it is w that is the wrong shape. So where is that shape determined? By the value you passed as the dimension argument to the initialize routine, right? Did you perhaps reference a global variable like dim there instead of the number of rows the input ā€œsampleā€ matrix?

1 Like

@paulinpaloalto Yes , that was the case, I was using dim in initialize routine. Thank you for the advice. Also, by input ā€œsampleā€ matrix do you mean X_train and do i need to provide shape[0] of that matrix in the initialize routine. I kind of did that , but still getting error though different from earlier one. I am getting assertion error : wrong values of d[ā€˜w’] . Kindly suggest.
Thanks

Yes, the ā€œsampleā€ matrix is X_train in the model function. So what you describe should work. But that error from the grader is saying that there is something wrong with either you back propagation or ā€œupdate parametersā€ logic with the result that the final w value that your code generates after the training iterations is not correct. There could be lots of potential reasons for that. If your propagate and optimize functions pass all the tests, then make sure you not ā€œhard-codingā€ any of the parameters you pass to optimize. Also make sure that you are correctly managing the return values from optimize. E.g. note that params and parameters are not the same variable.

I’ve the same problem where all tests pass except the last one, which merges all model functions.
Here is the error log:


I guess I’ve a bug somewhere in my code, but I couldn’t find it.
I’m confused on when to use np.dot() or broadcasting using *.

I appreciate any help.
Thanks

1 Like

I found my bug.
When initializing w, I was passing dim as the second dimension of the data, when it should be the first dimension. w should be of shape = (num_px * num_px * 3, 1)

Thank you

Great! Glad that you could find the bug.

@paulinpaloalto Thanks for your help and guidance as well as sorry for the delayed response.

i am getting this error when i am running merge all function test

@paulinpaloalto please help

@waqas_raja did you get any help on the error? I am facing the same issue too.

Hi, Solomon.

Please show us the actual error output that you are getting. Also please note the theme of the previous posts on this thread: just because your previous functions are correct, you can still have problems in the model function. A perfectly correct lower level routine can throw errors or produce incorrect results if you call it with bad arguments.

Hii there I am getting error in final model
AssertionError: Wrong length for d[ā€˜costs’]. 20 != 1
however as far as I understand program, length of costs will be 20…it will never be 1…because if loop condition is satisfying 20 times.

That is only true if the number of iterations you request is 2000. That is only the default value. The test in question passes a different number. So now you need to figure out why that parameter was not respected and you ended up using 2000 instead. How did that happen?

I got an error after merging all functions. Would you please help me with what wrong is with my code?

It looks like the main problem is that your input data there is not correct. It looks like somehow the X_train value that you are getting there has not been ā€œflattenedā€ from a 4D array into a 2D array (matrix). That was done earlier in the notebook. Are you sure you didn’t edit parts that you were not supposed to change? And I think the cell that invokes model there is not changeable, so it must be that the incorrect changes were in the earlier sections. Please check where the variables train_set_x and so forth are created.

The shape of the X_train value that is passed to model in that particular test case should be 12288 x 209, but yours is 209 x 64 x 64 x 3. So how did that happen?

Hello All, went through all of the responses. I got the same error as Mohammed:
ā€˜ValueError: shapes (1,7) and (4,1) not aligned: 7 (dim 1) != 4 (dim 0)’

I don’t understand how changing w from ā€˜(len(X_train[0]), 1)’ which I currently have to shape (num_px * num_px * 3, 1) solved this issue for him?

Please show us the full exception trace that you are getting. There should be no place in the model function where you reference num_px: you should be basing everything off the shapes of the X_train array that you are passed as a parameter.

Hello Paul, thanks for your prompt response. I made a mistake using len function instead of .shape to get the rows for initialising w.
Also had to make sure I didn’t hardcodse my learning rate and number of iterations.
All is well.

It’s great to hear you found the solution under your own power! Thanks for confirming. Onward! :nerd_face: