matlab 批量提取CNN特征
无类别,图像混合放置:
clear
close all addpath ./matlab model= './models/bvlc_reference_caffenet/deploy.prototxt';
weights= './models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel';
mean = load('./matlab/+caffe/imagenet/ilsvrc_2012_mean.mat');
net = caffe.Net(model, weights, 'test'); % create net and load weights
mean_data = mean.mean_data; net.blobs('data').reshape([ ]);
net.reshape(); rt_img_dir='/ImageNet/ILSVRC2012_img_val/';
rt_data_dir='ImageNet/Fea/ILSVRC2012_img_val/'; %disp('Extracting CNN features...'); frames = dir(fullfile(rt_img_dir, '*')); frames()=[]; frames()=[];
c_num = length(frames);
gray_num=;error_num_CMYK_JPEG=;
% database.path=[]; for jj = :c_num,
imgpath = fullfile(rt_img_dir, frames(jj).name);
try
%% prepare the image
im_data = caffe.io.load_image(imgpath);
%% subtract mean_data (already in W x H x C, BGR)
width = ; height = ;
im_data = imresize(im_data, [width, height]); % resize using Matlab's imresize
feaSet.iscolor=;
if size(im_data,)==
imdata=zeros([size(im_data),]);
imdata(:,:,)=im_data;
imdata(:,:,)=im_data;
imdata(:,:,)=im_data;
im_data=imdata;
feaSet.iscolor=;
gray_num=gray_num+;
end
im_data = im_data - (mean_data); width = ; height = ;
im_data = imresize(im_data, [width, height]); % resize using Matlab's imresize res = net.forward({im_data});
fc6_data = net.blobs('fc6').get_data();
fc7_data = net.blobs('fc7').get_data(); feaSet.fc6_data = fc6_data;
feaSet.fc7_data = fc7_data; [pdir, fname] = fileparts(frames(jj).name);
fpath = fullfile(rt_data_dir, [fname, '.mat']); save(fpath, 'feaSet');
%database.path = [database.path; fpath];
catch
str= fullfile(frames(jj).name);
disp(str);
error_num_CMYK_JPEG=error_num_CMYK_JPEG+;
error_CMYK_JPEG{error_num_CMYK_JPEG}=str;
end
end;
有类别,不同类图像按不同文件夹放置
clear
close all addpath ./matlab model= './models/bvlc_reference_caffenet/deploy.prototxt';
weights= './models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel';
mean = load('./matlab/+caffe/imagenet/ilsvrc_2012_mean.mat');
net = caffe.Net(model, weights, 'test'); % create net and load weights
mean_data = mean.mean_data;
%% obtain params in diff layers and show
%pdata = net.params('conv1',).get_data();
%vis_square(pdata,,0.5); net.blobs('data').reshape([ ]);
net.reshape(); rt_img_dir='mageNet/ILSVRC2012_img_train/';
rt_data_dir='ImageNet/Fea/ILSVRC2012_img_train/'; disp('Extracting CNN features...');
subfolders = dir(rt_img_dir); siftLens = []; database = []; database.imnum = ; % total image number of the database
database.cname = {}; % name of each class
database.label = []; % label of each class
database.path = {}; % contain the pathes for each image of each class
database.nclass = ;
error_num_CMYK_JPEG=;
for ii = :length(subfolders),
subname = subfolders(ii).name; if ~strcmp(subname, '.') & ~strcmp(subname, '..'),
database.nclass = database.nclass + ; database.cname{database.nclass} = subname; frames = dir(fullfile(rt_img_dir, subname, '*'));
frames()=[];frames()=[];
c_num = length(frames);
database.imnum = database.imnum + c_num;
database.label = [database.label; ones(c_num, )*database.nclass]; siftpath = fullfile(rt_data_dir, subname);
if ~isdir(siftpath),
mkdir(siftpath);
end; for jj = :c_num,
imgpath = fullfile(rt_img_dir, subname, frames(jj).name);
try
im_data = caffe.io.load_image(imgpath);
%% subtract mean_data (already in W x H x C, BGR)
width = ; height = ;
im_data = imresize(im_data, [width, height]); % resize using Matlab's imresize
feaSet.iscolor=;
if size(im_data,)==
imdata=zeros([size(im_data),]);
imdata(:,:,)=im_data;
imdata(:,:,)=im_data;
imdata(:,:,)=im_data;
im_data=imdata;
feaSet.iscolor=;
gray_num=gray_num+;
end
feaSet.label= database.nclass; im_data = im_data - (mean_data); width = ; height = ;
im_data = imresize(im_data, [width, height]); % resize using Matlab's imresize res = net.forward({im_data});
fc6_data = net.blobs('fc6').get_data();
fc7_data = net.blobs('fc7').get_data(); feaSet.fc6_data = fc6_data;
feaSet.fc7_data = fc7_data; [pdir, fname] = fileparts(frames(jj).name);
fpath = fullfile(rt_data_dir, subname, [fname, '.mat']); save(fpath, 'feaSet');
catch
str= fullfile(subname,frames(jj).name);
disp(str);
error_num_CMYK_JPEG=error_num_CMYK_JPEG+;
error_CMYK_JPEG{error_num_CMYK_JPEG}=str;
end end;
end;
end;
matlab 批量提取CNN特征的更多相关文章
- 原来CNN是这样提取图像特征的。。。
对于即将到来的人工智能时代,作为一个有理想有追求的程序员,不懂深度学习(Deep Learning)这个超热的领域,会不会感觉马上就out了?作为机器学习的一个分支,深度学习同样需要计算机获得强大的学 ...
- CNN基础二:使用预训练网络提取图像特征
上一节中,我们采用了一个自定义的网络结构,从头开始训练猫狗大战分类器,最终在使用图像增强的方式下得到了82%的验证准确率.但是,想要将深度学习应用于小型图像数据集,通常不会贸然采用复杂网络并且从头开始 ...
- Python 超简单 提取音乐高潮(附批量提取)
很多时候我们想提取某首歌的副歌部分(俗称 高潮部分),只能手动直接卡点剪切,但是对于大批量的获取就很头疼,如何解决? 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后 ...
- 寻找与疾病相关的SNP位点——R语言从SNPedia批量提取搜索数据
是单核苷酸多态性,人的基因是相似的,有些位点上存在差异,这种某个位点的核苷酸差异就做单核苷酸多态性,它影响着生物的性状,影响着对某些疾病的易感性.SNPedia是一个SNP调査百科,它引用各种已经发布 ...
- python实现gabor滤波器提取纹理特征 提取指静脉纹理特征 指静脉切割代码
参考博客:https://blog.csdn.net/xue_wenyuan/article/details/51533953 https://blog.csdn.net/jinshengtao/ar ...
- matlab批量读取一个文件夹里类似命名的mat文件
参考网址: Matlab读取同一路径下多个txt或mat文件总结 matlab 批量读取数据文件.mat .dat 整理:matlab批量读入数据文件的方法 首先命名方式体现在只是名字里数字有变化,其 ...
- PDF文本内容批量提取到Excel
QQ:231469242,版权所有 sklearn实战-乳腺癌细胞数据挖掘 https://study.163.com/course/introduction.htm?courseId=1005269 ...
- 使用matlab批量处理图像后在指定文件夹存储
使用matlab批量处理图像后在指定文件夹存储 clear;clc;close all; Files=dir('D:\文件及下载相关\文档\MATLAB\postgraduate\Kodak\*.jp ...
- VGG16提取图像特征 (torch7)
VGG16提取图像特征 (torch7) VGG16 loadcaffe torch7 下载pretrained model,保存到当前目录下 th> caffemodel_url = 'htt ...
随机推荐
- 移动apache访问日志后如何立即生效
一次偶然测试发现移动了apache下的access_log日志后或者修改了access_log的名称,该移动的日志或修改名称的日志文件仍记录了apache访问信息,即没有实时生效,后来查了资料才知道: ...
- php基础_字符串
1.字符串去掉空格 trim() ltrim() rtrim() 2.字符串的大小写更改 strtoupper():全部转成大写 // aAA bBB 变成 AAA BBB strtolowe ...
- 深入理解git,从研究git目录开始
转发学习的啦. 似乎很少有人在读某个git快速教程的时候会说:“这个关于git的快速教程太酷了!读完了用起git来超级舒服,并且我一点也不怕自己会破坏什么东西.” 对git的初学者来说,刚接触git时 ...
- MYSQL数据库日志和mysqlbinlog相关
mysql有4种不同的日志,分别是二进制日志,查询日志,慢查询日志和错误日志,这些日记记录着数据库工作的方方面面,可以帮助我们了解数据库的不同方面的踪迹,下面介绍二进制日志的作用和使用方法. 1.二进 ...
- UILabel多种字体
UILabel *label = [[UILabel alloc] init]; label.text = @"UILabel多种字体"; UIFont *font = [UIFo ...
- zepto.js学习
除了$( Zepto)对象上的直接方法外(如$.extend),文档对象中的所有方法都是集合方法. $.grep v1.0+ $.grep(items, function(item){ ... }) ...
- 对象序列化到本地文件 ObjectOutputstream ObjcetInputstream
package com.main.test; import java.io.FileInputStream; import java.io.FileNotFoundException; import ...
- Spark源码学习1.2——TaskSchedulerImpl.scala
许久没有写博客了,没有太多时间,最近陆续将Spark源码的一些阅读笔记传上,接下来要修改Spark源码了. 这个类继承于TaskScheduler类,重载了TaskScheduler中的大部分方法,是 ...
- BootStrap 的modal 中使用typeahead
刚开始怎么也不现实,在页面上显示正常. 调试发现是下拉框被modal遮挡住了, 找到样式dropdown-menu 修改z-index值为2000后,显示正常.(modal的z-index值为1 ...
- volatile关键字和mutable关键字
如果不用volatile关键字会如何?可能会造成一个后果就是:编译器发现你多次使用同一个变量的值,然后它可能会假设这个变量是不变的值,并且把这个变量的值放入寄存器中,方便下一次使用,提高存取速度. 一 ...