from palette import colorful_colors

에러해결경험-Ubuntu, CUDA, cudnn, tensorflow,Raspberrypi trouble shoot 본문

연구활동/기타 TIP

에러해결경험-Ubuntu, CUDA, cudnn, tensorflow,Raspberrypi trouble shoot

colorful-palette 2023. 1. 21. 21:18

Ubuntu 환경에서 CUDA, cudnn, tensorflow등 환경 설정시 만난 에러 해결경험을 공유하겠습니다

*추후 계속해서 업데이트 예정

<에러해결경험 목차>

1. Ubuntu Error

2. Ubuntu Error - terminal error

3. CUDA, cudnn Error

4. Python Error

5. Tensorflow Error

6. Pytorch Error

7. Raspberrypi error

8. 기타 에러

 

 

1. Ubuntu error:

우분투 네트워크 아이콘이 안 보이는 경우

Sol) 이더넷(랜선) 연결시: 랜선이 연결되어있지 않다면 아이콘이 안 뜰 수 있다. 랜선연결 후 재부팅해보자

Sol2) 랜카드가 지워졌을 경우: 첨부파일의 파일을 실행해주면 된다.

home에서 다운받고 ./autorun.sh 실행

우분투 환경설정 아이콘이 안 들어가지는 경우(setting이 안 보이는 경우)

Sol) 터미널에서 sudo apt-get intall gnome-control-center 입력

reference: https://nate9389.tistory.com/2155

sudo apt update error: apt update가 안 될 경우

Sol) reference: https://cryptosalamander.tistory.com/87

그래도 안 된다면 pc 밀어버리기…

파일을 옮기고 나서 (예시: ~/Download 에서 ~/ws로 옮겼을때) 파일 실행 안됨 등 나도 모르는 에러가 나는 경우

파일을 옮길 땐 GUI환경이 아니라 terminal 창에서 mv로 옮겨야 한다!!

Sol) ctrl + alt + t 로 터미널을 열고→ 해당 파일이 있는 위치로 이동하기 → mv (옮기고 싶은 파일 이름) (옮기고 싶은 파일 위치)

ex) mv palette.deb ~/ws

참고: 윈도우에서도 가끔 ctrl + x / ctrl + v가 아니라, cmd창에서 move 명령어로 옮겨야 파일이 실행되는 경우가 있다. 압축파일을 옮기고 풀었는데 실행파일이 제대로 실행이 안 되거나,,, 등등 이상한 오류에 이렇게 이동하면 해결된다.

리눅스단에서 좋은 습관: 파일 관리는 nautilus에서 마우스로 하는게 아니라Terminal 환경에서 키보드로!!, 파일 이름은 띄어쓰기 없이!!🤓

2. Ubuntu error - Terminal error:

터미널 주의사항(절대 사용하면 안 되는 명령어):

1. sudo apt upgrade -> 나의 개발환경과 완전히 달라질 수 있다. 잘못하면 pc밀어야한다.

2. sudo autoremove -> 말 그대로 패키지 자동으로 지워짐. 꼭 필요한 파일도 자동으로 지워질 수 있다.

 

Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend)

Sol) 재부팅하기

reference: https://stricky.tistory.com/181

명령어 아무것도 안 먹힐때(하다못해 ls 조차도):

Sol) 터미널에 $export PATH=%PATH:/bin:/usr/local/bin:/usr/bin 입력

사용하면 임시로 명령어 쓸 수 있음. 아마 .bashrc등 환경설정에서 잘못 만졌을 확률이 높다. 환경설정에서 내가 실수한 부분 고치기!!! (.bashrc에서 잘못된것 삭제하고 다시 source ~/.bashrc하기)

그래도 안 된다면 pc 밀어버리기…

ModuleNotFoundError: No module named 'apt_pkg’

sudo apt update하다 이런 오류가 떴음.

Sol) python3-apt 삭제 후 재설치해서 해결

reference: https://sncap.tistory.com/1115

 

sudo apt update 에서 다음과 비슷한  i386 error 가 뜰때:

Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'https://packages.microsoft.com/ubuntu/18.04/prod bionic InRelease' doesn't support architecture 'i386'

 

Google이 64비트 시스템에서 apt를 업데이트할 때, 오류를 트리거하는 Linux에서 32비트 Chrome에 대한 지원을 중단해서 생긴 오류.

Sol) repo 파일에서 위 에러메시지와 관련된 줄을 찾아서 [arch=amd64]를 적용하여 64비트로 제한한다.
sudo gedit /etc/apt/sources.list
deb [arch=amd64] https://packages.microsoft.com/ubuntu/18.04/prod focal main

 다음 source /etc/apt/sources.list 해주고  sudo apt update 해주기

 

 


 

3. CUDA, cudnn error:

ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory

bashrc파일에 path를 설정해주지 않아서 생긴 문제다. (그래서 cuda10.0의 파일을 불러올 수 없다고 뜬 것이다)

Sol) gedit ~/.bashrc로 들어간 후

export PATH=$PATH:/usr/local/cuda-10.0/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.0/lib64 

입력하기

(숫자는 자신의 CUDA버전에 맞추기!!! 중요)


4. Python error:

Non-ASCII character '\xed' in file

한글등 유니코드가 있을 때 생기는 에러다.

Sol) 파이썬 코드 첫 줄에 # -- coding: utf8 -- 적기

 


5. Tensorflow error:

ERROR: Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

텐서플로우 설치중 생긴 오류, 텐서플로우랑 파이썬 라이브러리들이랑 버전 안 맞아서 생긴 오류거나 wrapt 파일과 충돌이 발생해서 설치가 안되는 오류인 것 같다.

Sol) 터미널에서 pip install wrapt --upgrade --ignore-installed 한 다음 pip install tensorflow 하니깐 해결됐음. (그 전에 locate wrapt로 wrapt 관련 파일들 따로 옮겨뒀었는데 계속 존재하는걸로 떴었고, 설치가 계속 안 됐었다.)

reference:https://stackoverflow.com/questions/59232286/error-cannot-uninstall-wrapt-when-installing-tensorflow-gpu-1-14 https://whatslikewant.tistory.com/8

twisted 18.7.0 requires PyHamcrest>=1.9.0, which is not installed.

pip 업그레이드하다가 생긴 오류.

Sol) pyhamcrest 최신으로 바꿔주기.

referecne: https://blog.katastros.com/a?ID=01650-8962c8fd-0885-42f5-96de-bcd539375002


 

6. Pytorch error:

학습 시 튕기면서 안 될 때

Sol) 배치 사이즈 줄이면 해결됨

RuntimeError: CUDA out of memory

배치 사이즈를 줄이거나 아래의 코드로 캐시 지우기

import torch, gc
gc.collect()
torch.cuda.empty_cache()

 

그래도 안 되면 다음 레퍼런스 참고

https://discuss.pytorch.kr/t/cuda-out-of-memory/216

 

 

 

Dimension out of range (expected to be in range of [-1, 0], but got 1

텐서의 크기나 모양이 잘못되었을 때 발생한다. 범위를 벗어난 차원에 접근하려고 시도했음을 나타낸다.

ex) 1차원텐서가 두 번째 차원에 접근할려고 시도하는 경우

 

 

AttributeError: 'collections.OrderedDict' object has no attribute 'eval'

reference:https://stackoverflow.com/questions/49941426/attributeerror-collections-ordereddict-object-has-no-attribute-eval 

 

AttributeError: 'collections.OrderedDict' object has no attribute 'eval'

I have a model file which looks like this OrderedDict([('inp.conv1.conv.weight', (0 ,0 ,0 ,.,.) = -1.5073e-01 6.4760e-02 1.9156e-01 1.2175e-01 3.5886e-02 1.39...

stackoverflow.com

sol) 모델을 불러올때 torch.load(PATH)가 아니라 model.load_state_dict(torch.load(file_path)) 로 대체해준다.

 

 

argmax(): argument 'input' (position 1) must be Tensor, not tuple

모델 추론하려 테스트할때 생긴 에러. torch.argmax() 함수의 입력으로 tuple이 아닌 Tensor를 사용해야 한다.

모델 예측시 내가 반환값(output)을 2개를 설정해놔서 생긴 오류였다.

 

sol)  

_, predicted = torch.max(output, dim = 1)
_, predicted = torch.max(output[0], dim=1)로 바꿔 해결했다.
 
 

 


7. Raspberrypi error

 

라즈베리파이 모니터 화면이 안 나올 경우

임베디드에선 gnd와 vcc의 연결이 중요하다.

Sol)보드와 모니터끼리 hdmi 케이블을 먼저 연결한 이후에 라즈베리파이에 전원케이블을 꽂아야 한다!!

*라즈베리파이 보드와 모니터의 gnd를 먼저 통일하고, 그 다음 보드에 vcc 5V를 인가해주는 것이다.

윈도우환경에서도 가끔 모니터 등 장치연결이 이상한 경우, 해당 방법처럼 본체와 먼저 장치를 연결하고 전원을 인가했을때 문제가 해결되는 경우가 있다.

카메라 연결 안됨: vcgencmd get_camera로 연결 확인시 detectied = 1로 뜨는 경우:

Sol) 

1. 카메라 포트가 잘 물렸는지 확인한다.(앞 뒤 방향 확인, 끝까지 물렸는지 확인)

2. 그래도 안 된다면 카메라가 연결된 상태에서 재부팅


8. 기타 에러

DenseDepth error: (오픈소스 실행 중 경험한 오류)

AttributeError: module 'tensorflow.compat.v2' has no attribute 'internal'

tensorflow 2.3.0에는 keras 2.4버전이 깔려야 하는데, 2.10 깔려있었음

Sol) keras2.4버전 재설치로 해결

reference: https://github.com/fizyr/keras-retinanet/issues/1538

*참고: 파이썬 라이브러리들끼리 충돌이 날 때는 오류코드를 잘 읽고 해당 라이브러리를 수정하자. 혹 최신버전 라이브러리가 설치 안 된다면 pip 버전이 최신이 아니어서일 수도 있다.

ImportError: cannot import name '_validate_lengths' from 'numpy.lib.arraypad’

Sol) $ conda install -c conda-forge scikit-image

아직 해결 못함.. 아마 넘파이 버전이 높아서 그런걸지도, or densedepth가 높은 tensorrt 버전은 지원 안 할지도