cnns模型matlab,MatConvNet: CNNs for MATLAB

本文指导新手通过MatConvNet下载预训练CNN模型,演示如何在MATLAB中加载模型并用于识别图像。步骤包括安装、编译MatConvNet、下载模型、预处理图像和运行分类。适合初学者快速上手图像识别技术。
摘要由CSDN通过智能技术生成

Quick start

If you are new to MatConvNet, cut & paste the following code in a MATLAB window to try out MatConvNet. The code downloads and compiles MatConvNet, downloads a pre-trained CNN, and uses the latter to classify one of MATLAB stock images.

This example requires MATLAB to be interfaced to a C/C++ compiler (try mex -setup if you are unsure). Depending on your Internet connection speed, downloading the CNN model may require some time.

% Install and compile MatConvNet (needed once).

untar('http://www.vlfeat.org/matconvnet/download/matconvnet-1.0-beta25.tar.gz') ;

cd matconvnet-1.0-beta25

run matlab/vl_compilenn ;

% Download a pre-trained CNN from the web (needed once).

urlwrite(...

'http://www.vlfeat.org/matconvnet/models/imagenet-vgg-f.mat', ...

'imagenet-vgg-f.mat') ;

% Setup MatConvNet.

run matlab/vl_setupnn ;

% Load a model and upgrade it to MatConvNet current version.

net = load('imagenet-vgg-f.mat') ;

net = vl_simplenn_tidy(net) ;

% Obtain and preprocess an image.

im = imread('peppers.png') ;

im_ = single(im) ; % note: 255 range

im_ = imresize(im_, net.meta.normalization.imageSize(1:2)) ;

im_ = im_ - net.meta.normalization.averageImage ;

% Run the CNN.

res = vl_simplenn(net, im_) ;

% Show the classification result.

scores = squeeze(gather(res(end).x)) ;

[bestScore, best] = max(scores) ;

figure(1) ; clf ; imagesc(im) ;

title(sprintf('%s (%d), score %.3f',...

net.meta.classes.description{best}, best, bestScore)) ;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值