Dynex commited on
Commit
1a7ff05
1 Parent(s): 5641d1d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +73 -3
README.md CHANGED
@@ -1,3 +1,73 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - am
5
+ - sw
6
+ - wo
7
+ tags:
8
+ - image recognition
9
+ - image classification
10
+ - hand writen digits
11
+ - MNIST dataset
12
+ - quantum machine learning
13
+ - quantum ML
14
+ - quantum boltzmann machine
15
+ - QRBM
16
+ ---
17
+
18
+ # Quantum_rbm_mnist
19
+
20
+ ## Model description
21
+ This model is a pre-trained instance of the Quantum-Restricted-Boltzmann-Machine, focused in image recognition tasks of handwritten digits demonstrating quantum machine learning.
22
+
23
+ ## Training data
24
+
25
+ The model was pre-trained using the well known MNIST dataset. MNIST is a widely used dataset of handwritten digits that contains 60,000 handwritten digits for training a machine learning model and 10,000 handwritten digits for testing the model. It was introduced in 1998 and has become a standard benchmark for classification tasks.
26
+
27
+ ## Model Architecture
28
+
29
+ This model uses only one DynexQRBM PyTorch layer with 300 hidden nodes, combined with simple transfer learning using logistic regression. Due to its quantum algorithm approach, it evolves in only 1 training epoch to a training accuracy >99% and test accuracy >96%, which improves within a few more iterations.
30
+
31
+ ## Usage
32
+ This model is used for image recognition tasks of handwritten digits. It serves as a demonstration of quantum based machine learning algorithms and their effectiveness. To use this model:
33
+
34
+ ```
35
+ from sklearn.linear_model import LogisticRegression
36
+ from HybridQRBM.pytorchdnx import dnx
37
+ from HybridQRBM.optimizers import RBMOptimizer
38
+ from HybridQRBM.samplers import DynexSampler
39
+
40
+ testmodel = torch.load('quantum_rbm_mnist.pth');
41
+ _, features = testmodel.dnxlayer.sampler.predict(data, num_particles=10,num_gibbs_updates=1)
42
+
43
+ # extract hidden layers from QRBM:
44
+ hidden, prob_hidden = testmodel.dnxlayer.sampler.infer(data)
45
+ # Logistic Regression classifier on hidden nodes:
46
+ from sklearn.linear_model import LogisticRegression
47
+ t = hidden * prob_hidden
48
+ clf = LogisticRegression(max_iter=10000)
49
+ clf.fit(t, data_labels)
50
+ predictions = clf.predict(t)
51
+ print('Accuracy:', (sum(predictions == data_labels) / data_labels.shape[0]) * 100,'%')
52
+
53
+ # plot reconstructed images:
54
+ fig = plt.figure(figsize=(10, 7));
55
+ fig.suptitle('Reconstructed Dataset (50 samples)', fontsize=16)
56
+ rows = 5;
57
+ columns = 10;
58
+ for i in range(0,50):
59
+ fig.add_subplot(rows, columns, i+1)
60
+ plt.imshow(features[i].reshape(28,28))
61
+ marker=str(predictions[i])+' (t='+str(data_labels[i])+')'
62
+ plt.title(marker)
63
+ plt.axis('off');
64
+ plt.show()
65
+ ```
66
+
67
+ ## Performance
68
+
69
+ The model's performance was evaluated by accuracy. The effectiveness of the QRBM training is visible after a 1 training iteration and improves further within just a few more epochs.
70
+
71
+ ## Limitations
72
+
73
+ This model is for demonstration purposes and uses binary encoding. It can be easily modified to support color images by converting float values to its binary representation (Qubovert, Qubolite and other packages provide functions for this).