In what follows, We present an image classification model built using using QCi's EmuCore technology.
The dataset consists of 70,000 images of handwritten digits 0-9; 60,000 samples are used for training and the remaining 10,000 images are kept for testing. Each sample is a 28 x 28 pixel image.
The images are serialized in one of the two spatial directions and sent through EmuCore. The output is an enriched dataset which is then used to train a simple linear model.
Get train and test datasets
We use the mnist package from tensorflow to import training data.
As each image is 28 by 28 pixels, each sample in the data consists of a 28 by 28 matrix. The elements of the matrix are integers between 0 and 255, each representing one of the 256 colors. We can normalize values to a 0-1 range. This normalization improves the behavior of the reservoir.
In [35]:
x_train = x_train.astype('float32')
x_test = x_test.astype('float32')
x_train = x_train / 255.0
x_test = x_test / 255.0
Flatten data
We should now flatten in one of the two spatial directions. We have tested with both directions and the results are nearly identical.
Training response shape: (60000, 2500)
Testing response shape: (10000, 2500)
Build a linear model
We should now build a linear model based on the responses from the reservoir. As each label (from 0 to 9) represents a category of digits, the labels are converted to categorical values; each label is converted to an array with one element set to 1 and the other elements set to -1.
We can calculate the success rates of classifier on training and testing data,
In [45]:
from sklearn.metrics import accuracy_score
y_train_prd = model.predict(resp_train)
y_test_prd = model.predict(resp_test)
deffrom_categorical(y_cat):
y = []
for i inrange(y_cat.shape[0]):
y.append(np.argmax(y_cat[i]))
return np.array(y)
y_train_prd = from_categorical(y_train_prd)
y_test_prd = from_categorical(y_test_prd)
print(
"Success rate on train data: %0.3f" % (
accuracy_score(y_train, y_train_prd)
)
)
print(
"Success rate on test data: %0.3f" % (
accuracy_score(y_test, y_test_prd)
)
)
Out [ ]:
Success rate on train data: 0.919
Success rate on test data: 0.903
Conclusion
QCi's EmuCore reservoir technoloy was used to build an image classification model using the MNIST digit dataset. In this approach, images are flattened in one of the two spatial dimensions and are passed through EmuCore. A linear model is then trained using the output of EmuCore. The classification model yields a success rate of about 91% on both training and testing data.