muti input cnn in matalb how to do that and how to feed the data in the model?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Jaimin
el 30 de Sept. de 2024
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 comentarios
Arka Roy
el 1 de Oct. de 2024
Editada: Arka Roy
el 1 de Oct. de 2024
1 comentario
Jaimin
el 1 de Oct. de 2024
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.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!