实际上,我正在古瑟拉做deeplearning.ai的“神经式迁移的艺术生成”的作业。在函数compute_layer_style_cost(a_S, a_G):中
a_S = tf.reshape(a_S, [n_H*n_W, n_C])
a_G = tf.reshape(a_G, [n_H*n_W, n_C])
GS = gram_matrix(tf.transpose(a_S))
GG = gram_matrix(tf.transpose(a_G))然而,为什么这段代码给出了正确的答案,但以下内容却没有:
a_S = tf.reshape(a_S, [n_C, n_H*n_W])
a_G = tf.reshape(a_G, [n_C, n_H*n_W])
GS = gram_matrix(a_S)
GG = gram_matrix(a_G)发布于 2018-04-19 14:02:15
下面是一个简单的示例,它显示了这两个表达式之间的区别:
import tensorflow as tf
tf.InteractiveSession()
x = tf.range(0, 6)
a = tf.reshape(x, [3, 2])
b = tf.transpose(tf.reshape(x, [2, 3]))
print(x.eval())
print(a.eval())
print(b.eval())结果:
[0 1 2 3 4 5]
[[0 1]
[2 3]
[4 5]]
[[0 3]
[1 4]
[2 5]]您可以注意到,a和b是不同的,尽管它们的形状是相同的。这是因为,第一种方法将x“拆分”为[0 1]、[2 3]和[4 5],而第二种则重塑为[0 1 2]和[3 4 5]。
https://stackoverflow.com/questions/49922674
复制相似问题