pytorch / vision

Datasets, Transforms and Models specific to Computer Vision
https://pytorch.org/vision
BSD 3-Clause "New" or "Revised" License
16.31k stars 6.97k forks source link

Unable to load keypointrcnn_resnet50_fpn on C++ #7697

Open amirtronix opened 1 year ago

amirtronix commented 1 year ago

🐛 Describe the bug

I went through Pytorch tutorial for loading models on C++, and it works fine for resnet18 model, but once I save the fasterrcnn_resnet50_fpn with the same instructions and try to load it on C++, I get this error:

terminate called after throwing an instance of ‘torch::jit::ErrorReport’
what():
Unknown type name ‘NoneType’:
Serialized File “code/**torch**/torchvision/models/detection/transform.py”, line 11
image_std : List[float]
size_divisible : int
fixed_size : NoneType
~~~~~~~~ <— HERE
def forward(self: **torch**.torchvision.models.detection.transform.GeneralizedRCNNTransform,
images: List[Tensor],

Aborted (core dumped)

I’m going to share the Python, C++ and CMake files here for more information:

Python:

import torch

import torchvision

model = torchvision.models.detection.fasterrcnn_resnet50_fpn()

# An example input you would normally provide to your model's forward() method.

example = torch.rand(1, 3, 224, 224)

# Use torch.jit.trace to generate a torch.jit.ScriptModule via tracing.

traced_script_module = torch.jit.script(model, example)

traced_script_module.save("rcnn_model.pt")

C++:

#include <iostream>
#include <torch/torch.h>
#include <torch/script.h>

int main()
{

    torch::jit::script::Module model;

    try 
    {
    model = torch::jit::load("/home/bluesky/Documents/Codes/AI/Keypoint_RCNN/rcnn_model.pt");
    } 

    catch (const c10::Error& e) 
    {
        std::cerr << "Error loading the model: " << e.msg() << std::endl;
    }
}

CMake:

cmake_minimum_required(VERSION 3.2)

project(torchtest)

set(CMAKE_PREFIX_PATH /home/bluesky/Downloads/libtorch-cxx11-abi-shared-with-deps-1.8.0+cu112/libtorch)
find_package(Torch REQUIRED)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} "${TORCH_LIBRARIES}")

set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)

Versions

Collecting environment information... PyTorch version: 1.10.1+cu111 Is debug build: False CUDA used to build PyTorch: 11.1 ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.3 LTS (x86_64) GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 Clang version: Could not collect CMake version: version 3.26.3 Libc version: glibc-2.31

Python version: 3.8.10 (default, May 26 2023, 14:05:08) [GCC 9.4.0] (64-bit runtime) Python platform: Linux-5.15.0-73-generic-x86_64-with-glibc2.29 Is CUDA available: True CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3090 Nvidia driver version: 470.182.03 cuDNN version: Probably one of the following: /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn.so.8.9.2 /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.9.2 /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.9.2 /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.9.2 /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.9.2 /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.9.2 /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.9.2 HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian Address sizes: 46 bits physical, 48 bits virtual CPU(s): 28 On-line CPU(s) list: 0-27 Thread(s) per core: 2 Core(s) per socket: 14 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 85 Model name: Intel(R) Core(TM) i9-10940X CPU @ 3.30GHz Stepping: 7 CPU MHz: 3300.000 CPU max MHz: 4800.0000 CPU min MHz: 1200.0000 BogoMIPS: 6599.98 Virtualization: VT-x L1d cache: 448 KiB L1i cache: 448 KiB L2 cache: 14 MiB L3 cache: 19.3 MiB NUMA node0 CPU(s): 0-27 Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Retbleed: Mitigation; Enhanced IBRS Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Mitigation; TSX disabled Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512_vnni md_clear flush_l1d arch_capabilities

Versions of relevant libraries: [pip3] mypy-extensions==0.4.3 [pip3] numpy==1.22.2 [pip3] torch==1.10.1+cu111 [pip3] torch-summary==1.4.5 [pip3] torchaudio==0.10.1+cu111 [pip3] torchvision==0.11.2+cu111 [pip3] torchviz==0.0.2 [pip3] triton==2.0.0 [conda] Could not collect

haarisr commented 1 year ago

You might need to set the fixed size parameter when training the model. I remember reading it in the docs of keypoint rcnn that the c++ version only works with fixed size images