学习笔记之 初试Caffe,Matlab接口提取feature

Caffe 提供了matlab接口,可以用于提取图像的feature.





首先,打开终端,进入caffe的主目录下,然后打开Matlab
...
默认的文件是:classification_demo.m,
里面有两个函数。把路径设置完了之后,就可以试试运行了。我把它改成了我比较习惯的方式,即:xiao.m 

clc;

close all;

clear all;

num1=1000;
% 提取多少张图像的feature

use_gpu=1;
% 运行的模式,gpu
or cpu ?

if
exist('../+caffe',
'dir')

addpath('..');

else

error('Please
run this demo from caffe/matlab/demo');

end

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

model_dir
= '../../models/bvlc_reference_caffenet/';

net_model
= [model_dir 'deploy.prototxt'];

net_weights
= [model_dir 'bvlc_reference_caffenet.caffemodel'];

phase
= 'train';

if
~exist(net_weights, 'file')

error('Please
download CaffeNet from Model Zoo before you run this demo');

end

%
Initialize a network

net
= caffe.Net(net_model, net_weights, phase);

fprintf('Read
PETA-dataset images and Extract features ...\n');

dataPath
= '../../Link to PETA
dataset/3DPeS/archive/';

images
= dir([dataPath,'*.bmp']);

 

for
num=1:num1

 

%
disp('read the', num2str(num) ,'th', '/', num2str(num1) ,'image,
please waiting ...');

im
= imread([dataPath, images(num).name]);

fid1
= fopen('train_feature_id.txt',
'a');

fprintf(fid1,
'%s \n',
images(num).name );

fclose(fid1);

 

 

%
prepare oversampled input

%
input_data is Height x Width x Channel x Num

%
tic;

input_data
= {prepare_image(im)};

%
toc;

%
do forward pass to get scores ­

%
scores are now Channels x Num, where Channels == 1000

%
tic;

%
The net forward function. It takes in a cell array of N-D arrays

%
(where N == 4 here) containing data of input blob(s) and outputs a
cell

%
array containing data from output blob(s)

scores
= net.forward(input_data);

Score
= scores{1,1};

fid
= fopen('train_feature.txt',
'a');

fprintf(fid,
'%f \n',
Score);

fclose(fid);

 

%
toc;

%
scores = scores{1};

%
scores = mean(scores, 2); % take average scores over 10 crops

%
[~, maxlabel] = max(scores);

%
call caffe.reset_all() to reset caffe

%
caffe.reset_all();

 

end

这个函数调用了
prepare_image.m,因为caffe对图像的处理方式和常规的方式不同,需要对读取的图像做一个转换工作,而这个过程是由
prepare_image.m来完成的。

运行之后,就会生成两个txt文件,一个是读取图像的图像名字,另一个是对应所提取的feature。

 

 

 

 

 







        (a) train_feature_id          (b)  train_feature
由于这个网络的输入是255×255的图像,会对其做一个crop,生成10个227×227的图像,所以最后的feature为4096×10
的矩阵,而不是4096的向量。。。








				
时间: 2024-10-18 13:24:47

学习笔记之 初试Caffe,Matlab接口提取feature的相关文章

学习笔记之 初试Linux遇到的问题 2015-10-13

1. 安装.deb文件,用sudo gdebi XXX.deb sudo apt-get install xxx 2. 需要配置系统路径: LD_LIBRARY_PATH=.../lib:LD_LIBRARY_PATH export LD_LIBRARY_PATH 3. ln -sf xxx xxx 软链接 4. Training LeNet on MNIST with Caffe:   wangxiao@wangxiao-Aspire-VN7-591G:~/Downloads/caffe-ma

学习笔记-用反射动态给接口实现类

问题描述 usingSystem;usingSystem.Reflection;usingSystem.Reflection.Emit;publicinterfaceIAnimal{voidmove();voideat();}publicclassTypeCreator{privateTypetargetType;///<summary>///构造函数///</summary>///<paramname="targetType">被实现或者继承的类型

spring学习笔记(2)文件资源访问接口Resource

spring 资源抽象接口下的几个常用实现类 实现类 说明 ClassPathResource 类路径下的资源,资源以相对类路径的方式表示 FileSystemResource 文件系统资源,资源以文件系统路径的的方式表示,如/home/root/test.txt ServletContextResource 为访问web上下文中的资源而设计的类,负责以相对于web应用根目录的路径加载资源,它支持以流和URL的方式访问,在war解包情况下,也可以通过File的方式访问,该类还可以直接从jar包中

PHP 面向对象程序设计(oop)学习笔记(一) - 抽象类、对象接口、instanceof 和契约式编程_php实例

1.PHP中的抽象类 PHP 5 支持抽象类和抽象方法.定义为抽象的类不能被实例化.任何一个类,如果它里面至少有一个方法是被声明为抽象的,那么这个类就必须被声明为抽象的.被定义为抽象的方法只是声明了其调用方式(参数),不能定义其具体的功能实现.在类的声明中使用 abstract 修饰符可以将某个类声明为抽象的. 可以这样理解,抽象类作为一个基类,它把特定的细节留给继承者来实现.通过抽象概念,可以在开发项目中创建扩展性很好的架构. 复制代码 代码如下: abstract class Abstrac

caffe matlab 借口怎么提取灰度图的 feature ? What happened if I mixed the color images with gray images together for training ?

1. caffe matlab 接口提供了提取feature的脚本,但是由于中间要对这些图像进行RGB ---> BGR 的变换,卧槽,灰度图没有三通道啊?怎么破?从上午就在纠结怎么会跑着跑着程序就报错了,尼玛,坑啊...     如何解决这个问题 ?? ----------------------------------------------------------- 我把灰度图给扔了,谢谢!     2. If I use the color images mixed with gray

MySQL数据库学习笔记(九)----JDBC的ResultSet接口(查询操作)、PreparedStatement接口重构增删改查(含SQL注入的解释)

[正文] 首先需要回顾一下上一篇文章中的内容:MySQL数据库学习笔记(八)----JDBC入门及简单增删改数据库的操作 一.ResultSet接口的介绍: 对数据库的查询操作,一般需要返回查询结果,在程序中,JDBC为我们提供了ResultSet接口来专门处理查询结果集. Statement通过以下方法执行一个查询操作: ResultSet executeQuery(String sql) throws SQLException  单词Query就是查询的意思.函数的返回类型是ResultSe

Windows Shellcode学习笔记——Shellcode的提取与测试

本文讲的是Windows Shellcode学习笔记--Shellcode的提取与测试, 0x00 前言 之前在<Windows Shellcode学习笔记--通过VisualStudio生成shellcode>介绍了使用C++编写(不使用内联汇编),实现动态获取API地址并调用,对其反汇编提取shellcode的方法,并开源了测试代码. 接下来在对shellcode进行提取的过程中,发现了当时开源代码的一些bug,所以本文着重解决测试代码的bug,并介绍使用C++开发shellcode需要考

Android开发学习笔记之通过API接口将LaTex数学函数表达式转化为图片形式_Android

本文将讲解如何通过codecogs.com和Google.com提供的API接口来将LaTeX数学函数表达式转化为图片形式.具体思路如下:       (1)通过EditText获取用户输入的LaTeX数学表达式,然后对表达式格式化使之便于网络传输.       (2)将格式化之后的字符串,通过Http请求发送至codecogs.com或者Google.com.       (3)获取网站返回的数据流,将其转化为图片,并显示在ImageView上. 具体过程为: 1.获取并格式化LaTeX数学表

作为一个新手的Oracle(DBA)学习笔记

Oracle数据库笔记 Jack Chaing 作者QQ595696297 交流群 127591054 祝大家学习进步. 如果大家想看Word版本的可以去下载:Word排版比较清晰一些. http://download.csdn.net/detail/jack__chiang/9810532 此笔记是作者本人去年开始从一个DBA新人的学习笔记,积累至今,希望拿出来给那些对DBA有兴趣的童孩学习,大家一起努力嘛. 此笔记记录了作者工作学习中从零基础的学习的记录,和从中遇见的问题与问题的解决!很高兴