itto_v1 / scripts /collect_data.py
schauhan14's picture
Add files using upload-large-folder tool
52ce49d verified
#!/usr/bin/env python3
import os
import shutil
import argparse
def main():
parser = argparse.ArgumentParser(
description="Assemble final MOSE dataset structure: annotations, frames, masks"
)
parser.add_argument(
"--npz-dir",
default="/central/groups/glab/schauhan/gt_data/mose_npz",
help="Dir containing <video_id>_*.npy files"
)
parser.add_argument(
"--jpeg-root",
default="/central/groups/glab/idemler/datasets/mose/JPEGImages",
help="Root of MOSE JPEGImages/<video_id>/"
)
parser.add_argument(
"--anno-root",
default="/central/groups/glab/idemler/datasets/mose/Annotations",
help="Root of MOSE Annotations/<video_id>/"
)
parser.add_argument(
"--output-root",
default="/central/groups/glab/schauhan/final-dataset/mose",
help="Where to build final-dataset/mose/{annotations,frames,masks}"
)
args = parser.parse_args()
# make sure final dirs exist
out_ann = os.path.join(args.output_root, "annotations")
out_fr = os.path.join(args.output_root, "frames")
out_mask = os.path.join(args.output_root, "masks")
for d in (out_ann, out_fr, out_mask):
os.makedirs(d, exist_ok=True)
# collect unique video IDs
vids = set()
for fn in os.listdir(args.npz_dir):
if fn.endswith(".npy") and "_" in fn:
vids.add(fn.split("_", 1)[0])
if not vids:
print("No .npy files found in", args.npz_dir)
return
for vid in sorted(vids):
print(f"→ Processing video {vid}")
# 1) annotations: copy all vid_*.npy into annotations/<vid>/
dst_ann_dir = os.path.join(out_ann, vid)
os.makedirs(dst_ann_dir, exist_ok=True)
for fn in os.listdir(args.npz_dir):
if fn.startswith(vid + "_") and fn.endswith(".npy"):
shutil.copy2(
os.path.join(args.npz_dir, fn),
os.path.join(dst_ann_dir, fn)
)
# 2) frames: copy JPEGImages/<vid>/ → frames/<vid>/
src_frames = os.path.join(args.jpeg_root, vid)
dst_frames = os.path.join(out_fr, vid)
if os.path.isdir(src_frames):
shutil.copytree(src_frames, dst_frames, dirs_exist_ok=True)
else:
print(f" ⚠️ frames folder not found: {src_frames}")
# 3) masks: copy Annotations/<vid>/ → masks/<vid>/
src_masks = os.path.join(args.anno_root, vid)
dst_masks = os.path.join(out_mask, vid)
if os.path.isdir(src_masks):
shutil.copytree(src_masks, dst_masks, dirs_exist_ok=True)
else:
print(f" ⚠️ masks folder not found: {src_masks}")
print("Done.")
if __name__ == "__main__":
main()