Face_reg_app/FaceFeatureExtractorAPI/check_model_dim.py

21 lines
731 B
Python

import onnxruntime as ort
import numpy as np
# 检查 Python 端模型
python_model = "./checkpoints/face_recognizer.onnx"
session = ort.InferenceSession(python_model)
# 获取输出信息
output_info = session.get_outputs()[0]
print(f"Python 模型输出名称: {output_info.name}")
print(f"Python 模型输出形状: {output_info.shape}")
print(f"Python 模型输出维度: {output_info.shape[1] if len(output_info.shape) > 1 else 'Unknown'}")
# 创建测试输入
test_input = np.random.randn(1, 3, 248, 248).astype(np.float32)
input_name = session.get_inputs()[0].name
result = session.run(None, {input_name: test_input})
print(f"\n实际输出形状: {result[0].shape}")
print(f"实际特征维度: {result[0].shape[1]}")