Skip to content

Commit f278a9e

Browse files
committed
Time to get graphs!
1 parent 4e8b777 commit f278a9e

13 files changed

Lines changed: 787 additions & 206 deletions
Binary file not shown.
0 Bytes
Binary file not shown.

code/autoencoder_model/scripts/thesis_scripts/config_rendec16.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
TEST_DATA_DIR= '/local_home/JAAD_Dataset/iros/resized_imgs_208_thesis/test/'
3232
# TEST_DATA_DIR= '/local_home/JAAD_Dataset/fun_experiments/resized/'
3333

34-
RESULTS_DIR = '/local_home/JAAD_Dataset/thesis/results/rendec/'
34+
RESULTS_DIR = '/local_home/JAAD_Dataset/thesis/results/rev/'
3535

3636
# MODEL_DIR = './../' + path_var + 'models'
3737
MODEL_DIR = RESULTS_DIR + 'models/'
@@ -66,7 +66,7 @@
6666
SHUFFLE = True
6767
VIDEO_LENGTH = 32
6868
IMG_SIZE = (128, 208, 3)
69-
RAM_DECIMATE = False
69+
RAM_DECIMATE = True
7070
REVERSE = True
7171

7272

@@ -75,8 +75,9 @@
7575
print ("Loading network/training configuration.")
7676
print ("Config file: " + str(__name__))
7777

78-
BATCH_SIZE = 9
79-
TEST_BATCH_SIZE = 9
78+
BATCH_SIZE = 8
79+
80+
TEST_BATCH_SIZE = 1
8081
NB_EPOCHS_AUTOENCODER = 30
8182

8283
# OPTIM_A = Adam(lr=0.0001, beta_1=0.5)
-8 Bytes
Binary file not shown.

code/autoencoder_model/scripts/thesis_scripts/config_walle_r16.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
TEST_DATA_DIR= '/local_home/JAAD_Dataset/iros/resized_imgs_208_thesis/test/'
3232
# TEST_DATA_DIR= '/local_home/JAAD_Dataset/fun_experiments/resized/'
3333

34-
RESULTS_DIR = '/local_home/JAAD_Dataset/thesis/results/rescheck/'
34+
RESULTS_DIR = '/local_home/JAAD_Dataset/thesis/results/kernel/'
3535

3636
# MODEL_DIR = './../' + path_var + 'models'
3737
MODEL_DIR = RESULTS_DIR + 'models/'
Binary file not shown.

code/autoencoder_model/scripts/thesis_scripts/dilation.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
import hickle as hkl
66
import numpy as np
7-
from tensorflow.python.pywrap_tensorflow import do_quantize_training_on_graphdef
87

8+
#import tensorflow as tf
9+
#tf.reset_default_graph()
910
np.random.seed(9 ** 10)
1011
from keras import backend as K
1112
K.set_image_dim_ordering('tf')
@@ -223,13 +224,17 @@ def set_trainability(model, trainable):
223224

224225

225226
def autoencoder_model(encoder, decoder):
226-
inputs = Input(shape=(int(VIDEO_LENGTH / 2), 128, 208, 3))
227-
z = encoder(inputs)
227+
# inputs = Input(shape=(int(VIDEO_LENGTH / 2), 128, 208, 3))
228+
# z = encoder(inputs)
228229
# print (z.shape)
229230
# print (type(z))
230-
future = decoder(z)
231+
# future = decoder(z)
231232

232-
model = Model(inputs=inputs, outputs=future)
233+
# model = Model(inputs=inputs, outputs=future)
234+
235+
model = Sequential()
236+
model.add(encoder)
237+
model.add(decoder)
233238

234239
return model
235240

@@ -401,11 +406,11 @@ def train(BATCH_SIZE, ENC_WEIGHTS, DEC_WEIGHTS):
401406

402407
print("Beginning Training...")
403408
# Begin Training
404-
for epoch in range(1, NB_EPOCHS_AUTOENCODER+1):
405-
if epoch == 21:
409+
for epoch in range(28, NB_EPOCHS_AUTOENCODER+1):
410+
if epoch == 28:
406411
autoencoder.compile(loss="mean_absolute_error", optimizer=OPTIM_B)
407-
load_weights(os.path.join(CHECKPOINT_DIR, 'encoder_epoch_20.h5'), encoder)
408-
load_weights(os.path.join(CHECKPOINT_DIR, 'decoder_epoch_20.h5'), decoder)
412+
load_weights(os.path.join(CHECKPOINT_DIR, 'encoder_epoch_27.h5'), encoder)
413+
load_weights(os.path.join(CHECKPOINT_DIR, 'decoder_epoch_27.h5'), decoder)
409414

410415
print("\n\nEpoch ", epoch)
411416
loss = []
@@ -515,6 +520,7 @@ def test(ENC_WEIGHTS, DEC_WEIGHTS):
515520
mae_errors = np.zeros(shape=(n_test_videos, int(VIDEO_LENGTH/2) + 1))
516521
mse_errors = np.zeros(shape=(n_test_videos, int(VIDEO_LENGTH/2) + 1))
517522

523+
# z_all = []
518524
for index in range(NB_TEST_ITERATIONS):
519525
X = load_X(test_videos_list, index, TEST_DATA_DIR, IMG_SIZE, batch_size=TEST_BATCH_SIZE)
520526
X_test = np.flip(X[:, 0: int(VIDEO_LENGTH / 2)], axis=1)
@@ -527,9 +533,16 @@ def test(ENC_WEIGHTS, DEC_WEIGHTS):
527533
"\t [" + "{0}>".format("=" * (arrow)))
528534
stdout.flush()
529535

536+
530537
if SAVE_GENERATED_IMAGES:
531538
# Save generated images to file
532-
predicted_images = autoencoder.predict(X_test, verbose=0)
539+
z = encoder.predict(X_test, verbose=0)
540+
# z_all.append(z)
541+
542+
# z_new = np.zeros(shape=(TEST_BATCH_SIZE, 1, 16, 26, 64))
543+
# z_new[0] = z[:, 15]
544+
# z_new = np.repeat(z_new, int(VIDEO_LENGTH/2), axis=1)
545+
predicted_images = decoder.predict(z, verbose=0)
533546
voila = np.concatenate((X_test, y_test), axis=1)
534547
truth_seq = arrange_images(voila)
535548
pred_seq = arrange_images(np.concatenate((X_test, predicted_images), axis=1))
@@ -558,7 +571,7 @@ def test(ENC_WEIGHTS, DEC_WEIGHTS):
558571

559572
np.save(os.path.join(TEST_RESULTS_DIR + '/graphs/values/', str(index) + "_mae.npy"), np.asarray(mae_errors))
560573
np.save(os.path.join(TEST_RESULTS_DIR + '/graphs/values/', str(index) + "_mse.npy"), np.asarray(mse_errors))
561-
574+
# np.save(os.path.join(TEST_RESULTS_DIR + '/graphs/values/', "z_all.npy"), np.asarray(z_all))
562575

563576
# then after each epoch/iteration
564577
avg_test_loss = sum(test_loss) / len(test_loss)

code/autoencoder_model/scripts/thesis_scripts/kernel_16.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
from keras.layers.normalization import BatchNormalization
2424
from keras.callbacks import LearningRateScheduler
2525
from keras.layers.advanced_activations import LeakyReLU
26-
# from sklearn.metrics import mean_absolute_error as mae
27-
# from sklearn.metrics import mean_squared_error as mse
28-
# from plot_results import plot_err_variation
26+
from sklearn.metrics import mean_absolute_error as mae
27+
from sklearn.metrics import mean_squared_error as mse
28+
from plot_results import plot_err_variation
2929
from keras.layers import Input
3030
from keras.models import Model
3131
from config_walle_r16 import *
@@ -413,15 +413,16 @@ def test(ENC_WEIGHTS, DEC_WEIGHTS):
413413
encoder = encoder_model()
414414
decoder = decoder_model()
415415
autoencoder = autoencoder_model(encoder, decoder)
416-
autoencoder.compile(loss="mean_squared_error", optimizer=OPTIM_A)
416+
autoencoder.compile(loss="mean_absolute_error", optimizer=OPTIM_A)
417417

418418
run_utilities(encoder, decoder, autoencoder, ENC_WEIGHTS, DEC_WEIGHTS)
419419

420420
NB_TEST_ITERATIONS = int(n_test_videos / TEST_BATCH_SIZE)
421421
test_loss = []
422-
mae_errors = np.zeros(shape=(n_test_videos, int(VIDEO_LENGTH/2)))
423-
mse_errors = np.zeros(shape=(n_test_videos, int(VIDEO_LENGTH/2)))
422+
mae_errors = np.zeros(shape=(n_test_videos, int(VIDEO_LENGTH/2) + 1))
423+
mse_errors = np.zeros(shape=(n_test_videos, int(VIDEO_LENGTH/2) + 1))
424424

425+
z_all = []
425426
for index in range(NB_TEST_ITERATIONS):
426427
X = load_X(test_videos_list, index, TEST_DATA_DIR, IMG_SIZE, batch_size=TEST_BATCH_SIZE)
427428
X_test = np.flip(X[:, 0: int(VIDEO_LENGTH / 2)], axis=1)
@@ -434,9 +435,16 @@ def test(ENC_WEIGHTS, DEC_WEIGHTS):
434435
"\t [" + "{0}>".format("=" * (arrow)))
435436
stdout.flush()
436437

438+
437439
if SAVE_GENERATED_IMAGES:
438440
# Save generated images to file
439-
predicted_images = autoencoder.predict(X_test, verbose=0)
441+
z = encoder.predict(X_test, verbose=0)
442+
z_all.append(z)
443+
444+
# z_new = np.zeros(shape=(TEST_BATCH_SIZE, 1, 16, 26, 64))
445+
# z_new[0] = z[:, 15]
446+
# z_new = np.repeat(z_new, int(VIDEO_LENGTH/2), axis=1)
447+
predicted_images = decoder.predict(z, verbose=0)
440448
voila = np.concatenate((X_test, y_test), axis=1)
441449
truth_seq = arrange_images(voila)
442450
pred_seq = arrange_images(np.concatenate((X_test, predicted_images), axis=1))
@@ -450,17 +458,22 @@ def test(ENC_WEIGHTS, DEC_WEIGHTS):
450458
mae_errors[index, i] = (mae(y_test[0, i].flatten(), predicted_images[0, i].flatten()))
451459
mae_error.append(mae_errors[index, i])
452460

461+
453462
mse_errors[index, i] = (mse(y_test[0, i].flatten(), predicted_images[0, i].flatten()))
454463
mse_error.append(mse_errors[index, i])
455464

465+
dc_mae = mae(X_test[0, 0].flatten(), predicted_images[0, 0].flatten())
466+
mae_errors[index, -1] = dc_mae
467+
dc_mse = mse(X_test[0, 0].flatten(), predicted_images[0, 0].flatten())
468+
mse_errors[index, -1] = dc_mse
456469
cv2.imwrite(os.path.join(TEST_RESULTS_DIR + '/truth/', str(index) + "_truth.png"), truth_seq)
457470
cv2.imwrite(os.path.join(TEST_RESULTS_DIR + '/pred/', str(index) + "_pred.png"), pred_seq)
458-
plot_err_variation(mae_error, index)
459-
plot_err_variation(mse_error, index)
471+
plot_err_variation(mae_error, index, dc_mae, 'mae')
472+
plot_err_variation(mse_error, index, dc_mse, 'mse')
460473

461474
np.save(os.path.join(TEST_RESULTS_DIR + '/graphs/values/', str(index) + "_mae.npy"), np.asarray(mae_errors))
462475
np.save(os.path.join(TEST_RESULTS_DIR + '/graphs/values/', str(index) + "_mse.npy"), np.asarray(mse_errors))
463-
476+
np.save(os.path.join(TEST_RESULTS_DIR + '/graphs/values/', "z_all.npy"), np.asarray(z_all))
464477

465478
# then after each epoch/iteration
466479
avg_test_loss = sum(test_loss) / len(test_loss)
@@ -473,6 +486,7 @@ def test(ENC_WEIGHTS, DEC_WEIGHTS):
473486
print("\n Min: " + str(np.min(np.asarray(test_loss))))
474487

475488

489+
476490
def get_args():
477491
parser = argparse.ArgumentParser()
478492
parser.add_argument("--mode", type=str)

code/autoencoder_model/scripts/thesis_scripts/plot_results.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,56 @@ def get_args():
8484
# dilation_mean = np.mean(dilation, axis=0)
8585
# kernel_mean = np.mean(dilation, axis=0)
8686
# rev_mean = np.mean(rev, axis=0)
87+
88+
# import math
89+
# import numpy as np
90+
# import matplotlib.pyplot as plt
91+
# import matplotlib.patches as mpatches
92+
#
93+
# # def myreadlines(f, newline):
94+
# # buf = ""
95+
# # while True:
96+
# # while newline in buf:
97+
# # pos = buf.index(newline)
98+
# # yield buf[:pos]
99+
# # buf = buf[pos + len(newline):]
100+
# # chunk = f.read(4096)
101+
# # if not chunk:
102+
# # yield buf
103+
# # break
104+
# # buf += chunk
105+
#
106+
# # plt.rcParams['font.family'] = 'serif'
107+
# plt.rc('font', **{'family': 'serif', 'serif': ['Computer Modern']})
108+
# plt.rc('text', usetex=True)
109+
#
110+
# # plt.rcParams['font.serif'] = 'Ubuntu'
111+
# # plt.rcParams['font.monospace'] = 'Ubuntu Mono'
112+
# plt.rcParams['font.size'] = 10
113+
# plt.rcParams['axes.labelsize'] = 10
114+
# plt.rcParams['axes.labelweight'] = 'bold'
115+
# plt.rcParams['xtick.labelsize'] = 8
116+
# plt.rcParams['ytick.labelsize'] = 8
117+
# plt.rcParams['legend.fontsize'] = 10
118+
# plt.rcParams['figure.titlesize'] = 12
119+
# plt.style.use('seaborn-white')
120+
#
121+
# # if (prefixStr == "Results/200Robots500Boxes/star_switch/star_switch"):
122+
# # lines = plt.plot(stepNumbers, avgAvgDists)
123+
# # plt.setp(lines, color='#3E6386', linewidth=1)
124+
# # plt.fill_between(stepNumbers, [a-b for a,b in zip(avgAvgDists, stdDevs)], [a+b for a,b in zip(avgAvgDists, stdDevs)], facecolor="#9DB3C8", alpha=0.7)
125+
# # else:
126+
# # lines = plt.plot(stepNumbers, avgAvgDists)
127+
# # plt.setp(lines, color='#430029', linewidth=1)
128+
# # plt.fill_between(stepNumbers, [a-b for a,b in zip(avgAvgDists, stdDevs)], [a+b for a,b in zip(avgAvgDists, stdDevs)], facecolor="#C986AF", alpha=0.7)
129+
# # ax = plt.gca()
130+
# # ax.set_yticks(np.arange(0, math.ceil(max(avgAvgDists)), 0.50))
131+
# # plt.xlabel('World Steps')
132+
# # plt.ylabel('Mean Box Distance from Goal Shape (m)')
133+
# # plt.title("Avg Distance from Boxes to \nStar Shaped Goal with and without Switching\n200 Robots 500 Boxes")
134+
# # #plt.fill_between(stepNumbers, [a-b for a,b in zip(avgAvgDistsOut, stdDevsOut)], [a+b for a,b in zip(avgAvgDistsOut, stdDevsOut)], facecolor="#9DB3C8")
135+
# # red_patch = mpatches.Patch(color='#3E6386', label='With Switching')
136+
# # blue_patch = mpatches.Patch(color='#430029', label='Without Switching')
137+
# # plt.legend(handles=[blue_patch, red_patch])
138+
# # ax.set_facecolor([0.975, 0.975, 0.975])
139+
# # plt.savefig('/home/abignell/Pictures/push_pics/starstyle.pdf', bbox_inches='tight')
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)