muti input cnn in matalb how to do that and how to feed the data in the model?
4 ビュー (過去 30 日間)
古いコメントを表示
I want to train a muti input cnn in matalb how to do that and how to feed the data in the model?
like in python we do this:
history=final_model.fit(x=[X_insp_tr, X_exp_tr], y=y_tr,
epochs=100, batch_size=32,
validation_data=([X_insp_val, X_exp_val], y_val))
0 件のコメント
回答 (2 件)
Jaimin
2024 年 9 月 30 日
Hello @Arka Roy
You can utilise “connectLayers” function to build a cnn based deep learning model that accepts multiple inputs.
Kindly refer to the below code for sample model created using the “connectLayers” function.
% Define input layers for each input branch
inputLayer1 = imageInputLayer([28 28 1], 'Name', 'input1'); % Example size
inputLayer2 = imageInputLayer([28 28 1], 'Name', 'input2'); % Example size
% Define branches for each input with explicit layer names
branch1 = [
inputLayer1
convolution2dLayer(3, 8, 'Padding', 'same', 'Name', 'conv1_1')
reluLayer('Name', 'relu1_1')
maxPooling2dLayer(2, 'Stride', 2, 'Name', 'maxpool1_1')
];
branch2 = [
inputLayer2
convolution2dLayer(3, 8, 'Padding', 'same', 'Name', 'conv1_2')
reluLayer('Name', 'relu1_2')
maxPooling2dLayer(2, 'Stride', 2, 'Name', 'maxpool1_2')
];
% Concatenate branches
concatLayer = concatenationLayer(3, 2, 'Name', 'concat');
% Define the rest of the network
finalLayers = [
fullyConnectedLayer(10, 'Name', 'fc')
softmaxLayer('Name', 'softmax')
classificationLayer('Name', 'classoutput')
];
% Assemble the network
layers = layerGraph(branch1);
layers = addLayers(layers, branch2);
layers = addLayers(layers, concatLayer);
layers = connectLayers(layers, 'maxpool1_1', 'concat/in1');
layers = connectLayers(layers, 'maxpool1_2', 'concat/in2');
layers = addLayers(layers, finalLayers);
layers = connectLayers(layers, 'concat', 'fc');
For more information on “connectLayers” function, kindly refer the following MathWorks Documentation:
I hope this will be helpful.
0 件のコメント
Arka Roy
2024 年 10 月 1 日
編集済み: Arka Roy
2024 年 10 月 1 日
1 件のコメント
Jaimin
2024 年 10 月 1 日
You can utilize "imageDatastore" and "arrayDatastore" to read images and labels. Once done, you can merge them using the "combine" function.
Kindly refer to the snippet below.
% Combine data into a datastore
dsTrain = combine(imageDatastore(X_insp_tr), imageDatastore(X_exp_tr), arrayDatastore(y_tr));
dsVal = combine(imageDatastore(X_insp_val), imageDatastore(X_exp_val), arrayDatastore(y_val));
For more information on "imageDatastore", "arrayDatastore" and "combine" function, kindly refer the following MathWorks Documentation:
I hope this will be helpful.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!