您好,我想從tensorflow中調整VGG模型。我有兩個問題。從張量流模型獲取重量
如何從網絡中獲取權重? trainable_variables爲我返回空列表。
我從這裏使用現有的模型:https://github.com/ry/tensorflow-vgg16。 我找到關於獲得重量的帖子,但是這對我來說不適用,因爲import_graph_def。 Get the value of some weights in a model trained by TensorFlow
import tensorflow as tf
import PIL.Image
import numpy as np
with open("../vgg16.tfmodel", mode='rb') as f:
fileContent = f.read()
graph_def = tf.GraphDef()
graph_def.ParseFromString(fileContent)
images = tf.placeholder("float", [None, 224, 224, 3])
tf.import_graph_def(graph_def, input_map={ "images": images })
print("graph loaded from disk")
graph = tf.get_default_graph()
cat = np.asarray(PIL.Image.open('../cat224.jpg'))
print(cat.shape)
init = tf.initialize_all_variables()
with tf.Session(graph=graph) as sess:
print(tf.trainable_variables())
sess.run(init)
儘量避免一次詢問多個問題。如果你找不到任何答案,並且你認爲它們都是有價值的問題,請隨時在單獨的帖子中詢問他們。 – Giewev