Download unpack_checkpoint.py from cskrren/StereoHand: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/cskrren/StereoHand/resolve/main/unpack_checkpoint.py
- Command line
-
hf download hf://cskrren/StereoHand/unpack_checkpoint.py
-
curl -L -o unpack_checkpoint.py https://huggingface.co/cskrren/StereoHand/resolve/main/unpack_checkpoint.py
1.25 kB
| """Export a joint checkpoint to files accepted by StereoHand SharedHeads.""" | |
| import argparse,json | |
| from pathlib import Path | |
| import torch | |
| def unpack(checkpoint,output,model_config): | |
| bundle=torch.load(checkpoint,map_location='cpu',mmap=True,weights_only=True) | |
| if bundle.get('format')!='stereohand-joint-v1':raise ValueError('Unsupported checkpoint format') | |
| root=Path(output).resolve();root.mkdir(parents=True,exist_ok=False) | |
| for branch in ('mask','mano','matching'): | |
| torch.save({'model':bundle['states'][branch]},root/(branch+'.pt')) | |
| config=json.loads(Path(model_config).read_text()) | |
| model=config.get('model',config) | |
| model.pop('inference_cache',None) | |
| for branch in ('mask','mano'): | |
| model[branch+'_initial']=model[branch+'_checkpoint']=str(root/(branch+'.pt')) | |
| model[branch+'_step']=bundle['steps'][branch]['step'] | |
| model['matching_checkpoint']=str(root/'matching.pt') | |
| target=root/'reconstruct.json';target.write_text(json.dumps(config,indent=2)) | |
| print(target) | |
| if __name__=='__main__': | |
| p=argparse.ArgumentParser();p.add_argument('checkpoint');p.add_argument('--output',required=True);p.add_argument('--config',required=True) | |
| a=p.parse_args();unpack(a.checkpoint,a.output,a.config) | |