caffe 均值文件binaryproto 转mat

需要使用caffe 的matlab 接口测试分类,所以需要将之前的均值文件转换成.mat

caffe 根目录下,matlab/+caffe 目录下有io.m, 里面写好了一个fuction read_mean() .如下所示。

调用方法, 直接在caffe 的根目录下, 进入matlab,命令行,

>>addpath('./matlab')

>>mean_file = 'path/to/*.binaryproto'

>>image_mean = caffe.io.read_mean(mean_file);

>>save 'path/to/save/*.mat'  image_mean

之后,在你保存的地方就可以看到生成的mat 均值文件

     function im_data = load_image(im_file)
       % im_data = load_image(im_file)
       %   load an image from disk into Caffe-supported data format
       %   switch channels from RGB to BGR, make width the fastest dimension
       %   and convert to single
       %   returns im_data in W x H x C. For colored images, C = 3 in BGR
       %   channels, and for grayscale images, C = 1
       CHECK(ischar(im_file), 'im_file must be a string');
       CHECK_FILE_EXIST(im_file);
       im_data = imread(im_file);
       % permute channels from RGB to BGR for colored images
       if size(im_data, 3) == 3
         im_data = im_data(:, :, [3, 2, 1]);
       end 
       % 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);
     end 
     function mean_data = read_mean(mean_proto_file)
       % mean_data = read_mean(mean_proto_file)
       %   read image mean data from binaryproto file
       %   returns mean_data in W x H x C with BGR channels
       CHECK(ischar(mean_proto_file), 'mean_proto_file must be a string');
       CHECK_FILE_EXIST(mean_proto_file);
       mean_data = caffe_('read_mean', mean_proto_file);
     end 
     function write_mean(mean_data, mean_proto_file)
       % write_mean(mean_data, mean_proto_file)
       %   write image mean data to binaryproto file
       %   mean_data should be W x H x C with BGR channels
       CHECK(ischar(mean_proto_file), 'mean_proto_file must be a string');
       CHECK(isa(mean_data, 'single'), 'mean_data must be a SINGLE matrix');
       caffe_('write_mean', mean_data, mean_proto_file);
     end   
   end 
 end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值