使用 TensorFlow 从我自己的数据中使用 VGGnet 提取特征?

Feature extraction with VGGnet from my own data with TensorFlow?

我用SIRI-WHU数据集预训练了VGG19,现在想抽取特征,不知道怎么做。 有谁可以帮助我吗? 谢谢

好吧,没有太多信息可以帮助您。你能加载模型吗,如果可以,你可以这样做:

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)