【发布时间】:2018-11-04 16:55:11
【问题描述】:
我用 SIRI-WHU 数据集预训练了 VGG19,现在我想提取特征,但我不知道该怎么做。 有人能帮助我吗? 谢谢
【问题讨论】:
标签: python tensorflow deep-learning vgg-net
我用 SIRI-WHU 数据集预训练了 VGG19,现在我想提取特征,但我不知道该怎么做。 有人能帮助我吗? 谢谢
【问题讨论】:
标签: python tensorflow deep-learning vgg-net
没有太多信息可以帮助您。你能加载模型吗,如果可以的话,你可以这样做:
with tf.Session() as sess:
# the tensor you want to feed your image to
input_tensor = sess.graph.get_tensor_by_name("name of your input tensor")
# the tensor you're interested in, most likely last_dense_layer_name/BiasAdd:0
output_tensor = sess.graph.get_tensor_by_name("name of your output tensor")
feature_vector = sess.run(output_tensor, feed_dict={input_tensor: **insert numpy array of your image **})
此代码假定您的图表在内存中,如果您在执行此操作时遇到问题,请询问
【讨论】:
我通过将 FC6 层固定为输出层解决了这个问题
prob = sess.run(vgg.fc6, feed_dict=feed_dict)
然后我将特征存储在 h5 文件中
f = h5py.File('sample.h5','a')
f.create_dataset('data',data=prob,dtype=np.float32)
【讨论】: