-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
47 lines (32 loc) · 1.18 KB
/
utils.py
File metadata and controls
47 lines (32 loc) · 1.18 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
# coding: utf-8
import cv2
import scipy
import numpy as np
import tensorflow as tf
import scipy.signal as signal
from vizdoom import *
def update_target_graph(from_scope, to_scope):
from_vars = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, from_scope)
to_vars = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, to_scope)
op_holder = []
for from_var, to_var in zip(from_vars, to_vars):
op_holder.append(to_var.assign(from_var))
return op_holder
# Discounting function used to calculate discounted returns.
def discount(x, gamma):
return scipy.signal.lfilter([1], [1, -gamma], x[::-1], axis=0)[::-1]
def process_frame(frame, shape=(80, 80)):
img = cv2.resize(frame, shape, interpolation=cv2.INTER_LINEAR)
img = rgb2gray(img, shape)
return img
def rgb2gray(rgb, img_dim):
gray = np.dot(rgb[..., :3], [0.299, 0.587, 0.114])
return gray.reshape(img_dim)
def reduce_multiply(m_list):
if not isinstance(m_list, list):
raise TypeError('TypeError, the type of m_list must be list')
result = 1
for i in m_list:
result *= i
return result
xavier_initializer_conv2d = tf.contrib.layers.xavier_initializer_conv2d