资源简介
caffe的matlab使用接口的示例代码及文件
代码片段和文件信息
function [scores maxlabel] = classification_demo(im use_gpu)
% [scores maxlabel] = classification_demo(im use_gpu)
%
% Image classification demo using BVLC CaffeNet.
%
% IMPORTANT: before you run this demo you should download BVLC CaffeNet
% from Model Zoo (http://caffe.berkeleyvision.org/model_zoo.html)
%
% ****************************************************************************
% For detailed documentation and usage on Caffe‘s Matlab interface please
% refer to Caffe Interface Tutorial at
% http://caffe.berkeleyvision.org/tutorial/interfaces.html#matlab
% ****************************************************************************
%
% input
% im color image as uint8 HxWx3
% use_gpu 1 to use the GPU 0 to use the CPU
%
% output
% scores 1000-dimensional ILSVRC score vector
% maxlabel the label of the highest score
%
% You may need to do the following before you start matlab:
% $ export LD_LIBRARY_PATH=/opt/intel/mkl/lib/intel64:/usr/local/cuda-5.5/lib64
% $ export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6
% Or the equivalent based on where things are installed on your system
%
% Usage:
% im = imread(‘../../examples/images/cat.jpg‘);
% scores = classification_demo(im 1);
% [score class] = max(scores);
% Five things to be aware of:
% caffe uses row-major order
% matlab uses column-major order
% caffe uses BGR color channel order
% matlab uses RGB color channel order
% images need to have the data mean subtracted
% Data coming in from matlab needs to be in the order
% [width height channels images]
% where width is the fastest dimension.
% Here is the rough matlab for putting image data into the correct
% format in W x H x C with BGR channels:
% % permute channels from RGB to BGR
% im_data = im(: : [3 2 1]);
% % flip width and height to make width the fastest dimension
% im_data = permute(im_data [2 1 3]);
% % convert from uint8 to single
% im_data = single(im_data);
% % reshape to a fixed size (e.g. 227x227).
% im_data = imresize(im_data [IMAGE_DIM IMAGE_DIM] ‘bilinear‘);
% % subtract mean_data (already in W x H x C with BGR channels)
% im_data = im_data - mean_data;
% If you have multiple images cat them with cat(4 ...)
% Add caffe/matlab to you Matlab search PATH to use matcaffe
% if exist(‘../+caffe‘ ‘dir‘)
% addpath(‘..‘);
% else
% error(‘Please run this demo from caffe/matlab/demo‘);
% end
addpath(‘G:\caffe\caffe-master-MS\Build\x64\Release\matcaffe‘); %如果不行再改成加+caffe
% Set caffe mode
if exist(‘use_gpu‘ ‘var‘) && use_gpu
caffe.set_mode_gpu();
gpu_id = 0; % we will use the first gpu in this demo
caffe.set_device(gpu_id);
else
caffe.set_mode_cpu();
end
% Initialize the network using BVLC CaffeNet for image classification
% Weights (parameter) file needs to be downloaded from Model Zoo.
model_dir = ‘models/bvlc_reference_caffenet/‘;
% model_dir = ‘../../models/bvlc_reference_caffenet/‘;
net_model = [model_dir ‘deploy.prototxt‘];
net_weig
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5661 2016-11-19 20:32 caffe_matlab\classification_demo.m
文件 31674 2016-11-18 22:17 caffe_matlab\synset_words.txt
文件 598 2016-11-20 14:40 caffe_matlab\test.m
目录 0 2016-11-20 14:47 caffe_matlab
----------- --------- ---------- ----- ----
37933 4
相关资源
- 激光典型腔的matlab计算
- shepp-logan模型
- 基于Matlab的smith圆图程序
- matlab人工免疫算法求解TSP问题
- 利用POCS实现图像超分辨率重建的mat
- 图像能量代码用于图像处理中 mat
- MATLAB 带通切比雪夫滤波器代码
- 复杂背景下的动态目标识别,是基于
- 复杂网络的小世界模型的matlab实现
- Matlab与串口通信基础
- 单变量及多变量灰色模型matlab程序
- 一级倒立摆的PID控制
- ldpc的译码matlab程序
- matlab生成正弦波、三角波、锯齿波并
- 谱减法语音增强Matlab
- ISM程序MATLAB.txt
- JPEG编解码matlab
- matlab红外图像两点定标非均匀校正
- hausdorff距离matlab程序
- 模板匹配matlab程序112018
- 蚁群算法的matlab源码
- 调通的ukfslam
- 绝对能用的EKF-SLAM修正错误的版本
- matlab的SPWM逆变电路仿真模型
- 单端反激电路的matlab仿真
- GM11模型MATLAB代码
- 细胞分割计数matlab程序 附GUI
- matlab2013a 密钥
- LQR路径跟踪.rar
- 数学建模MATLAB常见程序源代码
评论
共有 条评论