File size: 1,802 Bytes
124e919
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Run one frozen variant on the user's own DanceTrack frames and the supplied inputs."""
import argparse
import json
from pathlib import Path
import numpy as np
import torch
from PIL import Image
from common_loop import run
from engines import Multiplex,S3
from holdtrack.sam._sequence import DetectionCandidate,_load_detections
from holdtrack.sam.projection import project

def main():
    parser=argparse.ArgumentParser(description=__doc__)
    parser.add_argument('variant',choices=['S3n','S3x','M16n','M16x'])
    for n in ('frames','inputs','output'):parser.add_argument(n,type=Path)
    a=parser.parse_args()
    paths=sorted(a.frames.glob('*.jpg'))
    meta=json.loads((a.inputs/'sequence.json').read_text())
    assert len(paths)==meta['frames']
    with Image.open(paths[0]) as im:w,h=im.size
    assert (w,h)==(meta['width'],meta['height'])
    import hashlib
    for p,expected in zip(paths,meta['image_sha256'],strict=True):
        with p.open('rb') as f:assert hashlib.file_digest(f,'sha256').hexdigest()==expected,p.name
    fr,boxes,scores=_load_detections(a.inputs/'births.npz',len(paths))
    detections={}
    for i,(frame,box,score) in enumerate(zip(fr,boxes,scores)):
        detections.setdefault(int(frame),[]).append(DetectionCandidate(i,tuple(box),float(score)))
    torch.set_num_threads(2)
    torch.manual_seed(20261201);np.random.seed(20261201)
    with torch.inference_mode(),torch.autocast('cuda',dtype=torch.bfloat16):
        model=(S3 if a.variant.startswith('S3') else Multiplex)(paths,w,h,a.variant.endswith('x'))
        run(model,detections,len(paths),a.output)
        result,_=project((a.inputs/'support.txt').read_bytes(),(a.output/'raw_MASK_BOX_IDS.txt').read_bytes())
        (a.output/'projected_2XL.txt').write_bytes(result)
if __name__=='__main__':main()