-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimDataFiles.py
More file actions
40 lines (32 loc) · 1.24 KB
/
SimDataFiles.py
File metadata and controls
40 lines (32 loc) · 1.24 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
from tensorflow.keras import datasets
from tensorflow import keras
import numpy as np
(train_images, train_labels_raw), (test_images, test_labels_raw) = datasets.mnist.load_data()
train_images = train_images / 255
train_images = train_images.reshape(-1, 28, 28, 1)
test_images = test_images / 255
test_images = test_images.reshape(-1, 28, 28, 1)
train_labels = []
for label in train_labels_raw:
output = [0 for x in range(10)]
output[label] = 1
train_labels.append(output)
train_labels = np.array(train_labels)
test_labels = []
for label in test_labels_raw:
output = [0 for x in range(10)]
output[label] = 1
test_labels.append(output)
test_labels = np.array(test_labels)
model = keras.models.load_model('DCTF.h5')
predictions = model.predict(test_images)
fout_images_flat = open('SimData/input.dat', 'w')
fout_labels = open('SimData/labels.dat', 'w')
fout_model_prediction = open('SimData/ModelPredictions.dat', 'w')
for i in range(100):
fout_labels.write(' '.join(test_labels[i].astype(str)) + '\n')
fout_images_flat.write(' '.join(test_images[i].flatten('C').astype(str)) + '\n')
fout_model_prediction.write(' '.join(predictions[i].astype(str)) + '\n')
fout_images_flat.close()
fout_labels.close()
fout_model_prediction.close()