-2

I test my network with the mnist dataset. Therefore the output of the model has shape 10.

How do I reshape the output? For example, if the output is label 3, is then the output [0 0 0 1 0 0 0 0 0 0], or [0 0 0 3 0 0 0 0 0 0] or completely different?

The thing is I don't want to use the dataloader. I use this method:

from mlxtend.data import loadlocal_mnist
X, y = loadlocal_mnist(
            images_path='/home/wai043/data/mnist/train-images-idx3-ubyte', 
            labels_path='/home/wai043/data/mnist/train-labels-idx1-ubyte')
gab
  • 165
  • 2
  • 8
  • what is the output here, is it the result after you perform classification or is it what you get after loading from mnist? – Banks Nov 20 '19 at 04:20

1 Answers1

1

The output has to be [0, 0, 0, 1, 0, 0, 0, 0, 0, 0] if the label is 3. The y parameter you get from loadlocal_mnist has the direct label, so you need to "one-hot encode" y before your training.

You can use the following code to do the encoding

from mlxtend.preprocessing import one_hot
from mlxtend.data import loadlocal_mnist

X, y = loadlocal_mnist(images_path='/home/wai043/data/mnist/train-images-idx3-ubyte', 
                       labels_path='/home/wai043/data/mnist/train-labels-idx1-ubyte')
y = one_hot(y)
Toyo
  • 667
  • 1
  • 5
  • 22