初识caffe的Matlab接口

 转自:https://www.cnblogs.com/wangnianbing/p/7287895.html

%  Copyright (c) 2015, Omkar M. Parkhi
%  All rights reserved.
clear all;
clc;
img = imread('ak.png');
img = double(img);

%训练的时候得到的每个通道平均值,在测试阶段需要每张图像减去对应通道的平均值
%对应的论文还没有看,好奇这里的均值不应该是图像大小么,类似于平均脸
averageImage = [129.1863,104.7624,93.5940] ;

img = cat(3,img(:,:,1)-averageImage(1),...
    img(:,:,2)-averageImage(2),...
    img(:,:,3)-averageImage(3));

img = img(:, :, [3, 2, 1]);%将RGB图像转换成BGR图像
model = 'VGG_FACE_deploy.prototxt'; %定义的网络结构都在其中
weights = 'VGG_FACE.caffemodel'; %用两百多万图片训练的权重参数
caffe.set_mode_gpu(); %设置GPU模式,GF820伤不起
net = caffe.Net(model, weights, 'test'); %创建网络,加载权重系数,声明'test'是避免前向传播的时候使用dropout

res = net.forward({img}); %前向传播得到最后一层的输出结果,其中参数需要是cell类型
prob = res{1};

caffe_ft =net.blobs('fc7').get_data();%取出全连接层名字为fc7的数据,这里提取的数据一般可以作为特征再在其它分类器中使用

猜你喜欢

转载自blog.csdn.net/justforacm/article/details/83247485
今日推荐