从 Fast-RCNN 获取特征向量

get feature vector from Fast-RCNN

我正在尝试识别和分组相似的图像,我遵循了这个教程:https://douglasduhaime.com/posts/identifying-similar-images-with-tensorflow.html

问题是我正在使用 faster_rcnn_resnet_101,我发现 fast-rcnn 中的特征向量在 SecondStageBoxPredictor 之后被丢弃。我使用 https://gist.github.com/markdtw/02ece6b90e75832bd44787c03a664e8d 在被删除之前获取向量。

feat_avg = graph.get_tensor_by_name('SecondStageBoxPredictor/AvgPool:0')

np.savetxt('output1/' + "test" + '.npz',feat_vector,delimiter=',')

然而,当我尝试保存矢量时出现错误:

ValueError: Expected 1D or 2D array, got 4D array instead

我把提取出来的特征向量打印出来看看结果:

    Tensor("SecondStageFeatureExtractor/resnet_v1_101/block4/unit_3/bottleneck_v1/Relu:0", shape=(?, 7, 7, 2048), dtype=float32) 
 [[[[0.         0.         0.         ... 0.         0.
    0.        ]
   [0.         0.         0.         ... 0.         0.
    0.        ]
   [0.         0.         0.         ... 0.         0.
    0.        ]
   ...
   [2.9170244  0.         0.33220196 ... 0.         0.
    0.        ]
   [0.         0.         0.         ... 0.         0.
    0.        ]
   [0.         0.         0.         ... 0.         0.
    0.        ]].....

我是TensorFlow和CV的新手,我想做的是提取特征向量,然后使用TSNE clusterring。 我提取的特征向量到底有什么问题

特征向量是 4D 传感器:[批次、高度、宽度、通道]。 np.savetxt 等待一维或二维数组。您可以将特征向量切片为 2D 数组或使用其他一些函数将其保存为 4D。