Reference to non-existent field 'normalization'

조회 수: 2 (최근 30일)
Abdullah Lafir
Abdullah Lafir 2017년 4월 28일
댓글: pratyush ghosh 2020년 7월 13일
%%Download and predict using a pretrained ImageNet model
% Setup MatConvNet
run(fullfile('matconvnet-1.0-beta24','matlab','vl_setupnn.m'));
% Download ImageNet model from MatConvNet pretrained networks repository
% urlwrite('http://www.vlfeat.org/matconvnet/models/imagenet-vgg-f.mat', 'imagenet-vgg-f.mat');
cnnModel.net = load('imagenet-vgg-f.mat');
% Load and display an example image
imshow('c1.JPG','InitialMagnification','fit');
img = imread('c1.JPG');
% Predict label using ImageNet trained vgg-f CNN model
label = cnnPredict(cnnModel,img,'display', false);
title(label,'FontSize',20)
Error in cnnPredict/cnnPreprocess (line 84)
im = imresize(im, cnnModel.net.normalization.imageSize(1:2));
Error in cnnPredict (line 26)
resTemp = vl_simplenn(cnnModel.net, cnnPreprocess(predImage(:,:,:,1)), [], []);
function [classLabel, scores, batchTime] = cnnPredict(cnnModel,predImage,varargin)
% Copyright (c) 2015, MathWorks, Inc.
% Parse inputs
p = inputParser;
addParameter(p,'outputLayer',numel(cnnModel.net.layers),@isnumeric);
addParameter(p,'UseGPU',false,@islogical);
addParameter(p,'display',true,@islogical);
parse(p,varargin{:});
% Get batch size and number of images
if ~isfield(cnnModel,'info')
cnnModel.info.opts.batchSize = 1;
end
batchSize = cnnModel.info.opts.batchSize;
n_obs = size(predImage,4);
isTapLayer = p.Results.outputLayer < numel(cnnModel.net.layers);
if isTapLayer
cnnModel.net.layers(p.Results.outputLayer+1:end) = [];
else
cnnModel.net.layers{end} = struct('type', 'softmax');
end
% Preallocate scores
resTemp = vl_simplenn(cnnModel.net, cnnPreprocess(predImage(:,:,:,1)), [], []);
scores = zeros([size(resTemp(end).x), n_obs]);
% Move model to GPU if requested
if p.Results.UseGPU
cnnModel.net = vl_simplenn_move(cnnModel.net,'gpu');
end
% Make predictions
batchNumber = 0;
numBatches = ceil(n_obs/batchSize);
batchTime = zeros(numBatches,1);
if p.Results.display
disp(' ')
fprintf('Using GPU: %s\n',mat2str(p.Results.UseGPU))
fprintf('Number of images: %d\n',n_obs)
fprintf('Number of batches: %d\n',numBatches)
fprintf('Number of layers in the Network: %d\n',numel(cnnModel.net.layers))
disp('-------------------------------------')
end
for ii = 1:batchSize:n_obs
tic
idx = ii:min(ii+batchSize-1,n_obs);
batchImages = predImage(:,:,:,idx);
im = cnnPreprocess(batchImages);
% Move batch to GPU if requested
if p.Results.UseGPU
im = gpuArray(im);
end
train_res = vl_simplenn(cnnModel.net, im, [], []);
scores(:,:,:,idx) = squeeze(gather(train_res(end).x));
batchNumber = batchNumber + 1;
batchTime(batchNumber) = toc;
if p.Results.display
fprintf('Batch: %2d/%d. Execution time: %2.4f\n',batchNumber,numBatches,batchTime(batchNumber))
end
end
if p.Results.display
fprintf('Avg. execution time/batch: %2.4f\n',mean(batchTime))
disp('-------------------------------------')
fprintf('Total execution time: %2.4f\n',sum(batchTime))
disp('-------------------------------------')
end
if isTapLayer
classLabel = [];
else
scores = squeeze(gather(scores))';
[~, labelId] = max(scores,[],2);
% classLabel = categorical(cnnModel.net.classes.description(labelId)');
classLabel = cnnModel.net.classes.description(labelId)';
end
function im = cnnPreprocess(batchImages)
% Preprocess images
im = single(batchImages);
im = imresize(im, cnnModel.net.normalization.imageSize(1:2));
im = bsxfun(@minus,im,cnnModel.net.normalization.averageImage);
end
end
  댓글 수: 1
Joss Knight
Joss Knight 2017년 4월 28일
This is a problem you are having with MatConvNet. That should be stated in your title or at least at the start of your problem description, otherwise people are going to have no chance of reproducing it.
Secondly, consider asking the MatConvNet fora.

댓글을 달려면 로그인하십시오.

답변 (2개)

CONG CAO
CONG CAO 2017년 10월 13일
use 'net.meta.normalization' instead of 'net.normalization'
  댓글 수: 1
pratyush ghosh
pratyush ghosh 2020년 7월 13일
I have tried doing that it says there is an error in Dilate in the vl_simplenn function

댓글을 달려면 로그인하십시오.


Sedat METLEK
Sedat METLEK 2020년 3월 10일
Hello, if you examine the matcovnet site, you will see functions with the same name but written differently. So if you test different functions with the same name, your problem will probably be solved.

카테고리

Help CenterFile Exchange에서 Get Started with Microsoft .NET에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by