【发布时间】:2019-03-29 04:13:27
【问题描述】:
我想加载一个经过 caffe 训练的神经网络进行图像分类。
NN 包含一个文件mean.binaryproto,它具有在输入要分类的图像之前要减去的方法。
我试图了解此文件中包含的内容,因此我使用 Google Colab 查看其中的内容。
加载它的代码如下:
# Load the Drive helper and mount
from google.colab import drive
# This will prompt for authorization.
drive.mount('/content/drive')
!ls "/content/drive/My Drive"
#install packages
!apt install -y caffe-cuda
!apt update
!apt upgrade
!apt dist-upgrade
!ls "/content/drive/My Drive/NeuralNetwork/CNRPark-Trained-Models/mAlexNet-on-CNRPark/"
import caffe
import numpy as np
with open('/content/drive/My Drive/NeuralNetwork/CNRPark-Trained-Models/mAlexNet-on-CNRPark/mean.binaryproto', 'rb') as f:
blob = caffe.proto.caffe_pb2.BlobProto()
blob.ParseFromString(f.read())
arr = np.array( caffe.io.blobproto_to_array(blob) )
print(arr.shape)
out = arr[0]
data = np.array(blob.data).reshape([blob.channels, blob.height, blob.width])
print (data.shape)
print(data[0])
#display the mean image
from PIL import Image
from IPython.display import Image as Im, display
display(Image.fromarray(data[0], 'RGB'))
哪个输出:
(1, 3, 256, 256)
(3, 256, 256)
我的理解是该文件包含均值,我们正在谈论的图像是 3 通道图像,因此每个通道都有一个均值。
但是我希望每个通道只有一个值,但我发现了一个 256x256 数组:这是否意味着每个通道的每个像素都已取平均值?
另一个问题如下:我想将这样的 NN 与 OpenCV 一起使用,而不是 RGB 使用 BGR:如何知道平均 3x256x256 是使用 RGB 还是 BGR?
模型的链接是this。我正在查看的模型包含在文件夹中的 zip 文件 CNRPark-Trained-Models.zip 中:mAlexNet-on-CNRPark。
【问题讨论】:
标签: python neural-network caffe pycaffe