gpt4 book ai didi

python - 如何解决 "RuntimeError: CUDA error: invalid device ordinal"?

转载 作者:行者123 更新时间:2023-12-02 17:16:49 25 4
gpt4 key购买 nike

我正在尝试运行此代码。我不知道它有什么问题,但是这段代码没有运行。我不知道如何解决这个问题。

import cv2
from facial_emotion_recognition import EmotionRecognition

emotion_detector = EmotionRecognition(device='gpu', gpu_id=1)
camera = cv2.VideoCapture(0)

while True:
image = camera.read()[1]
image = emotion_detector.recognise_emotion(image, return_type='BGR')
cv2.imshow('Camera', image)

key = cv2.waitKey(1)
if key == 27:
break

camera.release()
cv2.destroyAllWindows()
但我收到此错误:
Traceback (most recent call last):
File "/home/fahim/Documents/Python_projects/Python tutorials/pantech AI Master/Computer_Vision/Day 8 Face emotion recognition/emotion.py", line 4, in <module>
emotion_detector = EmotionRecognition(device='gpu', gpu_id=1)
File "/home/fahim/anaconda3/envs/Computer_Vision/lib/python3.7/site-packages/facial_emotion_recognition/facial_emotion_recognition.py", line 25, in __init__
self.network = NetworkV2(in_c=1, nl=32, out_f=7).to(self.device)
File "/home/fahim/anaconda3/envs/Computer_Vision/lib/python3.7/site-packages/torch/nn/modules/module.py", line 607, in to
return self._apply(convert)
File "/home/fahim/anaconda3/envs/Computer_Vision/lib/python3.7/site-packages/torch/nn/modules/module.py", line 354, in _apply
module._apply(fn)
File "/home/fahim/anaconda3/envs/Computer_Vision/lib/python3.7/site-packages/torch/nn/modules/module.py", line 354, in _apply
module._apply(fn)
File "/home/fahim/anaconda3/envs/Computer_Vision/lib/python3.7/site-packages/torch/nn/modules/module.py", line 376, in _apply
param_applied = fn(param)
File "/home/fahim/anaconda3/envs/Computer_Vision/lib/python3.7/site-packages/torch/nn/modules/module.py", line 605, in convert
return t.to(device, dtype if t.is_floating_point() else None, non_blocking)
RuntimeError: CUDA error: invalid device ordinal

Process finished with exit code 1
这是我的电脑配置:
GPU:NVIDIA GeForce MX130
CPU:Intel i5-10210U (8) @ 4.200GHz
请帮我解决这个问题。

最佳答案

尝试改变:

emotion_detector = EmotionRecognition(device='gpu', gpu_id=1)
到:
emotion_detector = EmotionRecognition(device='gpu', gpu_id=0)
gpu_id仅当检测到不止一个 GPU 时才有效,您似乎只有一个 GPU,因此它会引发错误,因为您告诉函数获取 GPU 2(因为我们从 0 开始计数)。

关于python - 如何解决 "RuntimeError: CUDA error: invalid device ordinal"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64334033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com