#!/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 _*.npy files" ) parser.add_argument( "--jpeg-root", default="/central/groups/glab/idemler/datasets/mose/JPEGImages", help="Root of MOSE JPEGImages//" ) parser.add_argument( "--anno-root", default="/central/groups/glab/idemler/datasets/mose/Annotations", help="Root of MOSE Annotations//" ) 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// 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// → frames// 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// → masks// 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()