dariuscty's picture
Restore RSI-Anything inference resources and LabHorizon dataset
672ecc3 verified
Raw History Blame Contribute Delete
648 Bytes
import hashlib,json
from pathlib import Path
def hash_object(value):
return hashlib.sha256(json.dumps(value,sort_keys=True,ensure_ascii=False,separators=(',',':')).encode()).hexdigest()
def checkpoint_manifest(path):
path=Path(path).resolve()
metadata=json.loads((path/'inference.json').read_text())
for name,expected in metadata['files'].items():
p=(path/name).resolve()
if path not in p.parents or not p.is_file() or hashlib.sha256(p.read_bytes()).hexdigest()!=expected:
raise RuntimeError('Model file checksum mismatch: '+name)
return metadata,metadata.get('model_identity',hash_object(metadata))