Except for the first iteration others show NaN

조회 수: 1 (최근 30일)
KAI-YANG WANG
KAI-YANG WANG 2021년 8월 31일
댓글: KAI-YANG WANG 2021년 9월 2일
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
Chunru
Chunru 2021년 9월 1일
Check if the train data contains any nan.
KAI-YANG WANG
KAI-YANG WANG 2021년 9월 1일
Thank you for the answer, Ive checked there's no nan in my training data.

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2021년 9월 1일
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
KAI-YANG WANG
KAI-YANG WANG 2021년 9월 1일
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 2021년 9월 2일
I've tried a further lower learning rate and it does help, Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Support Vector Machine Regression에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by