| 43 | # 2) Resize |
| 44 | # 3) Crop |
| 45 | class ImageTransformer: |
| 46 | def __init__(self): |
| 47 | with tf.variable_scope("image_transformer"): |
| 48 | self.input_state = tf.placeholder(shape=[210, 160, 3], dtype=tf.uint8) |
| 49 | self.output = tf.image.rgb_to_grayscale(self.input_state) |
| 50 | self.output = tf.image.crop_to_bounding_box(self.output, 34, 0, 160, 160) |
| 51 | self.output = tf.image.resize_images( |
| 52 | self.output, |
| 53 | [IM_SIZE, IM_SIZE], |
| 54 | method=tf.image.ResizeMethod.NEAREST_NEIGHBOR) |
| 55 | self.output = tf.squeeze(self.output) |
| 56 | |
| 57 | def transform(self, state, sess=None): |
| 58 | sess = sess or tf.get_default_session() |
| 59 | return sess.run(self.output, { self.input_state: state }) |
| 60 | |
| 61 | |
| 62 | def update_state(state, obs_small): |