spmallick / learnopencv

Learn OpenCV : C++ and Python Examples

Home Page:https://www.learnopencv.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PyTorch-ONNX-TensorRT-CPP wrong predictions

pazikk opened this issue · comments

commented

Hello, I am trying to work with PyTorch-ONNX-TensorRT-CPP tutorial.
I am working on jetson orin with TensorRT 8.4 and cuda 11.4.

While trying to compile project I get 2 error:
error: looser throw specifier for ‘virtual void Logger::log(nvinfer1::ILogger::Severity, const char*)’
21 | void log(Severity severity, const char* msg) override {
and
error: ‘class nvinfer1::IBuilder’ has no member named ‘createNetwork’; did you mean ‘createNetworkV2’?
144 | TRTUniquePtrnvinfer1::INetworkDefinition network{builder->createNetwork()};

First error I fixed by adding "noexcept" before "override" in 21 line:
void log(Severity severity, const char* msg) noexcept override {

Second error I fixed by changing "createNetwork()" to createNetworkV2(1U) in line 144:
TRTUniquePtrnvinfer1::INetworkDefinition network{builder->createNetworkV2(1U)};

After changes, projects compiles successfully.

When I run pytorch_model.py I get correct predictions:
class: cup , confidence: 92.43268585205078 %, index: 968
class: espresso , confidence: 6.134716033935547 %, index: 967
class: coffee mug , confidence: 0.7281741499900818 %, index: 504

However, when I run ./trt_sample resnet50.onnx turkish_coffee.jpg I get:
class: web site, website, internet site, site | confidence: 5.82525% | index: 916
class: cleaver, meat cleaver, chopper | confidence: 3.85025% | index: 499
class: nematode, nematode worm, roundworm | confidence: 3.3714% | index: 111
class: envelope | confidence: 3.0221% | index: 549
class: hatchet | confidence: 1.46425% | index: 596
class: nail | confidence: 1.38092% | index: 677
class: whistle | confidence: 1.24756% | index: 902
class: can opener, tin opener | confidence: 1.18116% | index: 473
class: hook, claw | confidence: 1.14482% | index: 600
class: guillotine | confidence: 0.986898% | index: 583
class: letter opener, paper knife, paperknife | confidence: 0.936203% | index: 623
class: theater curtain, theatre curtain | confidence: 0.92349% | index: 854
class: panpipe, pandean pipe, syrinx | confidence: 0.850759% | index: 699
class: revolver, six-gun, six-shooter | confidence: 0.827811% | index: 763
class: safety pin | confidence: 0.822975% | index: 772
class: plunger, plumber's helper | confidence: 0.783756% | index: 731
class: scabbard | confidence: 0.768597% | index: 777
class: hair slide | confidence: 0.730541% | index: 584
class: table lamp | confidence: 0.712225% | index: 846
class: bulletproof vest | confidence: 0.708064% | index: 465
class: assault rifle, assault gun | confidence: 0.663867% | index: 413
class: book jacket, dust cover, dust jacket, dust wrapper | confidence: 0.662572% | index: 921
class: stopwatch, stop watch | confidence: 0.658701% | index: 826
class: abaya | confidence: 0.648489% | index: 399
class: binder, ring-binder | confidence: 0.634705% | index: 446
class: chain | confidence: 0.633466% | index: 488
class: dishwasher, dish washer, dishwashing machine | confidence: 0.612779% | index: 534
class: rule, ruler | confidence: 0.61039% | index: 769
class: fire screen, fireguard | confidence: 0.603278% | index: 556
class: lipstick, lip rouge | confidence: 0.595087% | index: 629
class: screw | confidence: 0.592767% | index: 783
class: ocarina, sweet potato | confidence: 0.574529% | index: 684
class: mousetrap | confidence: 0.573408% | index: 674
class: muzzle | confidence: 0.567836% | index: 676
class: magnetic compass | confidence: 0.53972% | index: 635
class: hammer | confidence: 0.526189% | index: 587
class: maraca | confidence: 0.509005% | index: 641
class: spatula | confidence: 0.500135% | index: 813

Help for help in advance.