ojaffe commited on
Commit
efae84f
·
verified ·
1 Parent(s): 4632ad0

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. __pycache__/predict.cpython-311.pyc +0 -0
  2. predict.py +21 -28
__pycache__/predict.cpython-311.pyc CHANGED
Binary files a/__pycache__/predict.cpython-311.pyc and b/__pycache__/predict.cpython-311.pyc differ
 
predict.py CHANGED
@@ -149,26 +149,31 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
149
  context_tensor = torch.from_numpy(context).to(DEVICE)
150
  last_tensor = torch.from_numpy(last_frame_t).to(DEVICE)
151
 
152
- direct_pred = _predict_8frames_direct(ens.pong_direct, context_tensor, last_tensor)
 
 
153
 
154
  ar_preds = []
155
  ctx = context_tensor.clone()
 
156
  last_t = last_tensor.clone()
 
157
  for step in range(PRED_FRAMES):
158
- predicted = _predict_ar_frame(ens.models["pong"], ctx, last_t)
159
- ar_preds.append(predicted)
 
 
 
160
  ctx_frames = ctx.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
161
- ctx_frames = torch.cat([ctx_frames[:, 1:], predicted.unsqueeze(1)], dim=1)
162
  ctx = ctx_frames.reshape(1, -1, 64, 64)
163
- last_t = predicted
 
 
 
 
164
 
165
- ar_pred = torch.stack(ar_preds, dim=1)
166
-
167
- predicted = torch.zeros_like(direct_pred)
168
- for step in range(PRED_FRAMES):
169
- ar_weight = 0.85 - (step / (PRED_FRAMES - 1)) * 0.3
170
- direct_weight = 1.0 - ar_weight
171
- predicted[:, step] = ar_weight * ar_pred[:, step] + direct_weight * direct_pred[:, step]
172
 
173
  predicted_np = predicted[0].cpu().numpy()
174
  ens.direct_cache = []
@@ -203,10 +208,6 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
203
  direct_pred = (direct_orig + direct_flipped) / 2.0
204
 
205
  # Multi-run AR with noise diversity
206
- # For no-noise run: feed blended AR+direct as context
207
- direct_frames = direct_pred.reshape(1, PRED_FRAMES, 3, 64, 64)
208
- direct_frames_flip = torch.flip(direct_frames, dims=[4])
209
-
210
  all_ar_runs = []
211
  for noise_std in [0.0, 1.0/255.0, 2.0/255.0]:
212
  ar_preds_run = []
@@ -222,22 +223,14 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
222
  ar_flip_back = torch.flip(ar_flip, dims=[3])
223
  ar_frame = (ar_orig + ar_flip_back) / 2.0
224
  ar_preds_run.append(ar_frame)
225
- # For no-noise run: blend with direct before feeding back
226
- if noise_std == 0:
227
- w = 0.65 - (step / (PRED_FRAMES - 1)) * 0.3
228
- feedback_orig = w * ar_orig + (1.0 - w) * direct_frames[:, step]
229
- feedback_flip = w * ar_flip + (1.0 - w) * direct_frames_flip[:, step]
230
- else:
231
- feedback_orig = ar_orig
232
- feedback_flip = ar_flip
233
  ctx_frames = ctx.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
234
- ctx_frames = torch.cat([ctx_frames[:, 1:], feedback_orig.unsqueeze(1)], dim=1)
235
  ctx = ctx_frames.reshape(1, -1, 64, 64)
236
- last_t = feedback_orig
237
  ctx_flip_frames = ctx_flip.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
238
- ctx_flip_frames = torch.cat([ctx_flip_frames[:, 1:], feedback_flip.unsqueeze(1)], dim=1)
239
  ctx_flip = ctx_flip_frames.reshape(1, -1, 64, 64)
240
- last_f = feedback_flip
241
  all_ar_runs.append(torch.stack(ar_preds_run, dim=1))
242
 
243
  ar_pred = sum(all_ar_runs) / len(all_ar_runs)
 
149
  context_tensor = torch.from_numpy(context).to(DEVICE)
150
  last_tensor = torch.from_numpy(last_frame_t).to(DEVICE)
151
 
152
+ # Pong AR-only with hflip TTA
153
+ context_flipped = torch.flip(context_tensor, dims=[3])
154
+ last_flipped = torch.flip(last_tensor, dims=[3])
155
 
156
  ar_preds = []
157
  ctx = context_tensor.clone()
158
+ ctx_flip = context_flipped.clone()
159
  last_t = last_tensor.clone()
160
+ last_f = last_flipped.clone()
161
  for step in range(PRED_FRAMES):
162
+ ar_orig = _predict_ar_frame(ens.models["pong"], ctx, last_t)
163
+ ar_flip = _predict_ar_frame(ens.models["pong"], ctx_flip, last_f)
164
+ ar_flip_back = torch.flip(ar_flip, dims=[3])
165
+ ar_frame = (ar_orig + ar_flip_back) / 2.0
166
+ ar_preds.append(ar_frame)
167
  ctx_frames = ctx.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
168
+ ctx_frames = torch.cat([ctx_frames[:, 1:], ar_orig.unsqueeze(1)], dim=1)
169
  ctx = ctx_frames.reshape(1, -1, 64, 64)
170
+ last_t = ar_orig
171
+ ctx_flip_frames = ctx_flip.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
172
+ ctx_flip_frames = torch.cat([ctx_flip_frames[:, 1:], ar_flip.unsqueeze(1)], dim=1)
173
+ ctx_flip = ctx_flip_frames.reshape(1, -1, 64, 64)
174
+ last_f = ar_flip
175
 
176
+ predicted = torch.stack(ar_preds, dim=1)
 
 
 
 
 
 
177
 
178
  predicted_np = predicted[0].cpu().numpy()
179
  ens.direct_cache = []
 
208
  direct_pred = (direct_orig + direct_flipped) / 2.0
209
 
210
  # Multi-run AR with noise diversity
 
 
 
 
211
  all_ar_runs = []
212
  for noise_std in [0.0, 1.0/255.0, 2.0/255.0]:
213
  ar_preds_run = []
 
223
  ar_flip_back = torch.flip(ar_flip, dims=[3])
224
  ar_frame = (ar_orig + ar_flip_back) / 2.0
225
  ar_preds_run.append(ar_frame)
 
 
 
 
 
 
 
 
226
  ctx_frames = ctx.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
227
+ ctx_frames = torch.cat([ctx_frames[:, 1:], ar_orig.unsqueeze(1)], dim=1)
228
  ctx = ctx_frames.reshape(1, -1, 64, 64)
229
+ last_t = ar_orig
230
  ctx_flip_frames = ctx_flip.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
231
+ ctx_flip_frames = torch.cat([ctx_flip_frames[:, 1:], ar_flip.unsqueeze(1)], dim=1)
232
  ctx_flip = ctx_flip_frames.reshape(1, -1, 64, 64)
233
+ last_f = ar_flip
234
  all_ar_runs.append(torch.stack(ar_preds_run, dim=1))
235
 
236
  ar_pred = sum(all_ar_runs) / len(all_ar_runs)