按步驟來就好:
1. 新建一個空文件夾quickstart使用官方給出的代碼測試:
% 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 ;
報錯1:
'cl.exe' 不是內部或外部命令,也不是可運行的程序 或批處理文件。
解決辦法:
在c盤找到cl.exe文件位置,
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64
將該路徑添加至計算機系統環境變量,然後將MATLAB關閉再重啓就好了。
2. 參考urlwrite函數下載模型速度比較慢:
% 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') ;
可以從網站上直接下載放在當前文件夾中: http://www.vlfeat.org/matconvnet/pretrained/
3. 然後加載預訓練模型-運行:
注:peppers圖片需要自己網上下載保存到當前文件夾
% 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)) ;
之前參照別的博主文章推薦先在官網上下載matconvnet庫出了一堆網上能夠查出來的錯誤,簡直暴風哭泣,這樣重新開始除了cl.exe錯誤之外就很順利了!