File size: 1,478 Bytes
6b95c6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Build-time official GeoCalib checkpoint acquisition and offline preflight."""
import argparse
import hashlib
import json
from pathlib import Path
import sys
import urllib.request
from baseball_batting.camera_up_provider import REVISION,WEIGHTS_URL,WEIGHTS_SHA256


def main():
    p=argparse.ArgumentParser();p.add_argument('--output',required=True);args=p.parse_args()
    root=Path(args.output);root.mkdir(parents=True,exist_ok=True);weights=root/'geocalib-pinhole.tar'
    if not weights.is_file() or hashlib.sha256(weights.read_bytes()).hexdigest()!=WEIGHTS_SHA256:
        temporary=weights.with_suffix('.part')
        with urllib.request.urlopen(WEIGHTS_URL,timeout=90) as response,temporary.open('wb') as out:
            while block:=response.read(1024*1024):out.write(block)
        if hashlib.sha256(temporary.read_bytes()).hexdigest()!=WEIGHTS_SHA256:raise ValueError('GeoCalib checkpoint checksum mismatch')
        temporary.replace(weights)
    from geocalib import GeoCalib
    GeoCalib(weights=str(weights)).eval()  # Offline model construction, no video or provider credentials.
    (root/'provider.json').write_text(json.dumps({'worker_python':sys.executable,'weights':str(weights.resolve()),
        'weights_sha256':WEIGHTS_SHA256,'source_revision':REVISION,'provider':'cvg/GeoCalib',
        'weights_license':'CC-BY-4.0; Copyright 2024 ETH Zurich','code_license':'Apache-2.0'},indent=2))
    return 0


if __name__=='__main__':raise SystemExit(main())