File size: 2,789 Bytes
bec125c
 
 
 
 
 
 
 
 
 
 
52ce49d
bec125c
 
 
 
52ce49d
bec125c
 
 
 
52ce49d
bec125c
 
 
 
52ce49d
bec125c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/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()