-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_test.py
More file actions
65 lines (55 loc) · 1.36 KB
/
model_test.py
File metadata and controls
65 lines (55 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import json
import pickle
import numpy as np
from qiskit import QuantumCircuit
from qiskit_machine_learning.algorithms.classifiers import NeuralNetworkClassifier
from qiskit_machine_learning.neural_networks import EstimatorQNN
from qiskit.primitives import Estimator
with open("onehot_encoder.pkl", "rb") as f:
enc = pickle.load(f)
classifier = NeuralNetworkClassifier.load("tetris_classifier.model")
# L
# new_image = np.array([
# [0, 0, 0, 0],
# [0, 0, 0, 0],
# [0, 0, 0, 1],
# [0, 1, 1, 1]
# ])
# O
# new_image = np.array([
# [0, 0, 0, 0],
# [0, 1, 1, 0],
# [0, 1, 1, 0],
# [0, 0, 0, 0]
# ])
# I
# new_image = np.array([
# [0, 1, 0, 0],
# [0, 1, 0, 0],
# [0, 1, 0, 0],
# [0, 1, 0, 0]
# ])
# S
# new_image = np.array([
# [0, 0, 0, 0],
# [1, 0, 0, 0],
# [1, 1, 0, 0],
# [0, 1, 0, 0]
# ])
# T (sometimes)
new_image = np.array([
[0, 0, 0, 0],
[0, 0, 1, 0],
[0, 1, 1, 1],
[0, 0, 0, 0]
])
# adding noise to image
for i in range(4):
for j in range(4):
if new_image[i, j] == 0:
new_image[i, j] = np.random.uniform(0, 0.3)
encoded_image = np.array([val * np.pi/2 for val in new_image.flatten()])
# model predicts the block type
prediction = classifier.predict([encoded_image])
predicted_label = enc.inverse_transform(prediction)
print(f"Predicted block type: {predicted_label[0]}")