Test muy simple en Python con ONNX Runtime

Para medir cuántas operaciones puede hacer tu equipo por segundo, y así estimar tus TOPS reales.

⚙️ 1. Instalar dependencias

Abre una terminal y ejecuta:

python3 -m venv ia_test
source ia_test/bin/activate
pip install onnxruntime numpy

📁 2. Descargar un modelo pequeño de prueba

Descarga el modelo MobileNetV2 en formato ONNX (solo ~14 MB):

wget https://github.com/onnx/models/raw/main/vision/classification/mobilenet/model/mobilenetv2-7.onnx -O mobilenetv2.onnx

3. Script para medir tiempo y calcular TOPS estimados

Copia esto en un archivo benchmark_tops.py:

import onnxruntime as ort
import numpy as np
import time

# Cargar modelo
session = ort.InferenceSession("mobilenetv2.onnx", providers=["CPUExecutionProvider"])

# Crear entrada falsa (imagen 1x3x224x224)
input_name = session.get_inputs()[0].name
dummy_input = np.random.rand(1, 3, 224, 224).astype(np.float32)

# Calcular operaciones aproximadas (MobileNetV2 ~300 millones MACs ≈ 0.3 GFLOPs)
ops_model = 3e8

# Calentar sesión
for _ in range(5):
    session.run(None, {input_name: dummy_input})

# Medir tiempo
start = time.time()
for _ in range(50):  # 50 inferencias
    session.run(None, {input_name: dummy_input})
end = time.time()

tiempo = end - start
ops_totales = ops_model * 50
tops_estimados = ops_totales / (tiempo * 1e12)

print(f"Tiempo total: {tiempo:.2f}s")
print(f"Rendimiento aproximado: {tops_estimados:.4f} TOPS")

▶️ 4. Ejecutarlo

python benchmark_tops.py

El script hará 50 inferencias y te mostrará algo como:

Tiempo total: 8.50s
Rendimiento aproximado: 1.7643 TOPS

Así podrás comparar el rendimiento de tu CPU/NPU real con los valores teóricos de los fabricantes.

Qué piensas?
Share your love
What Our Clients Say
1 review