Skip to content

error: (-217:Gpu API call) invalid device function in function 'make_policy' #20778

@zijian98

Description

@zijian98
System information (version)
  • OpenCV => 4.5.3-dev
  • Operating System / Platform => Ubuntu 18.04 / Jetson AGX Xavier
  • Compiler => python3
Detailed description

I have compiled opencv with cuda and tried to run an object detection program but it returned an error. Cuda 10.2 is installed. May I know how do I fix this?

Thanks

Steps to reproduce

This is the code that I am trying to run with my camera:

import cv2
import numpy as np
import matplotlib.pyplot as plt

config_file = '/home/user/Desktop/Object_Detection/ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt'
frozen_model = '/home/user/Desktop/Object_Detection/frozen_inference_graph.pb'

model = cv2.dnn_DetectionModel(frozen_model, config_file)

model.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
model.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)

classlabels = []
file_name = '/home/user/Desktop/Object_Detection/Labels.txt'
with open(file_name, 'rt') as fpt:
    classLabels = fpt.read().rstrip('\n').split('\n')
    

model.setInputSize(320,320)
model.setInputScale(1.0/127.5)
model.setInputMean((127.5,127.5,127.5))
model.setInputSwapRB(True)


#ClassIndex, confidence, bbox = model.detect(img.confThreshold = 0.5)

# set font
font_scale = 3
font = cv2.FONT_HERSHEY_PLAIN

# initiate video
cv2.startWindowThread()
cap = cv2.VideoCapture(2)

# filter class objects
filt = np.zeros(80)
filt[0] = 1;

while True:
    ret, frame = cap.read()
    
    ClassIndex, confidence, bbox = model.detect(frame, confThreshold = 0.55)
  
    #print(ClassIndex)
    if (len(ClassIndex)!=0):
        for ClassInd, conf, boxes in zip(ClassIndex.flatten(), confidence.flatten(), bbox):
            if (ClassInd==1):
                cv2.rectangle(frame, boxes, (255,0,0), 2)
                cv2.putText(frame, classLabels[ClassInd-1], (boxes[0]+10, boxes[1]+40), font, fontScale = font_scale, color = (0,255,0), thickness = 3)
                
    
    cv2.imshow('Detected objects', frame)
    
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
        
cap.release()
cv2.destroyAllWindows()

The error:

Traceback (most recent call last):
  File "run_video.py", line 42, in <module>
    ClassIndex, confidence, bbox = model.detect(frame, confThreshold = 0.55)
cv2.error: OpenCV(4.5.3-dev) /home/user/opencv/modules/dnn/src/cuda/execution.hpp:52: error: (-217:Gpu API call) invalid device function in function 'make_policy'

and build information for cuda:

NVIDIA CUDA:                   YES (ver 10.2, CUFFT CUBLAS FAST_MATH)
    NVIDIA GPU arch:             70
    NVIDIA PTX archs:

  cuDNN:                         YES (ver 8.0.0)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions