I need help on this Deep Network Quantizer code

1 view (last 30 days)
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.

Answers (0)

Categories

Find more on Quantization, Projection, and Pruning in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!