Skip to content

Commit 326b38a

Browse files
committed
Sigmoidal classifier. New annotations
1 parent 640680b commit 326b38a

16 files changed

Lines changed: 1404 additions & 115 deletions

code/autoencoder_model/scripts/config_oc.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
if not os.path.exists(CLA_GEN_IMAGES_DIR):
4949
os.mkdir(CLA_GEN_IMAGES_DIR)
5050

51-
ATTN_WEIGHTS_DIR = './../' + path_var + 'attn_weights'
52-
if not os.path.exists(ATTN_WEIGHTS_DIR):
53-
os.mkdir(ATTN_WEIGHTS_DIR)
51+
# ATTN_WEIGHTS_DIR = './../' + path_var + 'attn_weights'
52+
# if not os.path.exists(ATTN_WEIGHTS_DIR):
53+
# os.mkdir(ATTN_WEIGHTS_DIR)
5454

5555
LOG_DIR = './../' + path_var + 'logs'
5656
if not os.path.exists(LOG_DIR):
@@ -82,9 +82,14 @@
8282
A_TRAIN_RATIO = 1
8383
C_TRAIN_RATIO = 1
8484
RAM_DECIMATE = True
85-
RETRAIN_CLASSIFIER = False
85+
RETRAIN_CLASSIFIER = True
8686
CLASS_TARGET_INDEX = 8
87-
87+
ROT_MAX = 10
88+
SFT_H_MAX = 0.05
89+
SFT_V_MAX = 0.05
90+
ZOOM_MAX = 0.2
91+
BRIGHT_RANGE_L = 0.5
92+
BRIGHT_RANGE_H = 1.5
8893

8994
# ped_actions = ['standing 0', 'moving slow 1', 'moving fast 2', 'look 3', 'looking 4',
9095
# 'slow down 5', 'speed up 6', 'crossing 7', 'stopped 8', 'clear path 9',
@@ -125,11 +130,11 @@
125130
print ("Config file: " + str(__name__))
126131

127132
BATCH_SIZE = 25
128-
NB_EPOCHS_CLASS = 15
133+
NB_EPOCHS_CLASS = 100
129134

130-
# OPTIM_C = Adam(lr=0.0000002, beta_1=0.5)
135+
OPTIM_C = Adam(lr=0.0000002, beta_1=0.5)
131136
# OPTIM_C = SGD(lr=0.0001, momentum=0.9, nesterov=True)
132-
OPTIM_C = RMSprop(lr=0.0001, rho=0.9)
137+
# OPTIM_C = RMSprop(lr=0.0001, rho=0.9)
133138

134139
# lr_schedule = [10, 20, 30] # epoch_step
135140

@@ -143,12 +148,12 @@
143148
# return 0.000000001
144149

145150

146-
lr_schedule = [4, 7, 10] # epoch_step
151+
lr_schedule = [15, 25, 40] # epoch_step
147152
def schedule(epoch_idx):
148153
if (epoch_idx + 1) < lr_schedule[0]:
149-
return 0.0001
154+
return 0.00001
150155
elif (epoch_idx + 1) < lr_schedule[1]:
151-
return 0.00001 # lr_decay_ratio = 10
156+
return 0.000001 # lr_decay_ratio = 10
152157
elif (epoch_idx + 1) < lr_schedule[2]:
153-
return 0.000001
154-
return 0.000001
158+
return 0.0000001
159+
return 0.0000001
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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 RMSprop
8+
from keras import backend as K
9+
K.set_image_dim_ordering('tf')
10+
import socket
11+
import os
12+
13+
# -------------------------------------------------
14+
# Background config:
15+
hostname = socket.gethostname()
16+
if hostname == 'baymax':
17+
path_var = 'baymax/'
18+
elif hostname == 'walle':
19+
path_var = 'walle/'
20+
elif hostname == 'bender':
21+
path_var = 'bender/'
22+
else:
23+
path_var = 'zhora/'
24+
25+
DATA_DIR= '/local_home/JAAD_Dataset/iros/resized_imgs_208_sorted/train/'
26+
# DATA_DIR= '/local_home/data/KITTI_data/'
27+
28+
TEST_DATA_DIR= '/local_home/JAAD_Dataset/iros/resized_imgs_208_sorted/test/'
29+
30+
VAL_DATA_DIR= '/local_home/JAAD_Dataset/iros/resized_imgs_208_sorted/val/'
31+
32+
PRETRAINED_C3D= '/home/pratik/git_projects/c3d-keras/models/sports1M_weights_tf.json'
33+
PRETRAINED_C3D_WEIGHTS= '/home/pratik/git_projects/c3d-keras/models/sports1M_weights_tf.h5'
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+
GEN_IMAGES_DIR = './../' + path_var + 'generated_images'
44+
if not os.path.exists(GEN_IMAGES_DIR):
45+
os.mkdir(GEN_IMAGES_DIR)
46+
47+
CLA_GEN_IMAGES_DIR = GEN_IMAGES_DIR + '/cla_gen/'
48+
if not os.path.exists(CLA_GEN_IMAGES_DIR):
49+
os.mkdir(CLA_GEN_IMAGES_DIR)
50+
51+
# ATTN_WEIGHTS_DIR = './../' + path_var + 'attn_weights'
52+
# if not os.path.exists(ATTN_WEIGHTS_DIR):
53+
# os.mkdir(ATTN_WEIGHTS_DIR)
54+
55+
LOG_DIR = './../' + path_var + 'logs'
56+
if not os.path.exists(LOG_DIR):
57+
os.mkdir(LOG_DIR)
58+
59+
TF_LOG_DIR = './../' + path_var + 'tf_logs'
60+
if not os.path.exists(TF_LOG_DIR):
61+
os.mkdir(TF_LOG_DIR)
62+
63+
TF_LOG_CLA_DIR = './../' + path_var + 'tf_cla_logs'
64+
if not os.path.exists(TF_LOG_CLA_DIR):
65+
os.mkdir(TF_LOG_CLA_DIR)
66+
67+
TEST_RESULTS_DIR = './../' + path_var + 'test_results'
68+
if not os.path.exists(TEST_RESULTS_DIR):
69+
os.mkdir(TEST_RESULTS_DIR)
70+
71+
PRINT_MODEL_SUMMARY = True
72+
SAVE_MODEL = True
73+
PLOT_MODEL = False
74+
SAVE_GENERATED_IMAGES = True
75+
SHUFFLE = True
76+
VIDEO_LENGTH = 16
77+
IMG_SIZE = (128, 208, 3)
78+
VIS_ATTN = True
79+
CLASSIFIER = True
80+
BUF_SIZE = 10
81+
LOSS_WEIGHTS = [1, 1]
82+
A_TRAIN_RATIO = 1
83+
C_TRAIN_RATIO = 1
84+
RAM_DECIMATE = True
85+
RETRAIN_CLASSIFIER = True
86+
CLASS_TARGET_INDEX = 8
87+
ROT_MAX = 10
88+
SFT_H_MAX = 0.05
89+
SFT_V_MAX = 0.05
90+
ZOOM_MAX = 0.2
91+
BRIGHT_RANGE_L = 0.5
92+
BRIGHT_RANGE_H = 1.5
93+
94+
ped_actions = ['slow down', 'standing', 'walking', 'speed up', 'nod', 'unknown',
95+
'clear path', 'handwave', 'crossing', 'looking', 'no ped']
96+
97+
simple_ped_set = ['standing' ,'crossing', 'no ped']
98+
99+
100+
101+
102+
103+
driver_actions = ['moving slow', 'slowing down', 'standing', 'speeding up', 'moving fast']
104+
simple_driver_set = ['slow down', 'stop', 'speed up']
105+
106+
joint_action_set = ['moving slow', 'slowing down', 'standing', 'speeding up', 'moving fast',
107+
'slow down', 'standing', 'moving fast', 'speed up', 'look', 'nod', 'unknown',
108+
'moving slow', 'flasher signal', 'looking' , 'handwave', 'clear path',
109+
'stopped', 'slowing down', 'crossing', 'speeding up']
110+
111+
formatted_joint_action_set = ['car moving slow', 'car slowing down', 'car standing', 'car speeding up', 'car moving fast',
112+
'ped slow down', 'ped standing', 'ped moving fast', 'ped speed up', 'ped look',
113+
'ped nod', 'ped unknown', 'ped moving slow', 'ped flasher signal', 'ped looking' ,
114+
'ped handwave', 'ped clear path', 'ped stopped', 'ped slowing down', 'ped crossing',
115+
'ped speeding up']
116+
117+
118+
# -------------------------------------------------
119+
# Network configuration:
120+
print ("Loading network/training configuration...")
121+
print ("Config file: " + str(__name__))
122+
123+
BATCH_SIZE = 25
124+
NB_EPOCHS_CLASS = 100
125+
126+
OPTIM_C = Adam(lr=0.0000002, beta_1=0.5)
127+
# OPTIM_C = SGD(lr=0.0001, momentum=0.9, nesterov=True)
128+
# OPTIM_C = RMSprop(lr=0.0001, rho=0.9)
129+
130+
# lr_schedule = [10, 20, 30] # epoch_step
131+
132+
# def schedule(epoch_idx):
133+
# if (epoch_idx + 1) < lr_schedule[0]:
134+
# return 0.00000001
135+
# elif (epoch_idx + 1) < lr_schedule[1]:
136+
# return 0.000000001 # lr_decay_ratio = 10
137+
# elif (epoch_idx + 1) < lr_schedule[2]:
138+
# return 0.000000001
139+
# return 0.000000001
140+
141+
142+
lr_schedule = [7, 15, 22] # epoch_step
143+
144+
145+
def schedule(epoch_idx):
146+
if (epoch_idx + 1) < lr_schedule[0]:
147+
return 0.00001
148+
elif (epoch_idx + 1) < lr_schedule[1]:
149+
return 0.000001 # lr_decay_ratio = 10
150+
elif (epoch_idx + 1) < lr_schedule[2]:
151+
return 0.0000001
152+
return 0.0000001

code/autoencoder_model/scripts/image_utils.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
_PIL_INTERPOLATION_METHODS['lanczos'] = pil_image.LANCZOS
3939

4040

41-
def random_rotation(x, rg, row_axis=1, col_axis=2, channel_axis=0,
41+
def random_rotation(x, theta_deg, row_axis=1, col_axis=2, channel_axis=0,
4242
fill_mode='nearest', cval=0.):
4343
"""Performs a random rotation of a Numpy image tensor.
4444
# Arguments
@@ -55,7 +55,7 @@ def random_rotation(x, rg, row_axis=1, col_axis=2, channel_axis=0,
5555
# Returns
5656
Rotated Numpy image tensor.
5757
"""
58-
theta = np.deg2rad(np.random.uniform(-rg, rg))
58+
theta = np.deg2rad(theta_deg)
5959
rotation_matrix = np.array([[np.cos(theta), -np.sin(theta), 0],
6060
[np.sin(theta), np.cos(theta), 0],
6161
[0, 0, 1]])
@@ -108,7 +108,7 @@ def apply_transform(x,
108108
return x
109109

110110

111-
def random_shift(x, wrg, hrg, row_axis=1, col_axis=2, channel_axis=0,
111+
def random_shift(x, tx, ty, row_axis=1, col_axis=2, channel_axis=0,
112112
fill_mode='nearest', cval=0.):
113113
"""Performs a random spatial shift of a Numpy image tensor.
114114
# Arguments
@@ -126,9 +126,9 @@ def random_shift(x, wrg, hrg, row_axis=1, col_axis=2, channel_axis=0,
126126
# Returns
127127
Shifted Numpy image tensor.
128128
"""
129-
h, w = x.shape[row_axis], x.shape[col_axis]
130-
tx = np.random.uniform(-hrg, hrg) * h
131-
ty = np.random.uniform(-wrg, wrg) * w
129+
# h, w = x.shape[row_axis], x.shape[col_axis]
130+
# tx = np.random.uniform(-hrg, hrg) * h
131+
# ty = np.random.uniform(-wrg, wrg) * w
132132
translation_matrix = np.array([[1, 0, tx],
133133
[0, 1, ty],
134134
[0, 0, 1]])
@@ -138,7 +138,7 @@ def random_shift(x, wrg, hrg, row_axis=1, col_axis=2, channel_axis=0,
138138
return x
139139

140140

141-
def random_zoom(x, zoom_range, row_axis=1, col_axis=2, channel_axis=0,
141+
def random_zoom(x, zx, zy, row_axis=1, col_axis=2, channel_axis=0,
142142
fill_mode='nearest', cval=0.):
143143
"""Performs a random spatial zoom of a Numpy image tensor.
144144
# Arguments
@@ -157,14 +157,16 @@ def random_zoom(x, zoom_range, row_axis=1, col_axis=2, channel_axis=0,
157157
# Raises
158158
ValueError: if `zoom_range` isn't a tuple.
159159
"""
160-
if len(zoom_range) != 2:
161-
raise ValueError('`zoom_range` should be a tuple or list of two floats. '
162-
'Received arg: ', zoom_range)
163-
164-
if zoom_range[0] == 1 and zoom_range[1] == 1:
165-
zx, zy = 1, 1
166-
else:
167-
zx, zy = np.random.uniform(zoom_range[0], zoom_range[1], 2)
160+
# if len(zoom_range) != 2:
161+
# raise ValueError('`zoom_range` should be a tuple or list of two floats. '
162+
# 'Received arg: ', zoom_range)
163+
#
164+
# if zoom_range[0] == 1 and zoom_range[1] == 1:
165+
# zx, zy = 1, 1
166+
# else:
167+
# zx, zy = np.random.uniform(zoom_range[0], zoom_range[1], 2)
168+
print (x.shape)
169+
print (zx)
168170
zoom_matrix = np.array([[zx, 0, 0],
169171
[0, zy, 0],
170172
[0, 0, 1]])
@@ -261,14 +263,14 @@ def img_to_array(img, data_format=None):
261263

262264

263265

264-
def random_brightness(x, brightness_range):
265-
if len(brightness_range) != 2:
266-
raise ValueError('`brightness_range should be tuple or list of two floats. '
267-
'Received arg: ', brightness_range)
268-
266+
def random_brightness(x, u):
267+
# if len(brightness_range) != 2:
268+
# raise ValueError('`brightness_range should be tuple or list of two floats. '
269+
# 'Received arg: ', brightness_range)
270+
#
269271
x = array_to_img(x)
270-
x = imgenhancer_Brightness = ImageEnhance.Brightness(x)
271-
u = np.random.uniform(brightness_range[0], brightness_range[1])
272+
imgenhancer_Brightness = ImageEnhance.Brightness(x)
273+
# u = np.random.uniform(brightness_range[0], brightness_range[1])
272274
x = imgenhancer_Brightness.enhance(u)
273275
x = img_to_array(x)
274276
return x

0 commit comments

Comments
 (0)