I need help on this Deep Network Quantizer code
1 次查看(过去 30 天)
显示 更早的评论
I copied this code from https://www.mathworks.com/help/deeplearning/ref/deepnetworkquantizer-app.html
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Quantization, Projection, and Pruning 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!