% load pre-trained CNN
net = load('imagenet-vgg-f.mat');
% load and preprocess an image
origin_img = imread('input.jpg');
img = imresize(single(origin_img), net.meta.normalization.imageSize(1:2));
imshow(img);
img = img - net.meta.normalization.averageImage;
% run the VGG
res = vl_simplenn(net, img);
% show the classification result
scores = squeeze(gather(res(end).x));
[bestScore, best] = max(scores);
figure(1);clf;
imagesc(origin_img);
title(sprintf('%s(%d),score %.3f', net.meta.classes.description{best},best,bestScore));
% show first conv kernel
figure(2); clf; colormap gray;
f1 = squeeze(net.layers{1}.weights{1});
vl_imarraysc(f1,'spacing',2);
axis equal ;
title('filters in the first layer') ;
% show first feature map
figure(3); clf; colormap gray;
f_t = squeeze(res(3).x);
f2 = zeros(54,54,3,64);
for i = 1:64
f2(:,:,:,i) = color_remap(f_t(:,:,i));
end
vl_imarraysc(f2);
axis equal ;
title('the first layer feature map') ;
% show second feature map
figure(4); clf; colormap gray;
f_t = squeeze(res(7).x);
minVal = min(min(min(min(f_t))));
maxVal = max(max(max(max(f_t))));
f_t = (f_t - minVal) / (maxVal - minVal) * 255;
f3 = zeros(27,27,3,64);
for i = 1:64
f3(:,:,:,i) = color_remap(f_t(:,:,i));
end
vl_imarraysc(f3);
axis equal ;
title('the second layer feature map') ;
% show third feature map
figure(5); clf; colormap gray;
f_t = squeeze(res(11).x);
minVal = min(min(min(min(f_t))));
maxVal = max(max(max(max(f_t))));
f_t = (f_t - minVal) / (maxVal - minVal) * 255;
f4 = zeros(13,13,3,64);
for i = 1:64
f4(:,:,:,i) = color_remap(f_t(:,:,i));
end
vl_imarraysc(f4);
axis equal ;
title('the third layer feature map') ;
% show fourth feature map
figure(6); clf; colormap gray;
f_t = squeeze(res(13).x);
minVal = min(min(min(min(f_t))));
maxVal = max(max(max(max(f_t))));
f_t = (f_t - minVal) / (maxVal - minVal) * 255;
f5 = zeros(13,13,3,64);
for i = 1:64
f5(:,:,:,i) = color_remap(f_t(:,:,i));
end
vl_imarraysc(f5);
axis equal ;
title('the fourth layer feature map') ;
% show fifth feature map
figure(7); clf; colormap gray;
f_t = squeeze(res(15).x);
minVal = min(min(min(min(f_t))));
maxVal = max(max(max(max(f_t))));
f_t = (f_t - minVal) / (maxVal - minVal) * 255;
f6 = zeros(13,13,3,64);
for i = 1:64
f6(:,:,:,i) = color_remap(f_t(:,:,i));
end
vl_imarraysc(f6);
axis equal ;
title('the fifth layer feature map') ;
没有合适的资源?快使用搜索试试~ 我知道了~
CNN特征图可视化
共3个文件
m:2个
jpg:1个
3星 · 超过75%的资源 需积分: 50 182 下载量 155 浏览量
2018-05-18
10:33:54
上传
评论 6
收藏 27KB ZIP 举报
温馨提示
基于MATLAB中MatConvNet工具包实现的VGG网络特征图和卷积核可视化
资源推荐
资源详情
资源评论
收起资源包目录
vgg_visualization.zip (3个子文件)
color_remap.m 637B
input.jpg 25KB
vgg_vis.m 2KB
共 3 条
- 1
资源评论
- 温杰2018-07-14给别人下载的,不知道能用不,应该不错
- 凶萌的小老虎2020-11-17跑不出来,很郁闷
- 富哥922019-04-29缺了个.mat文件
- congcong0505092019-04-01还行,不知道能不能运行出来
jsgaobiao
- 粉丝: 286
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功