ceyxprime commited on
Commit
eb9afd8
Β·
verified Β·
1 Parent(s): 031ff2d

Upload det01_check_det_batch.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. det01_check_det_batch.py +43 -0
det01_check_det_batch.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ det01 β€” Inspect det_500m.onnx input/output shapes and test batch > 1.
4
+
5
+ Answers: does the model support batched frame input, or is it fixed at batch=1?
6
+ """
7
+ import argparse
8
+ import numpy as np
9
+ import onnxruntime as ort
10
+ import onnx
11
+
12
+ parser = argparse.ArgumentParser()
13
+ parser.add_argument('--model', required=True, help='Path to det_500m.onnx')
14
+ args = parser.parse_args()
15
+
16
+ # ── Declared shapes from ONNX graph ──────────────────────────────────────────
17
+ model = onnx.load(args.model)
18
+
19
+ print('=== Declared input shapes ===')
20
+ for inp in model.graph.input:
21
+ shape = [d.dim_param if d.HasField('dim_param') else d.dim_value
22
+ for d in inp.type.tensor_type.shape.dim]
23
+ print(f' {inp.name}: {shape}')
24
+
25
+ print('\n=== Declared output shapes ===')
26
+ for out in model.graph.output:
27
+ shape = [d.dim_param if d.HasField('dim_param') else d.dim_value
28
+ for d in out.type.tensor_type.shape.dim]
29
+ print(f' {out.name}: {shape}')
30
+
31
+ # ── Runtime test with N=1 and N=2 ────────────────────────────────────────────
32
+ print('\n=== Runtime batch test ===')
33
+ sess = ort.InferenceSession(args.model, providers=['CPUExecutionProvider'])
34
+ inp0 = sess.get_inputs()[0]
35
+ out_names = [o.name for o in sess.get_outputs()]
36
+
37
+ for N in (1, 2):
38
+ dummy = np.random.randint(0, 255, (N, 3, 640, 640)).astype(np.float32)
39
+ try:
40
+ outs = sess.run(out_names, {inp0.name: dummy})
41
+ print(f' N={N}: OK output shapes={[list(o.shape) for o in outs]}')
42
+ except Exception as e:
43
+ print(f' N={N}: FAILED β€” {e}')