Upload folder using huggingface_hub
Browse files- __pycache__/predict.cpython-311.pyc +0 -0
- model_pole_position.pt +1 -1
- model_pong.pt +1 -1
- model_sonic.pt +1 -1
- predict.py +16 -9
__pycache__/predict.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/predict.cpython-311.pyc and b/__pycache__/predict.cpython-311.pyc differ
|
|
|
model_pole_position.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 2970182
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f9471a08cd9013392d19d9e950acda2e398ef8d3c2bcfe02079066393a337786
|
| 3 |
size 2970182
|
model_pong.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 2435368
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d6c8b9235347bea94e7e5f5f0f225d4c1dbd13a749d5e28920c75c91902ecb11
|
| 3 |
size 2435368
|
model_sonic.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 6180566
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:413d9fcfa15f30c74cdfda5f7d7c9dba8958fe027dfc09de563e6209c78378f5
|
| 3 |
size 6180566
|
predict.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
"""Prediction with
|
| 2 |
import sys
|
| 3 |
import os
|
| 4 |
import numpy as np
|
|
@@ -16,6 +16,12 @@ GAME_CONFIGS = {
|
|
| 16 |
"pole_position": {"enc_channels": (32, 64, 128), "bottleneck": 192},
|
| 17 |
}
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
def detect_game(context_frames: np.ndarray) -> str:
|
| 21 |
first_8 = context_frames[:CONTEXT_FRAMES]
|
|
@@ -50,6 +56,7 @@ def load_model(model_dir: str):
|
|
| 50 |
def predict_next_frame(models, context_frames: np.ndarray) -> np.ndarray:
|
| 51 |
game = detect_game(context_frames)
|
| 52 |
model = models[game]
|
|
|
|
| 53 |
|
| 54 |
n = len(context_frames)
|
| 55 |
if n < CONTEXT_FRAMES:
|
|
@@ -71,19 +78,19 @@ def predict_next_frame(models, context_frames: np.ndarray) -> np.ndarray:
|
|
| 71 |
|
| 72 |
# Original prediction
|
| 73 |
residual_orig = model(context_tensor)
|
| 74 |
-
predicted_orig = torch.clamp(last_tensor + residual_orig, 0, 1)
|
| 75 |
|
| 76 |
if game == "pong":
|
| 77 |
-
# Pong
|
| 78 |
-
|
|
|
|
| 79 |
else:
|
| 80 |
-
#
|
| 81 |
context_flipped = torch.flip(context_tensor, dims=[3])
|
| 82 |
-
last_flipped = torch.flip(last_tensor, dims=[3])
|
| 83 |
residual_flipped = model(context_flipped)
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
| 87 |
|
| 88 |
predicted_np = predicted[0].cpu().numpy()
|
| 89 |
predicted_np = np.transpose(predicted_np, (1, 2, 0))
|
|
|
|
| 1 |
+
"""Prediction with residual dampening and TTA for reduced AR error accumulation."""
|
| 2 |
import sys
|
| 3 |
import os
|
| 4 |
import numpy as np
|
|
|
|
| 16 |
"pole_position": {"enc_channels": (32, 64, 128), "bottleneck": 192},
|
| 17 |
}
|
| 18 |
|
| 19 |
+
DAMPEN_FACTORS = {
|
| 20 |
+
"pong": 0.90,
|
| 21 |
+
"sonic": 0.85,
|
| 22 |
+
"pole_position": 0.95,
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
|
| 26 |
def detect_game(context_frames: np.ndarray) -> str:
|
| 27 |
first_8 = context_frames[:CONTEXT_FRAMES]
|
|
|
|
| 56 |
def predict_next_frame(models, context_frames: np.ndarray) -> np.ndarray:
|
| 57 |
game = detect_game(context_frames)
|
| 58 |
model = models[game]
|
| 59 |
+
dampen = DAMPEN_FACTORS[game]
|
| 60 |
|
| 61 |
n = len(context_frames)
|
| 62 |
if n < CONTEXT_FRAMES:
|
|
|
|
| 78 |
|
| 79 |
# Original prediction
|
| 80 |
residual_orig = model(context_tensor)
|
|
|
|
| 81 |
|
| 82 |
if game == "pong":
|
| 83 |
+
# Pong: no TTA, apply dampening to residual
|
| 84 |
+
residual = residual_orig * dampen
|
| 85 |
+
predicted = torch.clamp(last_tensor + residual, 0, 1)
|
| 86 |
else:
|
| 87 |
+
# Sonic/PP: TTA with horizontal flip, then dampen
|
| 88 |
context_flipped = torch.flip(context_tensor, dims=[3])
|
|
|
|
| 89 |
residual_flipped = model(context_flipped)
|
| 90 |
+
residual_flipped = torch.flip(residual_flipped, dims=[3])
|
| 91 |
+
# Average residuals, then dampen
|
| 92 |
+
residual = (residual_orig + residual_flipped) / 2.0 * dampen
|
| 93 |
+
predicted = torch.clamp(last_tensor + residual, 0, 1)
|
| 94 |
|
| 95 |
predicted_np = predicted[0].cpu().numpy()
|
| 96 |
predicted_np = np.transpose(predicted_np, (1, 2, 0))
|