Train a neural Network with a Table input

9 visualizzazioni (ultimi 30 giorni)
Mauritz Wilshusen
Mauritz Wilshusen il 21 Mar 2022
Risposto: Abhaya il 6 Dic 2024
Hi i want to train a neural network with a Table in put. The Table is structured as input(rawdata = 111x1 Cell, with each cell a 512x1 Cell) and Response(label = 111x1 Cell). I tried a lot, but it seems to be more compllicated then i thought. I will paste the code Itried so far, but I dont know what to try next.
T = table(rawdata,label);
tblraw = table(rawdata);
tbllabel = (label);
head(T);
numObservations = size(T, 1);
numObservationsTrain = floor(0.85*numObservations);
numObservationsTest = numObservations - numObservationsTrain;
idx = randperm(numObservations);
idxTrain = idx(1:numObservationsTrain);
idxTest = idx(numObservationsTrain+1:end);
tblTrain = tabulate(idxTrain,:);
tblTest = tabulate(idxTest,:);
This is from a matlab example.
This is the Table
and this is the input in the cell, with different data but same formats:
Thanks, I am noob btw

Risposte (1)

Abhaya
Abhaya il 6 Dic 2024
To use data from a table containing cell arrays in a neural network, you need to convert the data into a matrix format.
Please refer to the steps given below to prepare the data and train a neural network using the table data.
  • Data Preparation: Convert the 'rawdata' column, which is currently stored as a cell array, into a numeric matrix. Each 512x1 cell should be converted into a row, creating a 111x512 matrix.Convert the labels to categorical format.
X = cell2mat(rawdata);
Y = categorical(label);
  • Create neural network architecture: You can design the neural network architecture using the deep learning layers provided by MATLAB. Here is an example of a simple architecture:
layers = [
featureInputLayer(512) % Input layer with 512 features
fullyConnectedLayer(64) % Hidden layer with 64 neurons
reluLayer % Activation function
fullyConnectedLayer(10) % Output layer with 10 classes (adjust if needed)
softmaxLayer % For multi-class classification
classificationLayer % Loss layer for classification
];
  • Set Training Options: Configure the training options using the MATLAB ‘trainingOptions’ function:
options = trainingOptions('adam', ...
'MaxEpochs', 50, ... % Number of epochs
'MiniBatchSize', 32, ... % Batch size
'Shuffle', 'every-epoch', ...
'Plots', 'training-progress');
  • Train the network: You can use the MATLAB ‘trainNetwork’ function to train the network.
net = trainNetwork(X, Y, layers, options);
For more detailed information, please refer to the MATLAB documentations on ‘trainNetwork’ function and ‘trainingOptions’ function.
I hope this helps.

Categorie

Scopri di più su Deep Learning Toolbox in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by