File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 9393 # copy metadata
9494 cp "$ONNX_DIR/metadata.json" release_temp/ 2>/dev/null || true
9595
96- # Generate labels.json from config
97- python -c "
98- import json, os, sys
99- onnx_dir = sys.argv[1]
100- if not onnx_dir:
101- sys.exit(1)
102- config_path = os.path.join(onnx_dir, 'config.json')
103- with open(config_path) as f:
104- config = json.load(f)
105- labels = [config['id2label'][str(i)] for i in range(len(config['id2label']))]
106- with open('release_temp/labels.json', 'w') as f:
107- json.dump(labels, f)
108- " "$ONNX_DIR"
96+ # Generate labels.json from config (using an external script)
97+ python src/generate_labels_json.py "$ONNX_DIR"
10998
11099 # Zip the release
111100 (cd release_temp && zip -r "../release_artifacts/$ZIP_NAME" .)
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ """Generate labels.json from an ONNX export directory (config.json)."""
3+
4+ import json
5+ import os
6+ import sys
7+
8+ def main ():
9+ if len (sys .argv ) != 2 :
10+ print ("Usage: generate_labels_json.py <onnx_dir>" )
11+ sys .exit (1 )
12+
13+ onnx_dir = sys .argv [1 ]
14+ config_path = os .path .join (onnx_dir , "config.json" )
15+
16+ with open (config_path , "r" ) as f :
17+ config = json .load (f )
18+
19+ # Map id2label to an ordered list of labels
20+ labels = [config ["id2label" ][str (i )] for i in range (len (config ["id2label" ]))]
21+
22+ # Output to release_temp/labels.json (working directory is repo root)
23+ os .makedirs ("release_temp" , exist_ok = True )
24+ with open ("release_temp/labels.json" , "w" ) as f :
25+ json .dump (labels , f )
26+
27+ print (f"labels.json written with { len (labels )} labels." )
28+
29+ if __name__ == "__main__" :
30+ main ()
You can’t perform that action at this time.
0 commit comments