| 21 | # 2) Resize |
| 22 | # 3) Crop |
| 23 | class ImageTransformer: |
| 24 | def __init__(self): |
| 25 | with tf.variable_scope("image_transformer"): |
| 26 | self.input_state = tf.placeholder(shape=[210, 160, 3], dtype=tf.uint8) |
| 27 | self.output = tf.image.rgb_to_grayscale(self.input_state) |
| 28 | self.output = tf.image.crop_to_bounding_box(self.output, 34, 0, 160, 160) |
| 29 | self.output = tf.image.resize_images( |
| 30 | self.output, |
| 31 | [84, 84], |
| 32 | method=tf.image.ResizeMethod.NEAREST_NEIGHBOR) |
| 33 | self.output = tf.squeeze(self.output) |
| 34 | |
| 35 | def transform(self, state, sess=None): |
| 36 | sess = sess or tf.get_default_session() |
| 37 | return sess.run(self.output, { self.input_state: state }) |
| 38 | |
| 39 | |
| 40 | # Create initial state by repeating the same frame 4 times |