# Week 4 Assignment 2 compute\_layer\_style\_cost - Exception: "Wrong value"

**URL:** <https://community.deeplearning.ai/t/week-4-assignment-2-compute-layer-style-cost-exception-wrong-value/21377>\
**Category:** Convolutional Neural Networks\
**Tags:** coursera-platform\
**Created:** [July 16, 2021, 5:27am UTC](https://community.deeplearning.ai/t/week-4-assignment-2-compute-layer-style-cost-exception-wrong-value/21377 "2021-07-16T05:27:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BennyG](https://avatars.discourse-cdn.com/v4/letter/b/b782af/32.png) [@BennyG](https://community.deeplearning.ai/u/BennyG)\
**Post date:** [July 16, 2021, 5:27am UTC](https://community.deeplearning.ai/t/week-4-assignment-2-compute-layer-style-cost-exception-wrong-value/21377/1 "2021-07-16T05:27:04Z")

</div>

Hello!

I can’t get the compute\_layer\_style\_cost function to work. I just get the exception “Wrong value” every time.

-I’ve redone, checked and rechecked the formula in the last line, but find no mistake. The function compute\_content\_cost uses the same functions for the calculation of the corresponding formula in the last line (but with different normalization constant of course) and it works fine.

-Below I will copy-paste values of a\_S before and after reshaping. It has the shapes I expected and the reshaping seems to be right. But maybe I’ve missed something.

a\_S before reshaping:  
tf.Tensor(  
[[[[-3.404881 7.183007 2.534576]  
[-2.5186315 -3.8986888 -2.9244845]  
[1.3512313 0.18695849 -1.2326248]  
[-1.8821764 -1.5039697 -1.8601038]]

[[-0.39341784 -0.34587932 1.730303]  
[5.434381 6.118635 0.91409665]  
[-0.2787553 2.493302 2.0111642]  
[3.5750656 9.585232 -2.3005989]]

[[-2.616547 6.5795145 5.8995004]  
[1.2345984 -0.9685255 -2.2799122]  
[0.25895953 -0.5711074 -1.6340902]  
[-2.933355 2.555351 -3.1489797]]

[[-5.2402277 0.36834985 -0.42677724]  
[0.19823879 7.452428 3.718691]  
[1.3253293 6.3523054 5.739221]  
[-0.41526246 0.583993 -2.0045857]]]], shape=(1, 4, 4, 3), dtype=float32)

a\_S after reshaping:  
tf.Tensor(  
[[-3.404881 -2.5186315 1.3512313 -1.8821764 -0.39341784 5.434381  
-0.2787553 3.5750656 -2.616547 1.2345984 0.25895953 -2.933355  
-5.2402277 0.19823879 1.3253293 -0.41526246]  
[ 7.183007 -3.8986888 0.18695849 -1.5039697 -0.34587932 6.118635  
2.493302 9.585232 6.5795145 -0.9685255 -0.5711074 2.555351  
0.36834985 7.452428 6.3523054 0.583993 ]  
[ 2.534576 -2.9244845 -1.2326248 -1.8601038 1.730303 0.91409665  
2.0111642 -2.3005989 5.8995004 -2.2799122 -1.6340902 -3.1489797  
-0.42677724 3.718691 5.739221 -2.0045857 ]], shape=(3, 16), dtype=float32)  
(3, 3)

Any hot tips?

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [July 16, 2021, 7:32am UTC](https://community.deeplearning.ai/t/week-4-assignment-2-compute-layer-style-cost-exception-wrong-value/21377/2 "2021-07-16T07:32:06Z")

</div>

Your a\_S shapes and values seem fine.

---

<div class="post-metadata">

**Author:** ![BennyG](https://avatars.discourse-cdn.com/v4/letter/b/b782af/32.png) [@BennyG](https://community.deeplearning.ai/u/BennyG)\
**Post date:** [July 18, 2021, 11:58pm UTC](https://community.deeplearning.ai/t/week-4-assignment-2-compute-layer-style-cost-exception-wrong-value/21377/3 "2021-07-18T23:58:44Z")

</div>

Thanks! I found my mistake. I was using ^2 in the calculation of the constant coefficient.
