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!