In Deep Learning Toolbox, what input layer should I use for simple dataframe-type input?

1 回表示 (過去 30 日間)
SC
SC 2020 年 4 月 11 日
編集済み: Yomna Genina 2021 年 12 月 7 日
In Deep Learning Toolbox, we can use imageInputLayer() and imageDatastore() for image-type input.
How about the simplest type of input: the dataframe (say an array)?
Which input layer should we use? Should we use datastore() for this type of input?
I don't see many tutorial about this type of input and I got error for the below code. Each of my data point contains 2 features (i.e. size 2x1x1), but when Matlab read the data store, it can only read 1 feature (i.e. 1x1x1).
Failed code
Error message: The training images are of size 1x1x1 but the input layer expects images of size 2x1x1.
data=[ ...
-0.4 -0.8; ...
-1.4 -1.0; ...
-1.5 -1.7; ...
-2.3 -2.0; ...
-1.2 -1.1; ...
];
csvwrite('data.csv',data);
ds_features = datastore('data.csv');
layers = [
imageInputLayer([2 1 1],'Name','in')
fullyConnectedLayer(10,'Name','fc1')
softmaxLayer('Name','sm1')
classificationLayer('Name','cf1')];
lgraph = layerGraph(layers);
options = trainingOptions('sgdm', ...
'MaxEpochs',4, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(ds_features,layers,options);

回答 (3 件)

Srivardhan Gadila
Srivardhan Gadila 2020 年 4 月 14 日
In the above question I see that you haven't provided any target data(classification labels) for training the network.
To use an image datastore as a source of training data, use the imds argument of trainNetwork. To use all other types of datastore as a source of training data, use the ds argument of trainNetwork. To be a valid input for training or validation, the read function of a datastore (with the exception of ImageDatastore) must return data as either a cell array or a table.
For networks with a single input, the table or cell array returned by the datastore must have two columns. The first column of data represents inputs to the network and the second column of data represents responses. Each row of data represents a separate observation.
In case of input size 2x1 & a table, it should be something like below:
>>>data = read(ds)
data =
4×2 table
input response
______________ ________
{2×1 double} 7
{2×1 double} 7
{2×1 double} 9
{2×1 double} 9
  1 件のコメント
SC
SC 2020 年 4 月 27 日
Thanks for your reply. How do you create the ds as you mentioned? I tried the following, but I can only construct a structure, not a datastore. I want a datastore that can be input into my model.
ds_table.response{1}=5;
ds_table.response{2}=9;
ds_table.response{3}=-1;
ds_table.response{4}=6;
ds_table.input{1}=[2 3];
ds_table.input{2}=[-2 8];
ds_table.input{3}=[9 7];
ds_table.input{4}=[1 5];
ds_table

サインインしてコメントする。


Sean de Wolski
Sean de Wolski 2020 年 4 月 14 日
I don't think deep learning is the right approach if your input data has two points. Consider using a standard machine learning technique and the classification learner app.
  1 件のコメント
SC
SC 2020 年 4 月 27 日
Thanks for your reply.
My intention is to use 2 features and several points (i.e. 4 or 5) in my example.
I used this data as a toy model, and I want to extend it into an input of n features and m data points.
Since I am exploring something with dataframe input and the effect of different deep learning architectures, I want to use the Deep Learning toolbox to achieve this.

サインインしてコメントする。


Yomna Genina
Yomna Genina 2021 年 12 月 7 日
編集済み: Yomna Genina 2021 年 12 月 7 日
Starting R2020b, you could use featureInputLayer for a dataset containing numeric features.

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by