새소식

기타

[파이썬 / VSCode] AssertionError: Torch not compiled with CUDA enabled

  • -

Yolo v3 모델을 통해 이미지 분류를 하려던 중 해당 에러가 발생하여 진행하지 못했다.

 

 

문제의 에러 블럭

command : python3 detect_1231.py --cfg cfg/yolov3-spp-403cls.cfg --names data/403food.names --weights weights/best_403food_e200b150v2.pt
===============================================================
Traceback (most recent call last):
  File "C:\Users\dongs\OneDrive\문서\2023-2th\AI_DeepLearning\03.AI알고리즘 소스코드\음식분류\yolov3\detect_1231.py", line 305, in <module>
    printOsInfo()
  File "C:\Users\dongs\OneDrive\문서\2023-2th\AI_DeepLearning\03.AI알고리즘 소스코드\음식분류\yolov3\detect_1231.py", line 300, in printOsInfo
    print('GPU                  :\t', torch.cuda.get_device_name(0))
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dongs\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch\cuda\__init__.py", line 419, in get_device_name
    return get_device_properties(device).name
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dongs\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch\cuda\__init__.py", line 449, in get_device_properties
    _lazy_init()  # will define _get_device_properties
    ^^^^^^^^^^^^
  File "C:\Users\dongs\AppData\Local\Programs\Python\Python311\Lib\site-packages\torch\cuda\__init__.py", line 289, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

 

 

 

여러 사이트를 돌아다닌 결과 GPU사용이 활성화 되지 않거나, 내부 라이브러리 버전이 호환되지 않아 그렇다는 것으로 문제를 인식했다.

 

 

#Yolo v5 모델에서는 작동을 잘 했기 때문에,

뭐 쿠다에 GPU 활성번호로 입력하면 된다는데, 그런건 모르겠어서 호환 문제로 해결해 보기로 했다.

 

 

우선 관련 기능 삭제

pip uninstall torch torchvision torchaudio

 

 

 

https://pytorch.org/get-started/previous-versions/#wheel

 

위 사이트에 가서 설치 링크를 받아온다.

pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cu118

 

 

확실히 위에 버전과 밑에 호환되는 버전이 다른 것 같기는 하다.

 

 

결과[인식 잘 된다]

 

 

 

 

UnicodeDecodeError: 'cp949' codec can't decode byte 0xec in position 93: illegal multibyte sequence

파일 읽어들이는 인코딩 형식 문제

Traceback (most recent call last):
  File "C:\Users\dongs\OneDrive\문서\2023-2th\AI_DeepLearning\03.AI알고리즘 소스코드\음식분류\yolov3\detect_1231.py", line 326, in <module>
    detect()
  File "C:\Users\dongs\OneDrive\문서\2023-2th\AI_DeepLearning\03.AI알고리즘 소스코드\음식분류\yolov3\detect_1231.py", line 53, in detect
    model = Darknet(opt.cfg, imgsz)
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dongs\OneDrive\문서\2023-2th\AI_DeepLearning\03.AI알고리즘 소스코드\음식분류\yolov3\models.py", line 231, in __init__
    self.module_defs = parse_model_cfg(cfg)
                       ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dongs\OneDrive\문서\2023-2th\AI_DeepLearning\03.AI알고리즘 소스코드\음식분류\yolov3\utils\parse_config.py", line 14, in parse_model_cfg
    lines = f.read().split('\n')
            ^^^^^^^^
UnicodeDecodeError: 'cp949' codec can't decode byte 0xec in position 93: illegal multibyte sequence

 

변경 후 잘됨

Contents

아핫

땡큐하다