-
Notifications
You must be signed in to change notification settings - Fork 0
/
testingStuffs.py
72 lines (63 loc) · 2.14 KB
/
testingStuffs.py
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
66
67
68
69
70
71
72
#%%
import tensorflow as tf
from tensorflow.keras.layers import Dense, Flatten, Dropout, Conv2D, MaxPooling2D, BatchNormalization
from tensorflow.keras.models import Sequential
import os
import random
import numpy as np
from keras.utils.np_utils import to_categorical
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPool2D, BatchNormalization, Activation, MaxPooling2D
from keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import LearningRateScheduler
from keras.datasets import mnist
from keras.models import load_model
from sklearn.model_selection import train_test_split
from keras.utils import np_utils
from PIL import Image
import time
import h5py
import matplotlib.pyplot as plt
from numba import njit
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
@njit
def addDimension(arrayOfImages):
iCounter = 0
jCounter = 0
kCounter = 0
output = np.empty(
(arrayOfImages.shape[0], arrayOfImages.shape[1], arrayOfImages.shape[2], 1))
for i in arrayOfImages:
for j in i:
for k in j:
output[iCounter][jCounter][kCounter] = k
kCounter += 1
kCounter = 0
jCounter += 1
jCounter = 0
iCounter += 1
iCounter = 0
return output
print("done!")
model = load_model('withPreprocessingYAY.h5')
X_train = np.load(r'/home/reid/Documents/khaosTrainData/X_train2.npy')
X_test = np.load(r'/home/reid/Documents/khaosTrainData/X_test2.npy')
y_train = np.load(r'/home/reid/Documents/khaosTrainData/y_train2.npy')
y_test = np.load(r'/home/reid/Documents/khaosTrainData/y_test2.npy')
print(X_train.shape)
X_train = addDimension(X_train)
X_test = addDimension(X_test)
print(X_train.shape)
#%%
counter= 0
startTime = time.time()
for j in range(100):
for i in model.predict(X_test):
plt.imshow(X_test[counter], cmap='gray')
plt.annotate(str(i), xy=(0,10), color='green')
plt.show()
counter += 1
endTime = time.time()
print(f'time taken for {str(counter)} inferences: {str(endTime-startTime)}')
print(f'time per iteration: {str((endTime-startTime)/counter)}')
# %%