ojaffe commited on
Commit
4a7a96e
·
verified ·
1 Parent(s): 5f64874

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. __pycache__/predict.cpython-311.pyc +0 -0
  2. predict.py +6 -18
__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
@@ -113,9 +113,9 @@ def _predict_8frames_direct(model, context_tensor, last_tensor):
113
  return torch.clamp(last_expanded + residuals, 0, 1)
114
 
115
 
116
- def _predict_ar_frame(model, context_tensor, last_tensor):
117
  residual = model(context_tensor)
118
- return torch.clamp(last_tensor + residual, 0, 1)
119
 
120
 
121
  def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
@@ -202,9 +202,8 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
202
  direct_flipped = torch.flip(direct_flipped, dims=[4])
203
  direct_pred = (direct_orig + direct_flipped) / 2.0
204
 
205
- # Multi-run AR with noise diversity, track TTA disagreement
206
  all_ar_runs = []
207
- tta_disagreements = [] # per-step disagreement from clean run
208
  for noise_std in [0.0, 1.0/255.0, 2.0/255.0]:
209
  ar_preds_run = []
210
  ctx = context_tensor.clone()
@@ -214,13 +213,9 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
214
  for step in range(PRED_FRAMES):
215
  ctx_in = ctx if noise_std == 0 else torch.clamp(ctx + torch.randn_like(ctx) * noise_std, 0, 1)
216
  ctx_flip_in = ctx_flip if noise_std == 0 else torch.clamp(ctx_flip + torch.randn_like(ctx_flip) * noise_std, 0, 1)
217
- ar_orig = _predict_ar_frame(ens.sonic_ar, ctx_in, last_t)
218
- ar_flip = _predict_ar_frame(ens.sonic_ar, ctx_flip_in, last_f)
219
  ar_flip_back = torch.flip(ar_flip, dims=[3])
220
- # Track TTA disagreement for clean run
221
- if noise_std == 0:
222
- disagreement = torch.abs(ar_orig - ar_flip_back).mean().item()
223
- tta_disagreements.append(disagreement)
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)
@@ -237,14 +232,7 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
237
 
238
  predicted = torch.zeros_like(direct_pred)
239
  for step in range(PRED_FRAMES):
240
- base_ar_weight = 0.65 - (step / (PRED_FRAMES - 1)) * 0.3
241
- # Adjust based on TTA disagreement
242
- disagreement = tta_disagreements[step]
243
- if disagreement < 5.0 / 255.0:
244
- base_ar_weight += 0.1 # AR confident
245
- elif disagreement > 15.0 / 255.0:
246
- base_ar_weight -= 0.1 # AR uncertain
247
- ar_weight = max(0.15, min(0.85, base_ar_weight))
248
  direct_weight = 1.0 - ar_weight
249
  predicted[:, step] = ar_weight * ar_pred[:, step] + direct_weight * direct_pred[:, step]
250
 
 
113
  return torch.clamp(last_expanded + residuals, 0, 1)
114
 
115
 
116
+ def _predict_ar_frame(model, context_tensor, last_tensor, residual_scale=1.0):
117
  residual = model(context_tensor)
118
+ return torch.clamp(last_tensor + residual_scale * residual, 0, 1)
119
 
120
 
121
  def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
 
202
  direct_flipped = torch.flip(direct_flipped, dims=[4])
203
  direct_pred = (direct_orig + direct_flipped) / 2.0
204
 
205
+ # Multi-run AR with noise diversity
206
  all_ar_runs = []
 
207
  for noise_std in [0.0, 1.0/255.0, 2.0/255.0]:
208
  ar_preds_run = []
209
  ctx = context_tensor.clone()
 
213
  for step in range(PRED_FRAMES):
214
  ctx_in = ctx if noise_std == 0 else torch.clamp(ctx + torch.randn_like(ctx) * noise_std, 0, 1)
215
  ctx_flip_in = ctx_flip if noise_std == 0 else torch.clamp(ctx_flip + torch.randn_like(ctx_flip) * noise_std, 0, 1)
216
+ ar_orig = _predict_ar_frame(ens.sonic_ar, ctx_in, last_t, residual_scale=0.95)
217
+ ar_flip = _predict_ar_frame(ens.sonic_ar, ctx_flip_in, last_f, residual_scale=0.95)
218
  ar_flip_back = torch.flip(ar_flip, dims=[3])
 
 
 
 
219
  ar_frame = (ar_orig + ar_flip_back) / 2.0
220
  ar_preds_run.append(ar_frame)
221
  ctx_frames = ctx.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
 
232
 
233
  predicted = torch.zeros_like(direct_pred)
234
  for step in range(PRED_FRAMES):
235
+ ar_weight = 0.65 - (step / (PRED_FRAMES - 1)) * 0.3
 
 
 
 
 
 
 
236
  direct_weight = 1.0 - ar_weight
237
  predicted[:, step] = ar_weight * ar_pred[:, step] + direct_weight * direct_pred[:, step]
238