8/12/2023 0 Comments Tensorflow permute mnistThe forward pass on a single example $x$ executes the following computation: We want to build a simple, feed-forward network with 784 inputs (=28 x 28), and a single sigmoid unit generating the output. A Single Neuron (aka Logistic Regression) Looks good, so let’s build our first network. ![]() That’s a zero, so we want the label to be 1, which it is. ![]() Plt.imshow(X_train.reshape(28,28), cmap = matplotlib.cm.binary) Let’s have a look at a random image and label just to make sure we didn’t throw anything out of wack: %matplotlib inline Y_train, y_test = y.reshape(1,m), y.reshape(1,m_test)įinally we’ll shuffle the training set for good measure: np.ed(138) We’ll also transform the data into the shape we want, with each example in a column (instead of a row): m = 60000 The MNIST images are pre-arranged so that the first 60,000 can be used for training, and the last 10,000 for testing. So we’ll overwrite the labels to make that happen: import numpy as np So we want our labels to say 1 when we have a zero, and 0 otherwise (intuitive, I know). But we’re just building a zero-classifier for now. The default MNIST labels record 7 for an image of a seven, 4 for an image of a four, etc. We’ll normalize the data to keep our gradients manageable: X = X / 255 Since it would be rude to neglect their efforts, we’ll just import it: from sklearn.datasets import fetch_mldata But the makers of scikit-learn already did that for us. We could download and preprocess the data ourselves. MNIST contains 70,000 images of hand-written digits, each 28 x 28 pixels, in greyscale with pixel-values from 0 to 255. In a followup post we’ll bring that up into the high nineties by making sundry improvements: better optimization, more hidden layers, and smarter initialization. That’ll give us a 92% accurate digit-recognizer, bringing us up to the cutting edge of 1985 technology. Then we’ll add a softmax for recognizing all the digits 0 through 9. Then we’ll extend that into a network with one hidden layer, still recognizing just 0. But it’ll help us get some key components working before things get more complicated. This is actually just an implementation of logistic regression, which may seem kind of silly. We’ll start with the simplest possible “network”: a single node that recognizes just the digit 0. We will dip into scikit-learn, but only to get the MNIST data and to assess our model once its built. We’ll use just basic Python with NumPy to build our network (no high-level stuff like Keras or TensorFlow). ![]() We’ll train it to recognize hand-written digits, using the famous MNIST data set. In this post we’re going to build a neural network from scratch.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |