File size: 648 Bytes
672ecc3
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
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))