繁体   English   中英

Caffe提供的AlexNet模型

[英]AlexNet model provided with Caffe

我一直在使用TensorFlow,但对Caffe还是陌生的。 我想尝试在ImageNet上训练的AlexNet的可靠实现,我发现其中一个包含在官方Caffe存储库中

我能够以非常短的Caffe代码链接bvlc_alexnet.caffemodel文件中包装的权重和deploy.prototxt中指定的模型,并获得与网络将图像分类为1000个类别相对应的1000个概率的输出向量。

import numpy as np
import matplotlib.pyplot as plt
import sys
import caffe
import operator

MODEL_FILE = 'D:\\Desktop\\caffe\\models\\bvlc_alexnet\\deploy.prototxt'
PRETRAINED = 'D:\\AlexNet_Caffe\\bvlc_alexnet.caffemodel'

net = caffe.Classifier(MODEL_FILE, PRETRAINED)


IMAGE_FILE = 'D:\\Desktop\\caffe\\python\\testIm1.jpg'
input_image1 = caffe.io.load_image(IMAGE_FILE)

IMAGE_FILE = 'D:\\Desktop\\caffe\\python\\testIm2.jpg'
input_image2 = caffe.io.load_image(IMAGE_FILE)


pred = net.predict([input_image1, input_image2])
print pred # prints the array of 1000 probabilities


index, value = max(enumerate(pred[0]), key=operator.itemgetter(1))

print index # prints the index of max probability
print value # prints the max probability


index, value = max(enumerate(pred[1]), key=operator.itemgetter(1))

print index # prints the index of max probability
print value # prints the max probability

就我而言,我可以只指定模型和权重并获得输出,但是无论我输入什么图像,输出似乎都是相同的(669)。

在Caffe存储库中,有一个用于获取ImageNet数据集脚本 它下载并解压缩的压缩包包含以下文件:

$ ls -al
total 80395
drwxr-xr-x 1 root 197121        0 Aug  8 14:09 ./
drwxr-xr-x 1 root 197121        0 Aug  7 16:27 ../
-rw-r--r-- 1 root 197121      187 Feb 25  2014 ._imagenet_mean.binaryproto
-rw-r--r-- 1 root 197121      187 Apr  8  2014 ._synset_words.txt
-rw-r--r-- 1 root 197121      187 Feb 25  2014 ._synsets.txt
-rw-r--r-- 1 root 197121      187 Feb 25  2014 ._test.txt
-rw-r--r-- 1 root 197121      187 Feb 25  2014 ._train.txt
-rw-r--r-- 1 root 197121      187 Feb 25  2014 ._val.txt
-rw-r--r-- 1 root 197121 17858008 Aug  8 14:09 caffe_ilsvrc12.tar.gz
-rw-r--r-- 1 root 197121     3787 Jun  8  2014 det_synset_words.txt
-rwxr-xr-x 1 root 197121      610 Aug  8 13:41 get_ilsvrc_aux.sh*
-rw-r--r-- 1 root 197121 14931117 Jul 11  2014 imagenet.bet.pickle
-rw-r--r-- 1 root 197121   786446 Feb 25  2014 imagenet_mean.binaryproto
-rw-r--r-- 1 root 197121    31675 Apr  8  2014 synset_words.txt
-rw-r--r-- 1 root 197121    10000 Feb 25  2014 synsets.txt
-rw-r--r-- 1 root 197121  3200000 Feb 25  2014 test.txt
-rw-r--r-- 1 root 197121 43829433 Feb 25  2014 train.txt
-rw-r--r-- 1 root 197121  1644500 Feb 25  2014 val.txt

我不确定是否还需要使用文件imagenet_mean.binaryprotoimagenet.bet.pickle

有人可以澄清一下吗?

您需要减去图像均值。

当训练深度模型时,通常将输入标准化为大致均值= 0。 对于Caffe的AlexNet,图像均值保存在imagenet_mean.binaryproto

有关如何使用预训练模型来获得分类结果的信息,请参见此示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM