-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathActionRecognition.py
More file actions
107 lines (56 loc) · 1.69 KB
/
Copy pathActionRecognition.py
File metadata and controls
107 lines (56 loc) · 1.69 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
# coding: utf-8
# ### Imports
# In[ ]:
import numpy as np
import tensorflow as tf
from data_gen import DataGenerator
from model import MyCL_Model
# ### Paths
# In[ ]:
videos_path = './Videos_MERL_Shopping_Dataset/'
# In[ ]:
x_train_path = videos_path+'train/'
y_train_path = 'train_y.pkl'
# In[ ]:
x_val_path = videos_path + '/val/'
y_val_path = 'val_y.pkl'
# ### Create Train and Validation Data Generator objects
# In[ ]:
train_data = DataGenerator(x_train_path ,y_path = y_train_path)
val_data = DataGenerator(x_val_path ,y_path = y_val_path)
# ### Define and Compile Model
# In[ ]:
model = MyCL_Model()
model.compile(loss='sparse_categorical_crossentropy', optimizer=tf.keras.optimizers.Adam(), metrics=['accuracy'])
# ### Train and Evaluate Model
# In[ ]:
epochs = 20
for i in range(epochs):
for j in range(len(train_data)):
model.fit_generator(generator = train_data[j])
val_loss = 0.0
val_acc = 0.0
for k in range(len(val_data)):
l, a = model.evaluate_generator(generator = val_data[k])
val_loss += l
val_acc += a
val_loss /= k
val_acc /=k
model.save('mycl.h5')
print("Epoch: ", i, ", Validation Loss: ", val_loss, ", Validation Per-Frame Accuracy: ", val_acc)
# ### Testing Data Paths
# In[ ]:
x_test_path = videos_path + 'test/'
y_test_path = 'test_y.pkl'
# ### Create Test Data Generator Object
# In[ ]:
test_data = DataGenerator(x_test_path ,y_path = y_test_path)
# ### Test the model
# In[ ]:
test_acc = 0.0
for i in range(len(test_data)):
_, a = model.evaluate_generator(testing_generator)
test_acc += a
test_acc/=i
print("Per Frame Accuracy for Test Data = ", test_acc)