I need help on this Deep Network Quantizer code

1 次查看(过去 30 天)
net = inceptionresnetv2();
quantobj = dlquantizer(net,'ExecutionEnvironment','GPU');
imds = imageDatastore('data', ...
'IncludeSubfolders',true, ...
'LabelSource','foldernames');
[calData, valData] = splitEachLabel(imds, 0.6, 'randomized');
aug_calData = augmentedImageDatastore([299 299], calData);
aug_valData = augmentedImageDatastore([299 299], valData);
quantObj = dlquantizer(net);
function accuracy = hComputeModelAccuracy(predictionScores, net, dataStore)
%% Computes model-level accuracy statistics
% Load ground truth
tmp = readall(dataStore);
groundTruth = tmp.response;
% Compare with predicted label with actual ground truth
predictionError = {};
for idx=1:numel(groundTruth)
[~, idy] = max(predictionScores(idx,:));
yActual = net.Layers(end).Classes(idy);
predictionError{end+1} = (yActual == groundTruth(idx)); %#ok
end
% Sum all prediction errors.
predictionError = [predictionError{:}];
accuracy = sum(predictionError)/numel(predictionError);
end
quantOpts = dlquantizationOptions('MetricFcn', ...
{@(x)hComputeModelAccuracy(x, net, aug_valData)});
calResults = calibrate(quantObj, aug_calData)
valResults = validate(quantObj, aug_valData, quantOpts)
valResults.MetricResults.Result
Error
Function definitions in a script must appear at the end of the file.
Move all statements after the "hComputeModelAccuracy" function definition to before the first local function
definition.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Quantization, Projection, and Pruning 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by