-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
41 lines (36 loc) · 1.69 KB
/
model.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
from keras.models import Sequential
from keras.layers import Dense,Dropout,Activation,Flatten,MaxPooling2D,TimeDistributed
from keras.layers import LSTM
from sklearn.model_selection import train_test_split
from keras.utils import to_categorical
from keras.layers import ConvLSTM2D
import numpy as np
from random import shuffle
from keras.callbacks import ModelCheckpoint
from keras import optimizers
seq = Sequential()
def loadWeights():
seq.add(ConvLSTM2D(filters=5, kernel_size=(3, 3), input_shape=(29, 256, 256, 3), padding='same', return_sequences=True))
seq.add(TimeDistributed(MaxPooling2D((2,2),(2,2))))
seq.add(TimeDistributed(MaxPooling2D((2,2),(2,2))))
seq.add(ConvLSTM2D(filters=5, kernel_size=(3, 3), input_shape=(29, 256, 256, 3), padding='same', return_sequences=True))
seq.add(TimeDistributed(MaxPooling2D((2,2),(2,2))))
seq.add(ConvLSTM2D(filters=5, kernel_size=(3, 3), input_shape=(29, 256, 256, 3), padding='same', return_sequences=True))
seq.add(TimeDistributed(MaxPooling2D((2,2),(2,2))))
seq.add(Flatten())
seq.add(Dense(1024))
seq.add(Dense(3))
seq.add(Activation('softmax'))
seq.compile(loss='categorical_crossentropy', optimizer='ADAM', metrics=['accuracy'])
seq.load_weights('weights-improvement-15-0.88.hdf5')
print('i am done')
def prediction(filename):
data = np.load(filename + '.npy', allow_pickle=True)
data_frames = list()
for x in range(29):
data_zeros = np.zeros((256, 256, 3), dtype=np.int)
for y, z in zip(data[x][0], data[x][1]):
data_zeros[z - 1][y - 1] = 255
data_frames.append(data_zeros)
x = np.array([data_frames])
return seq.predict(x)