| 199 | |
| 200 | |
| 201 | class LazyFrames: |
| 202 | def __init__(self, frames): |
| 203 | """This object ensures that common frames between the observations are only stored once. |
| 204 | It exists purely to optimize memory usage which can be huge for DQN's 1M frames replay |
| 205 | buffers. |
| 206 | |
| 207 | This object should only be converted to numpy array before being passed to the model. |
| 208 | |
| 209 | You'd not believe how complex the previous solution was.""" |
| 210 | self._frames = frames |
| 211 | |
| 212 | def __array__(self, dtype=None): |
| 213 | out = np.concatenate(self._frames, axis=2) |
| 214 | if dtype is not None: |
| 215 | out = out.astype(dtype) |
| 216 | return out |
| 217 | |
| 218 | |
| 219 | def make_atari(env_id): |