-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelper.py
52 lines (36 loc) · 1.31 KB
/
helper.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
42
43
44
45
46
47
48
49
""" Includes helper functions that are used to pre-process observations, or
to save figures, lists etc. """
import numpy as np
import matplotlib
#matplotlib.use('Agg') #hopw this is gonna work
import matplotlib.pyplot as plt
from skimage.transform import resize
from skimage.color import rgb2gray
import tensorflow as tf
def setup_saver(W, b):
features = W.copy()
features.update(b)
saver = tf.train.Saver(features)
return saver
#Helper functions
def save_figs(rewardList, stepsList, parameter, i):
""" Creates matplotlib figures out of the accumulated lists """
plt.interactive(False)
plt.plot(rewardList)
if parameter['SAVE_FIGS']:
plt.savefig( 'rewards{:d}.png'.format(i) )
else:
plt.ylabel('rewards')
plt.show()
plt.plot(stepsList)
if parameter['SAVE_FIGS']:
plt.savefig( 'steps{:d}.png'.format(i) )
else:
plt.ylabel('steps')
plt.show()
def preprocess_image(observation): #takes about 20% of the running time!!!
""" Grayscale, downscale and crop image for less data wrangling """
#consider transfering this to TF
out = rgb2gray(observation) #takes about 5% of the running time!!! #2s
out = resize(out, (110, 84)) #takes about 9% of running time!!!
return out[13:110 - 13, :]