资源简介
windows下caffe的matlab接口
代码片段和文件信息
classdef Blob < handle
% Wrapper class of caffe::Blob in matlab
properties (Access = private)
hBlob_self
end
methods
function self = Blob(hBlob_blob)
CHECK(is_valid_handle(hBlob_blob) ‘invalid Blob handle‘);
% setup self handle
self.hBlob_self = hBlob_blob;
end
function shape = shape(self)
shape = caffe_(‘blob_get_shape‘ self.hBlob_self);
end
function reshape(self shape)
shape = self.check_and_preprocess_shape(shape);
caffe_(‘blob_reshape‘ self.hBlob_self shape);
end
function data = get_data(self)
data = caffe_(‘blob_get_data‘ self.hBlob_self);
end
function set_data(self data)
data = self.check_and_preprocess_data(data);
caffe_(‘blob_set_data‘ self.hBlob_self data);
end
function diff = get_diff(self)
diff = caffe_(‘blob_get_diff‘ self.hBlob_self);
end
function set_diff(self diff)
diff = self.check_and_preprocess_data(diff);
caffe_(‘blob_set_diff‘ self.hBlob_self diff);
end
end
methods (Access = private)
function shape = check_and_preprocess_shape(~ shape)
CHECK(isempty(shape) || (isnumeric(shape) && isrow(shape)) ...
‘shape must be a integer row vector‘);
shape = double(shape);
end
function data = check_and_preprocess_data(self data)
CHECK(isnumeric(data) ‘data or diff must be numeric types‘);
self.check_data_size_matches(data);
if ~isa(data ‘single‘)
data = single(data);
end
end
function check_data_size_matches(self data)
% check whether size of data matches shape of this blob
% note: matlab arrays always have at least 2 dimensions. To compare
% shape between size of data and shape of this blob extend shape of
% this blob to have at least 2 dimensions
self_shape_extended = self.shape;
if isempty(self_shape_extended)
% target blob is a scalar (0 dim)
self_shape_extended = [1 1];
elseif isscalar(self_shape_extended)
% target blob is a vector (1 dim)
self_shape_extended = [self_shape_extended 1];
end
% Also matlab cannot have tailing dimension 1 for ndim > 2 so you
% cannot create 20 x 10 x 1 x 1 array in matlab as it becomes 20 x 10
% Extend matlab arrays to have tailing dimension 1 during shape match
data_size_extended = ...
[size(data) ones(1 length(self_shape_extended) - ndims(data))];
is_matched = ...
(length(self_shape_extended) == length(data_size_extended)) ...
&& all(self_shape_extended == data_size_extended);
CHECK(is_matched ...
sprintf(‘%s input data/diff size: [ %s] vs target blob shape: [ %s]‘ ...
‘input data/diff size does not match target blob shape‘ ...
sprintf(‘%d ‘ data_size_extended) sprintf(‘%d ‘ self_shape_extended)));
end
end
end
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 648 2016-02-04 00:38 matlab\+caffe\+test\test_io.m
文件 3971 2016-02-04 00:38 matlab\+caffe\+test\test_net.m
文件 1422 2016-02-04 00:38 matlab\+caffe\+test\test_solver.m
文件 2930 2016-02-04 00:38 matlab\+caffe\Blob.m
文件 1207 2016-02-04 00:38 matlab\+caffe\get_net.m
文件 298 2016-02-04 00:38 matlab\+caffe\get_solver.m
文件 606799 2016-02-04 00:38 matlab\+caffe\imagenet\ilsvrc_2012_mean.mat
文件 191 2016-02-04 00:38 matlab\+caffe\init_glog.m
文件 1742 2016-02-04 00:38 matlab\+caffe\io.m
文件 841 2016-02-04 00:38 matlab\+caffe\la
文件 6222 2016-02-04 00:38 matlab\+caffe\Net.m
文件 23411 2016-02-04 00:38 matlab\+caffe\private\caffe_.cpp
文件 856 2016-02-20 15:26 matlab\+caffe\private\caffe_.exp
文件 1720 2016-02-20 15:26 matlab\+caffe\private\caffe_.lib
文件 4713984 2016-02-20 15:26 matlab\+caffe\private\caffe_.mexw64
文件 15993856 2016-02-20 15:26 matlab\+caffe\private\caffe_.pdb
文件 71 2016-02-04 00:38 matlab\+caffe\private\CHECK.m
文件 118 2016-02-04 00:38 matlab\+caffe\private\CHECK_FILE_EXIST.m
文件 935 2016-02-04 00:38 matlab\+caffe\private\is_valid_handle.m
文件 71 2016-02-04 00:38 matlab\+caffe\private\matcaffe.def
文件 250 2016-02-04 00:38 matlab\+caffe\read_mean.m
文件 172 2016-02-04 00:38 matlab\+caffe\reset_all.m
文件 393 2016-02-04 00:38 matlab\+caffe\run_tests.m
文件 250 2016-02-04 00:38 matlab\+caffe\set_device.m
文件 97 2016-02-04 00:38 matlab\+caffe\set_mode_cpu.m
文件 97 2016-02-04 00:38 matlab\+caffe\set_mode_gpu.m
文件 1787 2016-02-04 00:38 matlab\+caffe\Solver.m
文件 3049 2016-02-04 00:38 matlab\CMakeLists.txt
文件 3544 2016-03-18 20:04 matlab\demo\classification_demo.m
文件 3255 2016-02-04 00:38 matlab\demo\getCifar10Feature.m
............此处省略15个文件信息
评论
共有 条评论