Как на Linux запустить скрипт через дискретную видеокарту Nvidia?

Рейтинг: 0Ответов: 0Опубликовано: 03.08.2023

Я пользуюсь библиотекой "Face-recognition", с установленным параметром "cnn"

locations = face_recognition.face_locations(frame, model='cnn')

Как мне сделать так, чтобы работа этого скрипта выполнялась через дискретную видеокарту, а не через встроенную?. Запуск через

optirun python main.py

и

primusrun python main.py

не даёт никаких результатов, при проверке использования я получаю только

nvidia-smi
...

|=======================================================================================|
|    0   N/A  N/A      7626      G   /usr/lib/Xorg                                 5MiB |
+---------------------------------------------------------------------------------------+

Соответсвенно сам скрипт не использует дискретную видеокарту

Я в линуксе слаб, но хочу познать эту прекрасную ОС, так что буду очень благодарен вашим ответам.

Скрипт:

def detected():

# data = pickle.loads(open('user_1_encodings.pickle', 'rb').read())

cams = cv2.VideoCapture(0)
not_identify = []

while True:
    ret, frame = cams.read()

    locations = face_recognition.face_locations(frame, model='cnn')
    encodings = face_recognition.face_encodings(frame, locations)

    for face_encoding, face_location in zip(encodings, locations):
        # user_encodings = user_data['encodings']
        # result = face_recognition.compare_faces(user_encodings, face_encoding)
        result = False
        green = [0, 255, 0]
        blue = [255, 0, 0]
        red = [0, 0, 255]

        if any(result):
            print(result)
            match = user_data['name']
            left_top = (face_location[3], face_location[0])
            right_bottom = (face_location[1], face_location[2])
            cv2.rectangle(frame, left_top, right_bottom, green, 2)

            text_x = face_location[3]
            text_y = face_location[0] - 10  
            font_scale = 0.5
            font_thickness = 1
            font_face = cv2.FONT_HERSHEY_COMPLEX_SMALL
            text_size, _ = cv2.getTextSize(match, font_face, font_scale, font_thickness)
            text_width, text_height = text_size


            rect_left_top = (text_x-1, text_y+5)
            rect_right_bottom = (text_x + text_width+5, text_y - text_height-5)
            cv2.rectangle(frame, rect_left_top, rect_right_bottom, (255, 255, 255), -1)


            cv2.putText(frame, match, (text_x, text_y), font_face, font_scale, (255, 0, 0), font_thickness)

        else:
            print('NOT OK')
            print(face_location)
            match = 'Unknown'

            top, right, bottom, left = face_location
            face = frame[top:bottom, left:right]
            pil_image = Image.fromarray(face)

            print(pil_image)
            not_identify.append(pil_image)
            print(not_identify)
            if len(not_identify) > 3:
                #
                if result is False:
                    not_identify = []
                else:
                    data = result
                    not_identify = []


            left_top = face_location[3], face_location[0]
            right_bottom = (face_location[1], face_location[2])

            cv2.rectangle(frame, left_top, right_bottom, red, 2)


        text_x = face_location[3]
        text_y = face_location[0] - 10  

        font_scale = 0.5
        font_thickness = 1
        font_face = cv2.FONT_HERSHEY_COMPLEX_SMALL
        text_size, _ = cv2.getTextSize(match, font_face, font_scale, font_thickness)
        text_width, text_height = text_size

        rect_left_top = (text_x-1, text_y+5)
        rect_right_bottom = (text_x + text_width+5, text_y - text_height-5)
        cv2.rectangle(frame, rect_left_top, rect_right_bottom, (255, 255, 255), -1)

        cv2.putText(frame, match, (text_x, text_y), font_face, font_scale, (255, 0, 0), font_thickness)

cv2.imshow('scan', frame)
k = cv2.waitKey(20)
if k == ord('q'):
    break

Бенчмарки все работают хорошо, через optirun запускаются от дискретной видеокарты, а значит, драйвера стоят и работают.

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      6351      G   /usr/lib/Xorg                                24MiB |
|    0   N/A  N/A      6355      G   glxspheres64                                  2MiB |
+---------------------------------------------------------------------------------------+

Ответы

Ответов пока нет.