フィルターのクリア

GOT AN ERROR ON VGG19 FULLYCONNECTED LAYER

1 回表示 (過去 30 日間)
mohd akmal masud
mohd akmal masud 2022 年 7 月 24 日
回答済み: Siraj 2023 年 9 月 13 日
Dear All
Anyone can help me to solve the problem?
Below is my code for VGG19 net.
I have 75 folder data. In each folder have 5 set images. every images have size 240x240x155.
But I got error below
Error using trainNetwork
Layer 39: Invalid initializer. Requested 75x285696000 (159.6GB) array exceeds maximum array size preference (15.9GB). This might
cause MATLAB to become unresponsive.
Caused by:
Error using nnet.internal.cnn.assembler.InitializeMixin/initializeLearnableParameters
Layer 39: Invalid initializer. Requested 75x285696000 (159.6GB) array exceeds maximum array size preference (15.9GB). This
might cause MATLAB to become unresponsive.
Related documentation
below is my code
clc
clear all
close all
%testDataimages
volReader = @(x) niftiread(x);
volds = imageDatastore('C:\Users\USER\Downloads\LGG',...
'IncludeSubfolders', true,...
'LabelSource', 'foldernames','FileExtensions','.nii','ReadFcn',volReader);
layers = [
image3dInputLayer([240 240 155],"Name","image3dinput")
convolution3dLayer([3 3 3],32,"Name","conv3d_1","Padding","same")
reluLayer("Name","relu_1")
convolution3dLayer([3 3 3],32,"Name","conv3d_2","Padding","same")
reluLayer("Name","relu_2")
maxPooling3dLayer([5 5 5],"Name","maxpool3d_1","Padding","same")
convolution3dLayer([3 3 3],32,"Name","conv3d_3","Padding","same")
reluLayer("Name","relu_3")
convolution3dLayer([3 3 3],32,"Name","conv3d_4","Padding","same")
reluLayer("Name","relu_4")
maxPooling3dLayer([5 5 5],"Name","maxpool3d_2","Padding","same")
convolution3dLayer([3 3 3],32,"Name","conv3d_5","Padding","same")
reluLayer("Name","relu_5")
convolution3dLayer([3 3 3],32,"Name","conv3d_6","Padding","same")
reluLayer("Name","relu_6")
convolution3dLayer([3 3 3],32,"Name","conv3d_7","Padding","same")
reluLayer("Name","relu_7")
convolution3dLayer([3 3 3],32,"Name","conv3d_8","Padding","same")
reluLayer("Name","relu_8")
maxPooling3dLayer([5 5 5],"Name","maxpool3d_3","Padding","same")
convolution3dLayer([3 3 3],32,"Name","conv3d_9","Padding","same")
reluLayer("Name","relu_9")
convolution3dLayer([3 3 3],32,"Name","conv3d_10","Padding","same")
reluLayer("Name","relu_10")
convolution3dLayer([3 3 3],32,"Name","conv3d_11","Padding","same")
reluLayer("Name","relu_11")
convolution3dLayer([3 3 3],32,"Name","conv3d_12","Padding","same")
reluLayer("Name","relu_12")
maxPooling3dLayer([5 5 5],"Name","maxpool3d_4","Padding","same")
convolution3dLayer([3 3 3],32,"Name","conv3d_13","Padding","same")
reluLayer("Name","relu_13")
convolution3dLayer([3 3 3],32,"Name","conv3d_14","Padding","same")
reluLayer("Name","relu_14")
convolution3dLayer([3 3 3],32,"Name","conv3d_15","Padding","same")
reluLayer("Name","relu_15")
convolution3dLayer([3 3 3],32,"Name","conv3d_16","Padding","same")
reluLayer("Name","relu_16")
maxPooling3dLayer([5 5 5],"Name","maxpool3d_5","Padding","same")
fullyConnectedLayer(75,"Name","fc_3")
reluLayer("Name","relu_18")
dropoutLayer(0.5,"Name","dropout_1")
fullyConnectedLayer(75,"Name","fc_2")
reluLayer("Name","relu_17")
dropoutLayer(0.5,"Name","dropout_2")
fullyConnectedLayer(75,"Name","fc_1")
softmaxLayer("Name","softmax")
pixelClassificationLayer("Name","pixel-class")];
plot(layerGraph(layers));
% Train network - 10000 epochs and 10 Augmentations per mask.
maxEpochs = 200;
options = trainingOptions('adam', ...
'MaxEpochs',maxEpochs, ...
'InitialLearnRate',1e-3, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',5, ...
'LearnRateDropFactor',0.97, ...
'Plots','training-progress', ...
'Verbose',false);
% 'CheckpointPath', checkpointPath );
[convnet, traininfo] = trainNetwork(volds, layers, options);

採用された回答

Siraj
Siraj 2023 年 9 月 13 日
Hi! It is my understanding that the error occurs because of the 39th layer “fc_3”. The weight matrix of this layer is of dimensions 75 X 285696000.
You can verify this information by utilizing the "Analyze Network" feature in the "Deep Network Designer" App. This functionality will allow you to examine the details of each layer in the network, including the dimensions of the weight matrix for the 39th layer ("fc_3").
Attaching the screenshot for your reference.
Total number of elements that will be in the “Weights” matrix for this layer will be “2.1427e+10”.
Run the following command to find the type of “Weights” matrix.
class(layers(39).Weights)
This comes out to be ‘double’ and ‘double’ takes 8 bytes.
So total bytes required comes out to be “1.7142e+11”.
Run the following command to see how much maximum memory MATLAB can allocated to a matrix.
memory
This depends on the system configuration but is generally around “1.556e+10 bytes” which is less than the total bytes required for the “Weights” matrix hence you see the error.
A potential solution to address this issue is to decrease the size of the input images. By reducing the dimensions of the input, the memory requirements for the weight matrix in the 39th layer will be reduced, potentially resolving the error.
Also you can try the following suggestions.
  1. Go to MATLAB > Preferences > Workspace and ensure the Maximum array size limit is set to 100%. Then execute 'memory' command in the Command Window and send the output. Ensure that the Maximum possible array size is larger than the memory required by the data used in neural network.
  2. Also, check that the Java Heap Memory is not set to a very large value because that might restrict the amount of memory available to perform computations.
To learn more about the “memory” command refer to the following link.
To gain a comprehensive understanding of all the things mentioned above, you can refer to the following code snippet. The code includes a variable named "layers," which represents the layer matrix mentioned in your code.
% dimensions of the Weights Matirx
nrows = 75;
ncols = 285696000;
total_elements_in_weights = nrows*ncols
% finding the type of weights matrix.
class(layers(39).Weights) %this comes out to be double.
%calculating how many bytes does a double takes.
temp = 1; %this by default will be double.
n_bytes = whos('temp').bytes %no. of bytes a double takes.
%total bytes required
total_bytes = total_elements_in_weights*n_bytes
memory
%now we can see that the total_bytes required exceed the total Memory
%available, hence we get the error.
Hope this helps.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by