资源简介
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_OFDM调制解调(来自剑桥大学)
- Matlab路面裂缝识别69319
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
评论
共有 条评论