Except for the first iteration others show NaN

2 visualizzazioni (ultimi 30 giorni)
When I start training my CNN it shows me training details only on first iteration, and I've already check the training data size and the validation data size is 100000 and 20000, I was wondering is it normal process or not. Thank you.
  2 Commenti
Chunru
Chunru il 1 Set 2021
Check if the train data contains any nan.
KAI-YANG WANG
KAI-YANG WANG il 1 Set 2021
Thank you for the answer, Ive checked there's no nan in my training data.

Accedi per commentare.

Risposta accettata

KSSV
KSSV il 1 Set 2021
Try reducing the initial learning rate.
options = trainingOptions('adam') ;
options.InitialLearnRate
ans = 1.0000e-03
options.InitialLearnRate = 10^-4 ;
options.InitialLearnRate
ans = 1.0000e-04
If the above works well and good. If not show us your full code and data.
  2 Commenti
KAI-YANG WANG
KAI-YANG WANG il 1 Set 2021
Thank you so much and I've try to reduce the initial learning rate, but still the same. My code is attached below.
location='\\ikb\home\25\1939725\Desktop\cost2100-master mimo\matlab\CNN\csitrain\Htrain'
imds = imageDatastore(location,'FileExtensions','.mat','IncludeSubfolders',1, ...
'LabelSource','foldernames');
imdsx=imageDatastore(location,'FileExtensions','.mat','IncludeSubfolders',1, ...
'LabelSource','foldernames');
imdsy=imageDatastore(location,'FileExtensions','.mat','IncludeSubfolders',1, ...
'LabelSource','foldernames');
countEachLabel(imds)
trainingDS = imds;
trainingDS.Labels = categorical(trainingDS.Labels);
trainingDS.ReadFcn=@readFcn1;
countEachLabel(imdsx)
trainingDS2 = imdsx;
trainingDS2.Labels = categorical(trainingDS.Labels);
trainingDS2.ReadFcn=@readFcn2;
countEachLabel(imdsy)
trainingDS2 = imdsy;
trainingDS2.Labels = categorical(trainingDS.Labels);
trainingDS2.ReadFcn=@readFcn3;
dsTrain = transform(imds,@commonPreprocessing);
dsVal = transform(imdsx,@commonPreprocessing);
dstest = transform(imdsy,@commonPreprocessing);
trainData=combine(dsTrain,dsTrain);
valData=combine(dsVal,dsVal);
%Designed concolutional network
maxEpochs = 200;
options = trainingOptions('sgdm', ...
'ValidationData', valData,...
'InitialLearnRate',0.0001,...
'ExecutionEnvironment','gpu', ...
'LearnRateSchedule','piecewise', ...
'MaxEpochs',maxEpochs, ...
'MiniBatchSize',200, ...
'Plots','training-progress')
doTraining = true;
if doTraining
modelDateTime = string(datetime('now','Format',"yyyy-MM-dd-HH-mm-ss"));
net =trainNetwork(trainData, lgraph, options);
save(strcat("trainedCNN-",modelDateTime,"-Epoch-",num2str(maxEpochs),".mat"),'net');
else
load('traindata.mat');
end
YPredicted = predict(net,dstest);
function dataOut = commonPreprocessing(data)
dataOut = cell(size(data));
for col = 1:size(data,2)
for idx = 1:size(data,1)
temp = single(data{idx,col});
temp = reshape(temp,[32,32,2]);
temp = rescale(temp);
dataOut{idx,col} = temp;
end
end
end
KAI-YANG WANG
KAI-YANG WANG il 2 Set 2021
I've tried a further lower learning rate and it does help, Thank you!

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by