4 pass but 2 failed with following error:
“Error: Data-type mismatch. Make sure it is a np.float32 value.”
Anyone seeing error like this? I’m using K.log, but can’t figure out how and where to use K.mean. Maybe that’s the reason? Following is my code:
{moderator edit - solution code removed}
Thank you
1 Like
I wrote this in a much simpler way: you don’t need a loop over the examples. You can vectorize that part. I used np.log
and np.sum
and it all worked for me.
My suggestion would be to consider rewriting it without the inner loop first and use numpy. If you then get an error similar to what you showed above, please show us the full exception trace, not just the error message. It would help to know which line “threw” …
It’s fine to show exception traces, but we aren’t technically allowed to share our solution code in a public way.
1 Like
Hello Sunolbanjo,
Try writing the loss code in a single line as per highlight equation in the image shared here below which was part of the assignment
As Paul mentioned you do not need to use any loop over for recalling weighted_loss.
On how to use K.mean, see the image hint click on that Keras.mean which will show you how to use K.mean. Basically you need to use K.mean for the equation I shared.
Initial loss was already recalled to 0 but in your code you again recalled to class_loss 0 which is incorrect.
The way you are recalling y_true and y_pred is also incorrect, check the args statements which states both size as (num_examples, num_classes), so you recalled it as j is incorrect.
Let me know if you still have the issue.
Regards
DP
Thank you so much, Paul. I’ll give it a try.
1 Like
Thank you so much, DP. I’ll look into it.
1 Like
Thank you, Paul and DP. I was able to resolve the issue using tensor in one line.
I now has better understanding of the function and how to use tensor code. Thank you both.
1 Like