简体   繁体   中英

How to perform a Multi-Class classification in a convoluted neural 1D network with tensorflow?

I have a training file in the following format:

0.086, 0.4343, 0.4212, ...., class1

0.086, 0.4343, 0.4212, ...., class2

0.086, 0.4343, 0.4212, ...., class5

Where, each row is a one-dimensional vector and the last column is the class in which that vector represents. We can see that a vector repeats itself several times, since it has several classes.

Reading this data is done by the python "Panda" library. That said, I need to conduct training with a convolutional network. I already researched some sites and did not get much success and also do not know if the network needs to be prepared for the "Multi-Class" form.

I would like to know if someone knows a multi-class 1D classification approach with tensorflow or could guide me with an example, being that after training the network, I need to pass a template (which would be a vector) and the network output me Give the correct percentage of each class.

Thank you!

This is a pretty straight forward setup.

First thing to know: Your labels need to be in "one hot encoding" format. That means, if you have 5 classes, class 1 is represented by the vector [1,0,0,0,0], class 2 by the vector [0,1,0,0,0], and so on. This is standard.

Second, you mention that you want multi-class classification. But the example you gave is single-class classification. So this is probably a terminology clarification here. When you say multi-class classification it means that you want a single sample to belong to more than one class, let's say your first sample is part of both class 2 and class 3. But it doesn't look like that in your case. So for single-class classification with 5 classes you want to use cross entropy as your loss function.

You can follow the cifar 10 tutorial. This is the same setup where each image is 1 of 10 classes.

https://www.tensorflow.org/tutorials/deep_cnn

You mentioned that your data is 1-dimensional. This is trivial to accomplish, just treat it like the cifar 10 2-dimensional data with one of those dimensions set to be 1. You don't need to change any other code. In the cifar 10 example your images will be 32x32, in your data your images will be maybe 32x1, or 10x1, whatever kernel you decide on (try different kernel sizes!). The same change will apply to stride. Just treat your problem as a 2D problem with a flat 2nd dimension, easy as pie.

From what I understand you have a multi-label problem. Meaning that a sample can belong to more than one classes

Take a look at sigmoid_cross_entropy_with_logits and use that as your loss function.

You do not need to use one hot encoding or repeat your samples for each label they belong to for this loss function. Just use a label vector and set to one the classes that the sample belongs to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM