(self)
| 83 | |
| 84 | class ValueNetwork: |
| 85 | def __init__(self): |
| 86 | # Placeholders for our input |
| 87 | # After resizing we have 4 consecutive frames of size 84 x 84 |
| 88 | self.states = tf.placeholder(shape=[None, 84, 84, 4], dtype=tf.uint8, name="X") |
| 89 | # The TD target value |
| 90 | self.targets = tf.placeholder(shape=[None], dtype=tf.float32, name="y") |
| 91 | |
| 92 | # Since we set reuse=True here, that means we MUST |
| 93 | # create the PolicyNetwork before creating the ValueNetwork |
| 94 | # PolictyNetwork will use reuse=False |
| 95 | with tf.variable_scope("shared", reuse=True): |
| 96 | fc1 = build_feature_extractor(self.states) |
| 97 | |
| 98 | # Use a separate scope for output and loss |
| 99 | with tf.variable_scope("value_network"): |
| 100 | self.vhat = tf.contrib.layers.fully_connected( |
| 101 | inputs=fc1, |
| 102 | num_outputs=1, |
| 103 | activation_fn=None) |
| 104 | self.vhat = tf.squeeze(self.vhat, squeeze_dims=[1], name="vhat") |
| 105 | |
| 106 | self.loss = tf.squared_difference(self.vhat, self.targets) |
| 107 | self.loss = tf.reduce_sum(self.loss, name="loss") |
| 108 | |
| 109 | # training |
| 110 | self.optimizer = tf.train.RMSPropOptimizer(0.00025, 0.99, 0.0, 1e-6) |
| 111 | |
| 112 | # we'll need these later for running gradient descent steps |
| 113 | self.grads_and_vars = self.optimizer.compute_gradients(self.loss) |
| 114 | self.grads_and_vars = [[grad, var] for grad, var in self.grads_and_vars if grad is not None] |
| 115 | |
| 116 | |
| 117 | # Should use this to create networks |
nothing calls this directly
no test coverage detected