如何使用Keras获取Inception v3模型的pool3功能?

问题描述:

使用Tensorflow,我得到一个2048维向量作为pool3层的输出.但是,使用Keras的include_top = False可以得出8,8,2048维向量.如何获得与使用Tensorflow的pool3输出层得到的相同矢量?

Using Tensorflow, I get a 2048 dimensional vector as the output of the pool3 layer. However, using Keras's include_top=False gives a 8,8,2048 dimensional vector. How do I get that same vector which I get using Tensorflow's pool3 output layer?

让我们看一下TensorBoard中的pool_3层.

Let's look at the pool_3 layer in TensorBoard.

看来Keras返回的图层实际上是mixed_10图层的输出.

It seems that the layer Keras returns is actually the mixed_10 layer output.

要获得pool_3的2048-D特征向量,Inception v3会附加一个平均池化层. 由于它使用8x8滤波器,因此这是前两个轴上的简单平均操作,因此我们可以使用NumPy获得此向量,如下所示:

To get the 2048-D feature vector of pool_3, Inception v3 appends an average pooling layer. Since it uses a 8x8 filter, this is a simple average operation over the first two axes, so we can obtain this vector with NumPy as follows:

pooled_vector = numpy.mean(unpooled_vector,axis =(0,1))

pooled_vector = numpy.mean(unpooled_vector, axis=(0,1))

其中,pooled_vector是2048-D向量,而unpooled_vector是8x8x2048向量.

where pooled_vector is the 2048-D vector and unpooled_vector is your 8x8x2048 vector.