Reference to non-existent field 'normalization'

1 visualización (últimos 30 días)
Abdullah Lafir
Abdullah Lafir el 28 de Abr. de 2017
Comentada: pratyush ghosh el 13 de Jul. de 2020
%%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 comentario
Joss Knight
Joss Knight el 28 de Abr. de 2017
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.

Iniciar sesión para comentar.

Respuestas (2)

CONG CAO
CONG CAO el 13 de Oct. de 2017
use 'net.meta.normalization' instead of 'net.normalization'
  1 comentario
pratyush ghosh
pratyush ghosh el 13 de Jul. de 2020
I have tried doing that it says there is an error in Dilate in the vl_simplenn function

Iniciar sesión para comentar.


Sedat METLEK
Sedat METLEK el 10 de Mzo. de 2020
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.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by