Skip to content

Commit f91390e

Browse files
committed
Reversed input to eliminate frame backlash
1 parent 9d3ab09 commit f91390e

32 files changed

Lines changed: 1080 additions & 351 deletions

code/autoencoder_model/scripts/aa10.py

Lines changed: 555 additions & 0 deletions
Large diffs are not rendered by default.

code/autoencoder_model/scripts/attention_autoencoder.py

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,22 @@ def decoder_model():
9999
x = TimeDistributed(LeakyReLU(alpha=0.2))(x)
100100
out_1 = TimeDistributed(Dropout(0.5))(x)
101101

102-
# flat_1 = TimeDistributed(Flatten())(out_1)
103-
# aclstm_1 = GRU(units=16 * 16,
104-
# recurrent_dropout=0.2,
105-
# return_sequences=True)(flat_1)
106-
# x = TimeDistributed(BatchNormalization())(aclstm_1)
107-
# dense_1 = TimeDistributed(Dense(units=16 * 16, activation='softmax'))(x)
108-
# a1_reshape = Reshape(target_shape=(int(VIDEO_LENGTH/2), 16, 16, 1))(dense_1)
109-
# a1 = AttnLossLayer()(a1_reshape)
110-
# dot_1 = multiply([out_1, a1])
102+
flat_1 = TimeDistributed(Flatten())(out_1)
103+
aclstm_1 = GRU(units=16 * 16,
104+
recurrent_dropout=0.2,
105+
return_sequences=True)(flat_1)
106+
x = TimeDistributed(BatchNormalization())(aclstm_1)
107+
dense_1 = TimeDistributed(Dense(units=16 * 16, activation='softmax'))(x)
108+
a1_reshape = Reshape(target_shape=(int(VIDEO_LENGTH/2), 16, 16, 1))(dense_1)
109+
a1 = AttnLossLayer()(a1_reshape)
110+
dot_1 = multiply([out_1, a1])
111111

112112
convlstm_2 = ConvLSTM2D(filters=64,
113113
kernel_size=(3, 3),
114114
strides=(1, 1),
115115
padding='same',
116116
return_sequences=True,
117-
recurrent_dropout=0.2)(out_1)
117+
recurrent_dropout=0.2)(dot_1)
118118
x = TimeDistributed(BatchNormalization())(convlstm_2)
119119
h_2 = TimeDistributed(LeakyReLU(alpha=0.2))(x)
120120
out_2 = UpSampling3D(size=(1, 2, 2))(h_2)
@@ -147,29 +147,13 @@ def decoder_model():
147147
h_4 = TimeDistributed(LeakyReLU(alpha=0.2))(x)
148148
out_4 = UpSampling3D(size=(1, 2, 2))(h_4)
149149

150-
aclstm_1 = ConvLSTM2D(filters=1,
151-
kernel_size=(3, 3),
152-
strides=(1, 1),
153-
padding='same',
154-
return_sequences=True,
155-
recurrent_dropout=0.2)(h_4)
156-
x = TimeDistributed(BatchNormalization())(aclstm_1)
157-
flat_1 = TimeDistributed(Flatten())(x)
158-
dense_1 = TimeDistributed(Dense(units=128 * 128, activation='softmax'))(flat_1)
159-
x = TimeDistributed(BatchNormalization())(dense_1)
160-
x = TimeDistributed(Dropout(0.2))(x)
161-
print (x.shape)
162-
a1_reshape = Reshape(target_shape=(int(VIDEO_LENGTH/2), 128, 128, 1))(x)
163-
a1 = AttnLossLayer()(a1_reshape)
164-
dot_1 = multiply([out_4, a1])
165-
166150
# 10x128x128
167151
convlstm_5 = ConvLSTM2D(filters=3,
168152
kernel_size=(3, 3),
169153
strides=(1, 1),
170154
padding='same',
171155
return_sequences=True,
172-
recurrent_dropout=0.2)(dot_1)
156+
recurrent_dropout=0.2)(out_4)
173157
predictions = TimeDistributed(Activation('tanh'))(convlstm_5)
174158

175159
model = Model(inputs=inputs, outputs=predictions)
@@ -479,8 +463,6 @@ def test(ENC_WEIGHTS, DEC_WEIGHTS):
479463
decoder = decoder_model()
480464
autoencoder = autoencoder_model(encoder, decoder)
481465

482-
if not os.path.exists(TEST_RESULTS_DIR + '/orig/'):
483-
os.mkdir(TEST_RESULTS_DIR + '/orig/')
484466
if not os.path.exists(TEST_RESULTS_DIR + '/truth/'):
485467
os.mkdir(TEST_RESULTS_DIR + '/truth/')
486468
if not os.path.exists(TEST_RESULTS_DIR + '/pred/'):
@@ -501,7 +483,10 @@ def l1_l2_loss(y_true, y_pred):
501483
# n_test_videos = test_videos_list.shape[0]
502484

503485
# NB_TEST_ITERATIONS = int(n_test_videos / BATCH_SIZE)
504-
NB_TEST_ITERATIONS = 30
486+
path, dirs, files = os.walk(TEST_DATA_DIR).next()
487+
file_count = len(files)
488+
NB_TEST_ITERATIONS = int((file_count/int(VIDEO_LENGTH/2))/BATCH_SIZE)
489+
# NB_TEST_ITERATIONS = 30
505490

506491
test_loss = []
507492
print (TEST_DATA_DIR)

code/autoencoder_model/scripts/classifier.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,38 @@ def get_action_classes(action_labels):
487487

488488

489489
simple_ped_action_per_frame = set(simple_ped_action_per_frame)
490-
for action in simple_ped_action_per_frame:
491-
count[action] = count[action] + 1
492-
# Add all unique categorical one-hot vectors
493-
encoded_ped_action = encoded_ped_action + to_categorical(action, len(simple_ped_set))
490+
491+
if 7 in simple_ped_action_per_frame:
492+
action = 7
493+
if 6 in simple_ped_action_per_frame:
494+
action = 6
495+
if 2 in simple_ped_action_per_frame:
496+
action = 2
497+
if 0 in simple_ped_action_per_frame:
498+
action = 0
499+
if 1 in simple_ped_action_per_frame:
500+
action = 1
501+
if 5 in simple_ped_action_per_frame:
502+
action = 5
503+
if 3 in simple_ped_action_per_frame:
504+
action = 3
505+
if 4 in simple_ped_action_per_frame:
506+
action = 4
507+
508+
encoded_ped_action = to_categorical(action, len(simple_ped_set))
509+
count[action] = count[action] + 1
510+
511+
# for action in simple_ped_action_per_frame:
512+
# count[action] = count[action] + 1
513+
# # Add all unique categorical one-hot vectors
514+
# encoded_ped_action = encoded_ped_action + to_categorical(action, len(simple_ped_set))
494515

495516
if (sum(encoded_ped_action) == 0):
496517
print (simple_ped_action_per_frame)
497518
print (a_clean)
519+
if (sum(encoded_ped_action) > 1):
520+
print (simple_ped_action_per_frame)
521+
print (a_clean)
498522
ped_action_class.append(encoded_ped_action.T)
499523
# action_class.append((encoded_driver_action + encoded_ped_action).T)
500524

-1.24 KB
Binary file not shown.
-2.1 KB
Binary file not shown.
-2.65 KB
Binary file not shown.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
from __future__ import absolute_import
2+
from __future__ import division
3+
from __future__ import print_function
4+
5+
from keras.optimizers import SGD
6+
from keras.optimizers import Adam
7+
from keras.optimizers import adadelta
8+
from keras.optimizers import rmsprop
9+
from keras.layers import Layer
10+
from keras import backend as K
11+
K.set_image_dim_ordering('tf')
12+
import socket
13+
import os
14+
15+
# -------------------------------------------------
16+
# Background config:
17+
hostname = socket.gethostname()
18+
if hostname == 'baymax':
19+
path_var = 'baymax/'
20+
elif hostname == 'walle':
21+
path_var = 'walle/'
22+
elif hostname == 'bender':
23+
path_var = 'bender/'
24+
else:
25+
path_var = 'zhora/'
26+
27+
DATA_DIR= '/local_home/JAAD_Dataset/iros/resized_imgs_128/train/'
28+
# DATA_DIR= '/local_home/data/KITTI_data/'
29+
30+
VAL_DATA_DIR= '/local_home/JAAD_Dataset/iros/resized_imgs_128/val/'
31+
32+
# TEST_DATA_DIR= '/local_home/JAAD_Dataset/iros/resized_imgs_128/test/'
33+
TEST_DATA_DIR= '/local_home/JAAD_Dataset/fun_experiments/resized/'
34+
35+
MODEL_DIR = './../' + path_var + 'models'
36+
if not os.path.exists(MODEL_DIR):
37+
os.mkdir(MODEL_DIR)
38+
39+
CHECKPOINT_DIR = './../' + path_var + 'checkpoints'
40+
if not os.path.exists(CHECKPOINT_DIR):
41+
os.mkdir(CHECKPOINT_DIR)
42+
43+
ATTN_WEIGHTS_DIR = './../' + path_var + 'attn_weights'
44+
if not os.path.exists(ATTN_WEIGHTS_DIR):
45+
os.mkdir(ATTN_WEIGHTS_DIR)
46+
47+
GEN_IMAGES_DIR = './../' + path_var + 'generated_images'
48+
if not os.path.exists(GEN_IMAGES_DIR):
49+
os.mkdir(GEN_IMAGES_DIR)
50+
51+
LOG_DIR = './../' + path_var + 'logs'
52+
if not os.path.exists(LOG_DIR):
53+
os.mkdir(LOG_DIR)
54+
55+
TF_LOG_DIR = './../' + path_var + 'tf_logs'
56+
if not os.path.exists(TF_LOG_DIR):
57+
os.mkdir(TF_LOG_DIR)
58+
59+
TEST_RESULTS_DIR = './../' + path_var + 'test_results'
60+
if not os.path.exists(TEST_RESULTS_DIR):
61+
os.mkdir(TEST_RESULTS_DIR)
62+
63+
PRINT_MODEL_SUMMARY = True
64+
SAVE_MODEL = True
65+
PLOT_MODEL = True
66+
SAVE_GENERATED_IMAGES = True
67+
SHUFFLE = True
68+
VIDEO_LENGTH = 20
69+
IMG_SIZE = (128, 128, 3)
70+
ATTN_COEFF = 0
71+
KL_COEFF = 0
72+
RAM_DECIMATE = False
73+
74+
# -------------------------------------------------
75+
# Network configuration:
76+
print ("Loading network/training configuration.")
77+
print ("Config file: " + str(__name__))
78+
79+
BATCH_SIZE = 10
80+
NB_EPOCHS_AUTOENCODER = 40
81+
82+
OPTIM_A = Adam(lr=0.0001, beta_1=0.5)
83+
# OPTIM_A = SGD(lr=0.000001, momentum=0.5, nesterov=True)
84+
# OPTIM_A = rmsprop(lr=0.00001)
85+
86+
lr_schedule = [10, 20, 30] # epoch_step
87+
88+
def schedule(epoch_idx):
89+
if (epoch_idx + 1) < lr_schedule[0]:
90+
return 0.0001
91+
elif (epoch_idx + 1) < lr_schedule[1]:
92+
return 0.0001 # lr_decay_ratio = 10
93+
elif (epoch_idx + 1) < lr_schedule[2]:
94+
return 0.0001
95+
return 0.0001
96+
97+
-1.93 KB
Binary file not shown.
-1.74 KB
Binary file not shown.
-2.16 KB
Binary file not shown.

0 commit comments

Comments
 (0)