FangSen9000 commited on
Commit ·
f379d24
1
Parent(s): 09eaa7b
Update preprocessing, logging, and config
Browse files
plugins/SignX/smkd/utils/parameters.py
CHANGED
|
@@ -81,6 +81,11 @@ def get_parser():
|
|
| 81 |
default=dict(),
|
| 82 |
help='data loader will be used'
|
| 83 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
parser.add_argument(
|
| 85 |
'--num-worker',
|
| 86 |
type=int,
|
|
|
|
| 81 |
default=dict(),
|
| 82 |
help='data loader will be used'
|
| 83 |
)
|
| 84 |
+
parser.add_argument(
|
| 85 |
+
'--preprocess-sample-ratio',
|
| 86 |
+
type=float,
|
| 87 |
+
default=1.0,
|
| 88 |
+
help='preprocess-only: fraction of manifest to sample (unused by training)')
|
| 89 |
parser.add_argument(
|
| 90 |
'--num-worker',
|
| 91 |
type=int,
|
plugins/SignX/training_yutubeasl/configs/youtubeasl_smkd.yaml
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
feeder: dataset.dataloader_video.BaseFeeder
|
| 2 |
phase: train
|
| 3 |
dataset: youtubeasl
|
| 4 |
-
num_epoch:
|
| 5 |
work_dir: ./work_dir/youtubeasl_baseline/
|
| 6 |
batch_size: 2
|
| 7 |
random_seed: 0
|
|
|
|
|
|
|
| 8 |
test_batch_size: 8
|
| 9 |
num_worker: 4
|
| 10 |
device: 0
|
|
@@ -36,6 +38,8 @@ feeder_args:
|
|
| 36 |
datatype: 'video'
|
| 37 |
num_gloss: -1
|
| 38 |
drop_ratio: 1.0
|
|
|
|
|
|
|
| 39 |
ctc_length_guard: true
|
| 40 |
ctc_length_guard_post: true
|
| 41 |
max_frames: 800
|
|
|
|
| 1 |
feeder: dataset.dataloader_video.BaseFeeder
|
| 2 |
phase: train
|
| 3 |
dataset: youtubeasl
|
| 4 |
+
num_epoch: 1500
|
| 5 |
work_dir: ./work_dir/youtubeasl_baseline/
|
| 6 |
batch_size: 2
|
| 7 |
random_seed: 0
|
| 8 |
+
preprocess_sample_ratio: 1 # Use 0.1 to sample 10% of manifest entries
|
| 9 |
+
scale_update_cycle: true # Scale SLTUNET update_cycle by GPU count
|
| 10 |
test_batch_size: 8
|
| 11 |
num_worker: 4
|
| 12 |
device: 0
|
|
|
|
| 38 |
datatype: 'video'
|
| 39 |
num_gloss: -1
|
| 40 |
drop_ratio: 1.0
|
| 41 |
+
transform_mode: false
|
| 42 |
+
# transform_mode: false 只会关闭训练增强(RandomCrop/Flip/TemporalRescale)
|
| 43 |
ctc_length_guard: true
|
| 44 |
ctc_length_guard_post: true
|
| 45 |
max_frames: 800
|
plugins/SignX/training_yutubeasl/scripts/1_preprocess.py
CHANGED
|
@@ -91,6 +91,18 @@ def _split_by_video(samples, seed, val_size, test_size):
|
|
| 91 |
return train, val, test
|
| 92 |
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
def preprocess_youtubeasl(
|
| 95 |
manifest_path,
|
| 96 |
output_dir,
|
|
@@ -98,6 +110,9 @@ def preprocess_youtubeasl(
|
|
| 98 |
seed=1234,
|
| 99 |
val_size=300,
|
| 100 |
test_size=100,
|
|
|
|
|
|
|
|
|
|
| 101 |
video_root=None,
|
| 102 |
frames_root=None,
|
| 103 |
min_frames=0,
|
|
@@ -108,16 +123,52 @@ def preprocess_youtubeasl(
|
|
| 108 |
samples, skipped = _read_manifest(manifest_path, video_root=video_root)
|
| 109 |
|
| 110 |
print(f"Total samples: {len(samples)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
if any(skipped.values()):
|
| 112 |
print(
|
| 113 |
"Skipped samples: "
|
| 114 |
+ ", ".join(f"{k}={v}" for k, v in skipped.items() if v)
|
| 115 |
)
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
train_samples, val_samples, test_samples = _split_by_video(
|
| 118 |
samples, seed=seed, val_size=val_size, test_size=test_size
|
| 119 |
)
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
if len(val_samples) < val_size or len(test_samples) < test_size:
|
| 122 |
print(
|
| 123 |
"Warning: requested split sizes not reached. "
|
|
@@ -261,6 +312,24 @@ if __name__ == "__main__":
|
|
| 261 |
default=100,
|
| 262 |
help="Test split size (by clips)",
|
| 263 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
parser.add_argument(
|
| 265 |
"--frames-root",
|
| 266 |
type=str,
|
|
@@ -296,6 +365,9 @@ if __name__ == "__main__":
|
|
| 296 |
seed=args.seed,
|
| 297 |
val_size=args.val_size,
|
| 298 |
test_size=args.test_size,
|
|
|
|
|
|
|
|
|
|
| 299 |
video_root=video_root,
|
| 300 |
frames_root=frames_root,
|
| 301 |
min_frames=min_frames,
|
|
|
|
| 91 |
return train, val, test
|
| 92 |
|
| 93 |
|
| 94 |
+
def _move_one_video_group(src, dst):
|
| 95 |
+
if not src:
|
| 96 |
+
return False
|
| 97 |
+
video_name = src[0]["video_name"]
|
| 98 |
+
group = [s for s in src if s["video_name"] == video_name]
|
| 99 |
+
if not group:
|
| 100 |
+
return False
|
| 101 |
+
src[:] = [s for s in src if s["video_name"] != video_name]
|
| 102 |
+
dst.extend(group)
|
| 103 |
+
return True
|
| 104 |
+
|
| 105 |
+
|
| 106 |
def preprocess_youtubeasl(
|
| 107 |
manifest_path,
|
| 108 |
output_dir,
|
|
|
|
| 110 |
seed=1234,
|
| 111 |
val_size=300,
|
| 112 |
test_size=100,
|
| 113 |
+
sample_ratio=1.0,
|
| 114 |
+
val_ratio=None,
|
| 115 |
+
test_ratio=None,
|
| 116 |
video_root=None,
|
| 117 |
frames_root=None,
|
| 118 |
min_frames=0,
|
|
|
|
| 123 |
samples, skipped = _read_manifest(manifest_path, video_root=video_root)
|
| 124 |
|
| 125 |
print(f"Total samples: {len(samples)}")
|
| 126 |
+
if not (0 < sample_ratio <= 1.0):
|
| 127 |
+
raise ValueError(f"sample_ratio must be in (0, 1], got {sample_ratio}")
|
| 128 |
+
if sample_ratio < 1.0:
|
| 129 |
+
rng = random.Random(seed)
|
| 130 |
+
rng.shuffle(samples)
|
| 131 |
+
keep = max(1, int(len(samples) * sample_ratio))
|
| 132 |
+
samples = samples[:keep]
|
| 133 |
+
print(f"Sampled {len(samples)} samples ({sample_ratio:.2%} of manifest)")
|
| 134 |
if any(skipped.values()):
|
| 135 |
print(
|
| 136 |
"Skipped samples: "
|
| 137 |
+ ", ".join(f"{k}={v}" for k, v in skipped.items() if v)
|
| 138 |
)
|
| 139 |
|
| 140 |
+
if val_ratio is not None or test_ratio is not None:
|
| 141 |
+
if val_ratio is None or test_ratio is None:
|
| 142 |
+
raise ValueError("Both val_ratio and test_ratio must be set when using ratios")
|
| 143 |
+
if not (0 <= val_ratio < 1.0 and 0 <= test_ratio < 1.0):
|
| 144 |
+
raise ValueError("val_ratio and test_ratio must be in [0, 1)")
|
| 145 |
+
if val_ratio + test_ratio >= 1.0:
|
| 146 |
+
raise ValueError("val_ratio + test_ratio must be < 1.0")
|
| 147 |
+
val_size = max(1, int(len(samples) * val_ratio)) if val_ratio > 0 else 0
|
| 148 |
+
test_size = max(1, int(len(samples) * test_ratio)) if test_ratio > 0 else 0
|
| 149 |
+
print(
|
| 150 |
+
f"Using ratio-based split: val={val_ratio:.2%} ({val_size}), "
|
| 151 |
+
f"test={test_ratio:.2%} ({test_size})"
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
train_samples, val_samples, test_samples = _split_by_video(
|
| 155 |
samples, seed=seed, val_size=val_size, test_size=test_size
|
| 156 |
)
|
| 157 |
|
| 158 |
+
# Ensure non-empty dev/test splits when possible by moving one video group.
|
| 159 |
+
if len(val_samples) == 0:
|
| 160 |
+
moved = _move_one_video_group(train_samples, val_samples)
|
| 161 |
+
if not moved:
|
| 162 |
+
_move_one_video_group(test_samples, val_samples)
|
| 163 |
+
if len(val_samples) > 0:
|
| 164 |
+
print(f"Adjusted split to ensure non-empty dev; dev={len(val_samples)}")
|
| 165 |
+
if len(test_samples) == 0:
|
| 166 |
+
moved = _move_one_video_group(train_samples, test_samples)
|
| 167 |
+
if not moved:
|
| 168 |
+
_move_one_video_group(val_samples, test_samples)
|
| 169 |
+
if len(test_samples) > 0:
|
| 170 |
+
print(f"Adjusted split to ensure non-empty test; test={len(test_samples)}")
|
| 171 |
+
|
| 172 |
if len(val_samples) < val_size or len(test_samples) < test_size:
|
| 173 |
print(
|
| 174 |
"Warning: requested split sizes not reached. "
|
|
|
|
| 312 |
default=100,
|
| 313 |
help="Test split size (by clips)",
|
| 314 |
)
|
| 315 |
+
parser.add_argument(
|
| 316 |
+
"--val-ratio",
|
| 317 |
+
type=float,
|
| 318 |
+
default=None,
|
| 319 |
+
help="Validation split ratio over the sampled manifest (e.g., 0.06)",
|
| 320 |
+
)
|
| 321 |
+
parser.add_argument(
|
| 322 |
+
"--test-ratio",
|
| 323 |
+
type=float,
|
| 324 |
+
default=None,
|
| 325 |
+
help="Test split ratio over the sampled manifest (e.g., 0.04)",
|
| 326 |
+
)
|
| 327 |
+
parser.add_argument(
|
| 328 |
+
"--sample-ratio",
|
| 329 |
+
type=float,
|
| 330 |
+
default=1.0,
|
| 331 |
+
help="Randomly sample this fraction of the manifest before splitting",
|
| 332 |
+
)
|
| 333 |
parser.add_argument(
|
| 334 |
"--frames-root",
|
| 335 |
type=str,
|
|
|
|
| 365 |
seed=args.seed,
|
| 366 |
val_size=args.val_size,
|
| 367 |
test_size=args.test_size,
|
| 368 |
+
sample_ratio=args.sample_ratio,
|
| 369 |
+
val_ratio=args.val_ratio,
|
| 370 |
+
test_ratio=args.test_ratio,
|
| 371 |
video_root=video_root,
|
| 372 |
frames_root=frames_root,
|
| 373 |
min_frames=min_frames,
|
plugins/SignX/utils/loss_logger.py
CHANGED
|
@@ -111,7 +111,11 @@ class LossLogger:
|
|
| 111 |
for row in reader:
|
| 112 |
self.eval_steps.append(int(row['step']))
|
| 113 |
self.eval_losses.append(float(row['eval_loss']))
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
def generate_plots(self):
|
| 117 |
"""Generate loss and BLEU plots."""
|
|
|
|
| 111 |
for row in reader:
|
| 112 |
self.eval_steps.append(int(row['step']))
|
| 113 |
self.eval_losses.append(float(row['eval_loss']))
|
| 114 |
+
# Backward compatibility: older CSVs used different BLEU column names
|
| 115 |
+
bleu_val = row.get('bleu_score', None)
|
| 116 |
+
if bleu_val is None or bleu_val == '':
|
| 117 |
+
bleu_val = row.get('bleu4', 0.0)
|
| 118 |
+
self.eval_bleus.append(float(bleu_val))
|
| 119 |
|
| 120 |
def generate_plots(self):
|
| 121 |
"""Generate loss and BLEU plots."""
|