Hello,
I am developing an engineering project with machine vision, I am following this tutorial GitHub - NVIDIA-AI-IOT/trt_pose: Real-time pose estimation accelerated with NVIDIA TensorRT and I downloaded the weights of the resnet18 model from this link Models - JetNet
to optimize the model I get the following error, using only the conversion part with torch2trt.
Conversion Script:
import torch
from torch2trt import torch2trt, TRTModule
import trt_pose.models
import os
Configuración de parámetros para el modelo
MODEL_WEIGHTS = ‘resnet18_baseline_att_224x224_A_epoch_249.pth’ # archivo de pesos
OPTIMIZED_MODEL = ‘resnet18_baseline_att_224x224_A_epoch_249_trt.pth’ # guardar modelo optimizado
HEIGHT, WIDTH = 224, 224 # tamaño de entrada para el modelo
num_parts = 18 # número de puntos clave (keypoints) en el modelo de pose humana
num_links = 21 # número de conexiones entre puntos clave
Carga del modelo base en PyTorch
model = trt_pose.models.resnet18_baseline_att(num_parts, 2 * num_links).cuda().eval()
Preparación de un tensor de entrada de ejemplo para la conversión
data = torch.zeros((1, 3, HEIGHT, WIDTH)).cuda()
Convertir y guardar el modelo solo si el archivo optimizado no existe
if not os.path.exists(OPTIMIZED_MODEL):
# Cargar los pesos del modelo de PyTorch
model.load_state_dict(torch.load(MODEL_WEIGHTS))
# Convertir el modelo de PyTorch a TensorRT con torch2trt
model_trt = torch2trt(model, [data], fp16_mode=True, max_workspace_size=1 << 25)
# Guardar el modelo optimizado
torch.save(model_trt.state_dict(), OPTIMIZED_MODEL)
print(“Conversión a TensorRT completada y guardada como:”, OPTIMIZED_MODEL)
Error:
[10/30/2024-20:51:28] [TRT] [E] 3: 1.cmap_up.0:0:DECONVOLUTION:GPU:kernel weights has count 2097152 but 4194304 was expected
[10/30/2024-20:51:28] [TRT] [E] 4: 1.cmap_up.0:0:DECONVOLUTION:GPU: count of 2097152 weights in kernel, but kernel dimensions (4,4) with 512 input channels, 512 output channels and 1 groups were specified. Expected Weights count is 512 * 44 * 512 / 1 = 4194304
[10/30/2024-20:51:28] [TRT] [E] 3: 1.cmap_up.0:0:DECONVOLUTION:GPU:kernel weights has count 2097152 but 4194304 was expected
[10/30/2024-20:51:28] [TRT] [E] 4: 1.cmap_up.0:0:DECONVOLUTION:GPU: count of 2097152 weights in kernel, but kernel dimensions (4,4) with 512 input channels, 512 output channels and 1 groups were specified. Expected Weights count is 512 * 44 * 512 / 1 = 4194304
[10/30/2024-20:51:28] [TRT] [E] 3: 1.cmap_up.0:0:DECONVOLUTION:GPU:kernel weights has count 2097152 but 4194304 was expected
[10/30/2024-20:51:28] [TRT] [E] 4: 1.cmap_up.0:0:DECONVOLUTION:GPU: count of 2097152 weights in kernel, but kernel dimensions (4,4) with 512 input channels, 512 output channels and 1 groups were specified. Expected Weights count is 512 * 44 * 512 / 1 = 4194304
[10/30/2024-20:51:28] [TRT] [E] 3: 1.cmap_up.0:0:DECONVOLUTION:GPU:kernel weights has count 2097152 but 4194304 was expected
[10/30/2024-20:51:28] [TRT] [E] 4: 1.cmap_up.0:0:DECONVOLUTION:GPU: count of 2097152 weights in kernel, but kernel dimensions (4,4) with 512 input channels, 512 output channels and 1 groups were specified. Expected Weights count is 512 * 44 * 512 / 1 = 4194304
[10/30/2024-20:51:28] [TRT] [E] 3: 1.cmap_up.0:0:DECONVOLUTION:GPU:kernel weights has count 2097152 but 4194304 was expected
[10/30/2024-20:51:28] [TRT] [E] 4: 1.cmap_up.0:0:DECONVOLUTION:GPU: count of 2097152 weights in kernel, but kernel dimensions (4,4) with 512 input channels, 512 output channels and 1 groups were specified. Expected Weights count is 512 * 44 * 512 / 1 = 4194304
[10/30/2024-20:51:28] [TRT] [E] 3: 1.cmap_up.0:0:DECONVOLUTION:GPU:kernel weights has count 2097152 but 4194304 was expected
[10/30/2024-20:51:28] [TRT] [E] 4: 1.cmap_up.0:0:DECONVOLUTION:GPU: count of 2097152 weights in kernel, but kernel dimensions (4,4) with 512 input channels, 512 output channels and 1 groups were specified. Expected Weights count is 512 * 44 * 512 / 1 = 4194304
[10/30/2024-20:51:29] [TRT] [E] 3: 1.cmap_up.0:0:DECONVOLUTION:GPU:kernel weights has count 2097152 but 4194304 was expected
[10/30/2024-20:51:29] [TRT] [E] 4: 1.cmap_up.0:0:DECONVOLUTION:GPU: count of 2097152 weights in kernel, but kernel dimensions (4,4) with 512 input channels, 512 output channels and 1 groups were specified. Expected Weights count is 512 * 4*4 * 512 / 1 = 4194304
Traceback (most recent call last):
File “conversion2.py”, line 29, in
model_trt = torch2trt(model, [data], fp16_mode=True, max_workspace_size=1 << 25)
File “/usr/local/lib/python3.6/dist-packages/torch2trt-0.5.0-py3.6-linux-aarch64.egg/torch2trt/torch2trt.py”, line 643, in torch2trt
outputs = module(*inputs)
File “/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py”, line 889, in _call_impl
result = self.forward(*input, **kwargs)
File “/usr/local/lib/python3.6/dist-packages/torch/nn/modules/container.py”, line 119, in forward
input = module(input)
File “/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py”, line 889, in _call_impl
result = self.forward(*input, **kwargs)
File “/usr/local/lib/python3.6/dist-packages/trt_pose-0.0.1-py3.6-linux-aarch64.egg/trt_pose/models/common.py”, line 76, in forward
return self.cmap_conv(xc * ac), self.paf_conv(xp * ap)
File “/usr/local/lib/python3.6/dist-packages/torch2trt-0.5.0-py3.6-linux-aarch64.egg/torch2trt/torch2trt.py”, line 262, in wrapper
converter"converter"
File “/usr/local/lib/python3.6/dist-packages/torch2trt-0.5.0-py3.6-linux-aarch64.egg/torch2trt/converters/native_converters.py”, line 1496, in convert_mul
input_a_trt, input_b_trt = broadcast_trt_tensors(ctx.network, [input_a_trt, input_b_trt], len(output.shape))
File “/usr/local/lib/python3.6/dist-packages/torch2trt-0.5.0-py3.6-linux-aarch64.egg/torch2trt/torch2trt.py”, line 146, in broadcast_trt_tensors
if len(t.shape) < broadcast_ndim:
ValueError: len() should return >= 0
Best regards!