- Make sure the "ExecutionEnvironment" is set to 'gpu' explicitly if you want to ensure the use of the GPU. Sometimes 'auto' might not choose the GPU if it detects any issues.
- Ensure you have the Parallel Computing Toolbox installed and configured. This allows MATLAB to leverage multiple CPU cores and the GPU more effectively.
the utilization of cpu and gpu is low, how to increase them?
3 次查看(过去 30 天)
显示 更早的评论
while i am using matlab to train a alexnet from the scratch on window, the utilization ratio of cpu and gpu of my computer is low, and I wonder how to increase them.
here is my code:
trainImagesetPath = 'E:\deep_learning_dataset\tiny-imagenet-200\train';
valImagesetPath = 'E:\deep_learning_dataset\tiny-imagenet-200\val';
testImagesetPath = 'E:\deep_learning_dataset\tiny-imagenet-200\test';
miniBatchSize = 960;
imdsTrain = imageDatastore(trainImagesetPath, 'IncludeSubfolders', true, ...
'LabelSource', 'foldernames', 'FileExtensions',{'.jpg','.JPG', '.JPEG'}, 'ReadSize', miniBatchSize);
imdsValidation = imageDatastore(valImagesetPath, 'IncludeSubfolders', true, ...
'LabelSource', 'foldernames', 'FileExtensions',{'.jpg','.JPG', '.JPEG'}, 'ReadSize', miniBatchSize);
imdsTest = imageDatastore(testImagesetPath, 'IncludeSubfolders', true);
layers = [imageInputLayer([224 224 3])
convolution2dLayer(11, 96, 'Stride', [4, 4], 'Padding', [0 0 0 0])
reluLayer
batchNormalizationLayer
maxPooling2dLayer(3, 'Stride', [2, 2], 'Padding', [0 0 0 0])
groupedConvolution2dLayer(5, 128, 2, 'Stride', [1, 1], 'Padding', [2 2 2 2])
reluLayer
batchNormalizationLayer
maxPooling2dLayer(3, 'Stride', [2, 2], 'Padding', [0 0 0 0])
convolution2dLayer(3, 384, 'Stride', [1, 1], 'Padding', [1 1 1 1])
reluLayer
groupedConvolution2dLayer(3, 192, 2, 'Stride', [1, 1], 'Padding', [1 1 1 1])
reluLayer
groupedConvolution2dLayer(3, 128, 2, 'Stride', [1, 1], 'Padding', [1 1 1 1])
reluLayer
maxPooling2dLayer(3, 'Stride', [2, 2], 'Padding', [0 0 0 0])
fullyConnectedLayer(4096)
reluLayer
dropoutLayer(0.5)
fullyConnectedLayer(4096)
reluLayer
dropoutLayer(0.5)
fullyConnectedLayer(200)
softmaxLayer
classificationLayer
];
% analyzeNetwork(layers);
inputSize = [224, 224, 3];
augimdsTrain = augmentedImageDatastore(inputSize, imdsTrain, 'ColorPreprocessing', 'gray2rgb', 'DispatchInBackground', true);
augimdsValidation = augmentedImageDatastore(inputSize, imdsValidation, 'ColorPreprocessing', 'gray2rgb', 'DispatchInBackground', true);
augimdsTest = augmentedImageDatastore(inputSize, imdsTest, 'ColorPreprocessing', 'gray2rgb');
options = trainingOptions('adam', ...
'MiniBatchSize', miniBatchSize, ...
'MaxEpochs',120, ...
'InitialLearnRate',1e-4, ...
'LearnRateSchedule', 'piecewise', ...
'LearnRateDropFactor', 0.25, ...
'LearnRateDropPeriod', 5, ...
'DispatchInBackground', true, ...
'Shuffle','every-epoch', ...
'ValidationData', augimdsValidation, ...
'ValidationFrequency', 20, ...
'Verbose',true, ...
'Plots','training-progress', ...
'ExecutionEnvironment', 'auto');
tic
alexNetModel = trainNetwork(augimdsTrain,layers,options);
fprintf('training process time cost: ');
toc
[YPred,scores] = classify(alexNetModel,augimdsTest);
YTest = imdsTest.Labels;
accuracy = mean(YPred == YTest);
fprintf('test acc: %f\n', accuracy);
figure
confusionchart(YTest, YPred)
my computer is a lenovo laptop called r9000k 2021 with rtx3080 laptop GPU, and the utilization ratio is shown as follow:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/748799/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/748804/image.png)
0 个评论
回答(1 个)
Meet
2024-12-11
Hi Yan,
You can also refer to this documentation link for more information:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!