matlab 测试 caffe model

由于实验需要,需要使用caffe进行训练和测试,所以发布出一个简单的测试caffe model的代码.

(Made by BUAA wangxuehao)

可收藏,禁止转载哈

 

clc; clear all; close all;

addpath(genpath('/usr/home/caffe-master/matlab/'));

caffe.reset_all();
use_gpu=1;
gpu_id=0;
if use_gpu
  caffe.set_mode_gpu();
  caffe.set_device(gpu_id);
else
  caffe.set_mode_cpu();
end
net = caffe.Net('./deploy.prototxt', './SGD_iter_6400.caffemodel', 'test');

dir_rgb = '/media/wang/500G/0Data_Process/Data/RGB/';
dir_depth = '/media/wang/500G/0Data_Process/Data/Depth/';

list = dir([dir_rgb '*.jpg']);
for i=1:length(list)
    disp(num2str(i));
    str = list(i).name;
    rgb = imread([dir_rgb str]);
    depth = imread([dir_depth str]);
    [m,n,~] = size(rgb);
    
    im = single(imresize(rgb,[224,224]));
    depth = single(imresize(depth,[224,224]));
    % RGB
    data = zeros(224,224,3,1,'single');
    data(:,:,1,1) = (im(:,:,3)-103.2505)*0.00390625;
    data(:,:,2,1) = (im(:,:,2)-115.8347)*0.00390625;
    data(:,:,3,1) = (im(:,:,1)-119.7084)*0.00390625;
    data=permute(data,[2 1 3 4]);
    net.blobs('rgb').set_data(data);
    
    net.forward_prefilled();
    
    csal = net.blobs('csal').get_data();
end
caffe.reset_all();

 

你可能感兴趣的:(Matlab,函数应用,机器学习)