train with multiple input to get two classes output

조회 수: 1 (최근 30일)
Rayan Matlob
Rayan Matlob 2022년 7월 11일
댓글: Ben 2022년 7월 13일
I have two folders
folder_1 with two subfolders(good, bad) each with (900 images and 100 image) respectively
folder_2 with two subfolders(good, bad) each with (900 images and 100 image) respectively. when training with pretrained (resnet50) on the "Deep netwoek designer" console, i get the next error about categorical response? any explaination please.
imds_1 = imageDatastore('C:\Users\Folder_1', ...
'IncludeSubfolders',true, ...
'FileExtensions','.jpg', ...
'LabelSource','foldernames');
[imdsTrain_1,imdsValidation_1] = splitEachLabel(imds_1,0.75); %split the data into training and validation
imds_2 = imageDatastore('C:\Users\Folder_2', ...
'IncludeSubfolders',true, ...
'FileExtensions','.jpg', ...
'LabelSource','foldernames');
[imdsTrain_2,imdsValidation_2] = splitEachLabel(imds_2,0.75); %split the data into training and validation
% 'train_ok.txt' contain the labels of the images in (imdsTrain_1 or imdsTrain_2) 750x1
% 'val_ok.txt' contain the labels of the images in (imdsValidation_1 or imdsValidation_2) 250x1
labelStore = tabularTextDatastore('train_ok.txt','TextscanFormats','%C',"ReadVariableNames",false);
labelStoreCell = transform(labelStore,@setcat_and_table_to_cell);
train_multi = combine(imdsTrain_1,imdsTrain_2,labelStoreCell);
train_multi.read
labelStore2 = tabularTextDatastore('val_ok.txt','TextscanFormats','%C',"ReadVariableNames",false);
labelStoreCell2 = transform(labelStore2,@setcat_and_table_to_cell);
val_multi = combine(imdsValidation_1,imdsValidation_2,labelStoreCell2);
val_multi.read
%train_multi.read 750x1
{224×224×3 uint8} {224×224×3 uint8} {[Good ]}
{224×224×3 uint8} {224×224×3 uint8} {[bad ]}
{224×224×3 uint8} {224×224×3 uint8} {[bad ]} ...
%val_multi.read 250x1
{224×224×3 uint8} {224×224×3 uint8} {[Good ]}
{224×224×3 uint8} {224×224×3 uint8} {[Good ]}
{224×224×3 uint8} {224×224×3 uint8} {[bad ]} ....
function [dataout] = setcat_and_table_to_cell(datain)
validcats = ["Good", "bad"];
datain.(1) = setcats(datain.(1),validcats);
dataout = table2cell(datain);
end
  댓글 수: 9
Rayan Matlob
Rayan Matlob 2022년 7월 12일
편집: Rayan Matlob 2022년 7월 13일
@Ben, Dear Sir, every thing you said is just correct, even the concatenation is perfectly worked. The error is disappeared.
one last thing you also mentioned and was correct which is the data, it is first all the "Good" images, then all the "bad", and in order to make it random i used
imdsTrain_1 = shuffle(imdsTrain_1);
imdsTrain_2 = shuffle(imdsTrain_2);
The problem now is the order of both (imdsTrain_1 and imdsTrain_2) is not the same! , and the same for (imdsValidation_1 and imdsValidation_2). how to make the shuffle reorder the images of both (imdsTrain_1 and imdsTrain_2) in the same manner?
Ben
Ben 2022년 7월 13일
You can do cds = combine(imdsTrain_1,imdsTrain_2) and call shuffle(cds). You will want to also combine an arrayDatastore (or other Shuffleable datastore) containing the labels to use this for training.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by