小编Ye_*_*Ye_的帖子

Keras 权重和 get_weights() 显示不同的值

我在 Tensorflow 中使用 Keras。Keras 层有一个方法“get_weights()”和一个属性“weights”。我的理解是“权重”输出权重的 Tensorflow 张量,“get_weights()”评估权重张量并将值输出为 numpy 数组。然而,两者实际上向我展示了不同的价值观。这是要复制的代码。

from keras.applications.vgg19 import VGG19
import tensorflow as tf

vgg19 = VGG19(weights='imagenet', include_top=False)

vgg19.get_layer('block5_conv1').get_weights()[0][0,0,0,0]
#result is 0.0028906602, this is actually the pretrained weight

sess = tf.Session()

sess.run(tf.global_variables_initializer())
#I have to run the initializer here. Otherwise, the next line will give me an error
sess.run(vgg19.get_layer('block5_conv1').weights[0][0,0,0,0])
#The result here is -0.017039195 for me. It seems to be a random number each time.
Run Code Online (Sandbox Code Playgroud)

我的 Keras 版本是 2.0.6。我的 Tensorflow 是 1.3.0。谢谢!

keras tensorflow

1
推荐指数
1
解决办法
2357
查看次数

标签 统计

keras ×1

tensorflow ×1