jetson-inference icon indicating copy to clipboard operation
jetson-inference copied to clipboard

Didn't load class colours...

Open SJavad opened this issue 2 years ago • 2 comments

My model trained for two classes object-1 and object-goal I trained the ssd-mobilenet-v2 in pytorch-ssd repository. When I train a model, I get label.txt file with content BACKGROUND, object-1 and, object-goal But when I try to load the model for predicting, it gives me the error: 20230710_171521.jpg

I don't know why... 🤔 The classes of the model is ok...

SJavad avatar Jul 10 '23 18:07 SJavad

my labels.txt file is:

BACKGROUND
object-1
object-goal

and the console output:

jetson.utils -- compiled without NumPy array conversion support (warning)
jetson.utils -- if you wish to have support for converting NumPy arrays,
jetson.utils -- first run 'sudo apt-get install python-numpy python3-numpy'
--Finding Camera Instance
--Set Grab Continousely
--Convert Pixel Format
jetson.inference -- detectNet loading custom model '1080F.onnx'

detectNet -- loading detection network model from:
          -- prototxt     NULL
          -- model        1080F.onnx
          -- input_blob   'input_0'
          -- output_cvg   'scores'
          -- output_bbox  'boxes'
          -- mean_pixel   0.000000
          -- class_labels ./labels.txt
          -- class_colors NULL
          -- threshold    0.500000
          -- batch_size   1

[TRT]    TensorRT version 8.2.1
[TRT]    loading NVIDIA plugins...
[TRT]    Registered plugin creator - ::GridAnchor_TRT version 1
[TRT]    Registered plugin creator - ::GridAnchorRect_TRT version 1
[TRT]    Registered plugin creator - ::NMS_TRT version 1
[TRT]    Registered plugin creator - ::Reorg_TRT version 1
[TRT]    Registered plugin creator - ::Region_TRT version 1
[TRT]    Registered plugin creator - ::Clip_TRT version 1
[TRT]    Registered plugin creator - ::LReLU_TRT version 1
[TRT]    Registered plugin creator - ::PriorBox_TRT version 1
[TRT]    Registered plugin creator - ::Normalize_TRT version 1
[TRT]    Registered plugin creator - ::ScatterND version 1
[TRT]    Registered plugin creator - ::RPROI_TRT version 1
[TRT]    Registered plugin creator - ::BatchedNMS_TRT version 1
[TRT]    Registered plugin creator - ::BatchedNMSDynamic_TRT version 1
[TRT]    Could not register plugin creator -  ::FlattenConcat_TRT version 1
[TRT]    Registered plugin creator - ::CropAndResize version 1
[TRT]    Registered plugin creator - ::DetectionLayer_TRT version 1
[TRT]    Registered plugin creator - ::EfficientNMS_TRT version 1
[TRT]    Registered plugin creator - ::EfficientNMS_ONNX_TRT version 1
[TRT]    Registered plugin creator - ::EfficientNMS_TFTRT_TRT version 1
[TRT]    Registered plugin creator - ::Proposal version 1
[TRT]    Registered plugin creator - ::ProposalLayer_TRT version 1
[TRT]    Registered plugin creator - ::PyramidROIAlign_TRT version 1
[TRT]    Registered plugin creator - ::ResizeNearest_TRT version 1
[TRT]    Registered plugin creator - ::Split version 1
[TRT]    Registered plugin creator - ::SpecialSlice_TRT version 1
[TRT]    Registered plugin creator - ::InstanceNormalization_TRT version 1
[TRT]    detected model format - ONNX  (extension '.onnx')
[TRT]    desired precision specified for GPU: FASTEST
[TRT]    requested fasted precision for device GPU without providing valid calibrator, disabling INT8
[TRT]    [MemUsageChange] Init CUDA: CPU +225, GPU +0, now: CPU 330, GPU 3242 (MiB)
[TRT]    [MemUsageSnapshot] Begin constructing builder kernel library: CPU 330 MiB, GPU 3271 MiB
[TRT]    [MemUsageSnapshot] End constructing builder kernel library: CPU 359 MiB, GPU 3303 MiB
[TRT]    native precisions detected for GPU:  FP32, FP16
[TRT]    selecting fastest native precision for GPU:  FP16
[TRT]    found engine cache file 1080F.onnx.1.1.8201.GPU.FP16.engine
[TRT]    found model checksum 1080F.onnx.sha256sum
[TRT]    echo "$(cat 1080F.onnx.sha256sum) 1080F.onnx" | sha256sum --check --status
[TRT]    model matched checksum 1080F.onnx.sha256sum
[TRT]    loading network plan from engine cache... 1080F.onnx.1.1.8201.GPU.FP16.engine
[TRT]    device GPU, loaded 1080F.onnx
[TRT]    [MemUsageChange] Init CUDA: CPU +0, GPU +0, now: CPU 347, GPU 3362 (MiB)
[TRT]    Loaded engine size: 16 MiB
[TRT]    Using cublas as a tactic source
[TRT]    [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +157, GPU +37, now: CPU 505, GPU 3417 (MiB)
[TRT]    Using cuDNN as a tactic source
[TRT]    [MemUsageChange] Init cuDNN: CPU +241, GPU +17, now: CPU 746, GPU 3434 (MiB)
[TRT]    Deserialization required 4799981 microseconds.
[TRT]    [MemUsageChange] TensorRT-managed allocation in engine deserialization: CPU +0, GPU +16, now: CPU 0, GPU 16 (MiB)
[TRT]    Using cublas as a tactic source
[TRT]    [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +0, GPU +0, now: CPU 746, GPU 3434 (MiB)
[TRT]    Using cuDNN as a tactic source
[TRT]    [MemUsageChange] Init cuDNN: CPU +0, GPU +0, now: CPU 746, GPU 3434 (MiB)
[TRT]    Total per-runner device persistent memory is 15163904
[TRT]    Total per-runner host persistent memory is 70080
[TRT]    Allocated activation device memory of size 8871424
[TRT]    [MemUsageChange] TensorRT-managed allocation in IExecutionContext creation: CPU +0, GPU +23, now: CPU 0, GPU 39 (MiB)
[TRT]    
[TRT]    CUDA engine context initialized on device GPU:
[TRT]       -- layers       109
[TRT]       -- maxBatchSize 1
[TRT]       -- deviceMemory 8871424
[TRT]       -- bindings     3
[TRT]       binding 0
                -- index   0
                -- name    'input_0'
                -- type    FP32
                -- in/out  INPUT
                -- # dims  4
                -- dim #0  1
                -- dim #1  3
                -- dim #2  300
                -- dim #3  300
[TRT]       binding 1
                -- index   1
                -- name    'scores'
                -- type    FP32
                -- in/out  OUTPUT
                -- # dims  3
                -- dim #0  1
                -- dim #1  3000
                -- dim #2  3
[TRT]       binding 2
                -- index   2
                -- name    'boxes'
                -- type    FP32
                -- in/out  OUTPUT
                -- # dims  3
                -- dim #0  1
                -- dim #1  3000
                -- dim #2  4
[TRT]    
[TRT]    binding to input 0 input_0  binding index:  0
[TRT]    binding to input 0 input_0  dims (b=1 c=3 h=300 w=300) size=1080000
[TRT]    binding to output 0 scores  binding index:  1
[TRT]    binding to output 0 scores  dims (b=1 c=3000 h=3 w=1) size=36000
[TRT]    binding to output 1 boxes  binding index:  2
[TRT]    binding to output 1 boxes  dims (b=1 c=3000 h=4 w=1) size=48000
[TRT]    
[TRT]    device GPU, 1080F.onnx initialized.
[TRT]    detectNet -- number of object classes: 3
[TRT]    detectNet -- maximum bounding boxes:   3000
[TRT]    loaded 3 class labels
[TRT]    detectNet -- number of object classes:  3
[TRT]    loaded 0 class colors
[TRT]    didn't load expected number of class colors  (0 of 3)
[TRT]    filling in remaining 3 class colors with default colors
Segmentation fault (core dumped)

I don't know what is the problem... and this my code:

'''
A simple Program for grabing video from basler camera and converting it to opencv img.
Tested on Basler acA1300-200uc (USB3, linux 64bit , python 3.5)

'''
from pypylon import pylon
import cv2,time
import torch
import yaml
import sys
import argparse

from jetson_inference import detectNet
from jetson_utils import videoSource, videoOutput, Log
from jetson_utils import cudaImage, cudaMemcpy

# parse the command line
parser = argparse.ArgumentParser(description="Locate objects in a live camera stream using an object detection DNN.", 
                                 formatter_class=argparse.RawTextHelpFormatter, 
                                 epilog=detectNet.Usage() + videoSource.Usage() + videoOutput.Usage() + Log.Usage())

parser.add_argument("input", type=str, default="", nargs='?', help="URI of the input stream")
parser.add_argument("output", type=str, default="", nargs='?', help="URI of the output stream")
parser.add_argument("--network", type=str, default="ssd-mobilenet-v2", help="pre-trained model to load (see below for options)")
parser.add_argument("--overlay", type=str, default="box,labels,conf", help="detection overlay flags (e.g. --overlay=box,labels,conf)\nvalid combinations are:  'box', 'labels', 'conf', 'none'")
parser.add_argument("--threshold", type=float, default=0.5, help="minimum detection threshold to use") 

try:
	args = parser.parse_known_args()[0]
except:
	print("")
	parser.print_help()
	sys.exit(0)

# conecting to the first available camera
print("--Finding Camera Instance")
camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())

# Grabing Continusely (video) with minimal delay
print("--Set Grab Continousely")
camera.StartGrabbing(pylon.GrabStrategy_LatestImageOnly) 
converter = pylon.ImageFormatConverter()

# converting to opencv bgr format
print("--Convert Pixel Format")
converter.OutputPixelFormat = pylon.PixelType_BGR8packed
converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned


model = detectNet(model="1080F.onnx",labels="./labels.txt",
    input_blob="input_0",output_cvg="scores" , output_bbox="boxes",
    threshold=args.threshold)

while camera.IsGrabbing():
    grabResult = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)

    if grabResult.GrabSucceeded():
        # Access the image data
        image1 = converter.Convert(grabResult)
        image = image1.GetArray()
        image_rsz = cv2.resize(image,(640,640))
        image = cudaImage(width=640,height=640,like=image_rsz,format="rgb8")
        image_final = cudaMemcpy(image , image_rsz)
        results = model.Detect(image_final , overlay=args.overlay)
        for res in results:
            print(res)
        cv2.namedWindow('title', cv2.WINDOW_NORMAL)
        cv2.imshow('title', image_final)
        k = cv2.waitKey(1)
        if k == 27:
            break
    grabResult.Release()
    
# Releasing the resource    
camera.StopGrabbing()

cv2.destroyAllWindows()

@dusty-nv can you help me dusty ? :(

SJavad avatar Jul 11 '23 10:07 SJavad

@dusty-nv I noticed something... the model load successfully and when trying to create cuda image... it give me a error segmentation fault (core dumped) this is the problem... I don't know why Am I convert the image to cudaImage correctly ?

SJavad avatar Jul 11 '23 11:07 SJavad