"Keras:에러"의 두 판 사이의 차이

Pywiki
둘러보기로 가기 검색하러 가기
 
(사용자 2명의 중간 판 4개는 보이지 않습니다)
15번째 줄: 15번째 줄:
 
제너레이터를 사용하기 위해 Sequence를 불러올 때, <code>keras.utils.Sequence</code>로 불러오는데... 에러의 원인은 모르겠다.. 버전문제인 듯한데.. 두 가지 방법이 있다.
 
제너레이터를 사용하기 위해 Sequence를 불러올 때, <code>keras.utils.Sequence</code>로 불러오는데... 에러의 원인은 모르겠다.. 버전문제인 듯한데.. 두 가지 방법이 있다.
 
# 버전이 낮은 경우 : pip install keras --upgrade
 
# 버전이 낮은 경우 : pip install keras --upgrade
# <code>keras.utils.all_utils.Sequence</code>로 불러오기. <code>from keras.utils.all_utils import Sequence</code> 형태로 부르기.
+
# 텐스플로우와 함께 설치된 케라스를 이용해 불러오는 것이 가장 정확하다. <code>from tensorflow.keras.utils import Sequence</code>
 +
# 케라스 단독으로 사용한다면 다음 시도도 해보자. <code>keras.utils.all_utils.Sequence</code>로 불러오기. <code>from keras.utils.all_utils import Sequence</code> 형태로 부르기.
  
 
=== Function call stack: train_function error ===
 
=== Function call stack: train_function error ===
21번째 줄: 22번째 줄:
  
 
<code>I tensorflow/core/common_runtime/bfc_allocator.cc:1040] Next region of size 숫자.</code>
 
<code>I tensorflow/core/common_runtime/bfc_allocator.cc:1040] Next region of size 숫자.</code>
 +
 +
=== You must install pydot (`pip install pydot`) and install graphviz (see instructions at <nowiki>https://graphviz.gitlab.io/download/</nowiki>) ', 'for plot_model/model_to_dot to work. ===
 +
관련 라이브러리를 설치하지 않은 경우.
 +
 +
다음 링크를 참고해서 해결했다. [https://stackoverflow.com/questions/47605558/importerror-failed-to-import-pydot-you-must-install-pydot-and-graphviz-for-py 링크] 변경사항을 반영하기 위해 IDE를 재시작해야 한다.
  
 
== GPU 관련 ==
 
== GPU 관련 ==
32번째 줄: 38번째 줄:
 
* 활성화 함수를 ReLU 대신 다른 것 사용해보기.
 
* 활성화 함수를 ReLU 대신 다른 것 사용해보기.
  
 +
=== Allocator (GPU_0_bfc) ran out of memory trying to allocate 8.92GiB (rounded to 9574400000)requested by op CudnnRNN ===
 +
위와 같은 에러는 저만한 용량을 욯지만, GPU에서 처리할 수 없음을 보여준다.
 +
 +
가장 간단한 처리는 메모리 사용을 줄이게끔 batch_size를 줄이는 것. 그러나 메모리가 충분함에도 에러를 띄우는 경우가 있는데, 이는 GPU 사용에 제한이 걸려있기 때문.
 +
{| class="wikitable"
 +
|+해결방법
 +
!방법
 +
!설명
 +
|-
 +
|런타임 할당에 따라 메모리 설정
 +
|훈련 전에 다음의 코드를 넣는다.<syntaxhighlight lang="python">
 +
config = tf.ConfigProto()
 +
# 2버전 부터는 경로가 바뀌었기 때문에 다음과 같이 넣자. tf.compat.v1.ConfigProto()
 +
config.gpu_options.allow_growth = True
 +
session = tf.Session(config=config)
 +
# 2버전 부터는 경로가 바뀌었기 때문에 다음의 경로를 지정하자. tf.compat.v1.Session
 +
</syntaxhighlight>텐서플로우 2부턴 경로가 바뀌었기 때문에 config에 다음과 같이 넣자.
 +
|-
 +
|메모리 할당 비율을 설정
 +
|훈련 전에 다음의 코드를 넣는다.<syntaxhighlight lang="python">
 +
config = tf.ConfigProto()
 +
config.gpu_options.per_process_gpu_memory_fraction = 0.4
 +
session = tf.Session(config=config)
 +
</syntaxhighlight>
 +
|}
 
[[분류:Keras]]
 
[[분류:Keras]]

2022년 4월 12일 (화) 17:46 기준 최신판

1 개요[편집 | 원본 편집]

케라스를 사용하다 발생하는 에러들을 모아둔 문서이다.

1.1 InternalError: stream did not block host until done; was already in an error state[편집 | 원본 편집]

쥬피터노트북을 사용할 때 나오는 에러인데, 간단하다. 쥬피터노트북을 재시작하면 해결.

1.2 InternalError:    Failed to call ThenRnnForward with model config: [rnn_mode, rnn_input_mode, rnn_direction_mode]:[편집 | 원본 편집]

아마 데이터가 너무 커서 발생하는 에러.


이외.. 모델이 너무 크면 커널을 죽이기도 하던데.. 이건 딱히 뜨는 에러가 없어 모르겠다;;

1.3 AttributeError: module 'keras.utils' has no attribute 'Sequence'[편집 | 원본 편집]

제너레이터를 사용하기 위해 Sequence를 불러올 때, keras.utils.Sequence로 불러오는데... 에러의 원인은 모르겠다.. 버전문제인 듯한데.. 두 가지 방법이 있다.

  1. 버전이 낮은 경우 : pip install keras --upgrade
  2. 텐스플로우와 함께 설치된 케라스를 이용해 불러오는 것이 가장 정확하다. from tensorflow.keras.utils import Sequence
  3. 케라스 단독으로 사용한다면 다음 시도도 해보자. keras.utils.all_utils.Sequence로 불러오기. from keras.utils.all_utils import Sequence 형태로 부르기.

1.4 Function call stack: train_function error[편집 | 원본 편집]

아마 메모리 사용량이 너무 클 때 나타나는 에러인듯. 아래 에러도 비슷한 이유에서 나타나는 듯하다. 하여간... 다른 시간대에 다시 실행하면 작동하기도 해서... 굉장히 당황스러운 에러다;

I tensorflow/core/common_runtime/bfc_allocator.cc:1040] Next region of size 숫자.

1.5 You must install pydot (`pip install pydot`) and install graphviz (see instructions at https://graphviz.gitlab.io/download/) ', 'for plot_model/model_to_dot to work.[편집 | 원본 편집]

관련 라이브러리를 설치하지 않은 경우.

다음 링크를 참고해서 해결했다. 링크 변경사항을 반영하기 위해 IDE를 재시작해야 한다.

2 GPU 관련[편집 | 원본 편집]

2.1 WARNING:tensorflow:Layer lstm will not use cuDNN kernels since it doesn't meet the criteria. It will use a generic GPU kernel as fallback when running on GPU.[편집 | 원본 편집]

몇몇 조건에 의해 GPU 사용이 안될 때 나타나는 에러이다. 단순히 GPU 사용이 안된다는 건데, 큰 메모리를 사용하는 딥러닝의 특성 상 이 에러가 뜨면 실패 확정이라 보면 된다.

다음과 같은 시도가 가능하다.

  • recurrent_dropout 옵션 없애기.
  • 활성화 함수를 ReLU 대신 다른 것 사용해보기.

2.2 Allocator (GPU_0_bfc) ran out of memory trying to allocate 8.92GiB (rounded to 9574400000)requested by op CudnnRNN[편집 | 원본 편집]

위와 같은 에러는 저만한 용량을 욯지만, GPU에서 처리할 수 없음을 보여준다.

가장 간단한 처리는 메모리 사용을 줄이게끔 batch_size를 줄이는 것. 그러나 메모리가 충분함에도 에러를 띄우는 경우가 있는데, 이는 GPU 사용에 제한이 걸려있기 때문.

해결방법
방법 설명
런타임 할당에 따라 메모리 설정 훈련 전에 다음의 코드를 넣는다.
config = tf.ConfigProto()
# 2버전 부터는 경로가 바뀌었기 때문에 다음과 같이 넣자. tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config)
# 2버전 부터는 경로가 바뀌었기 때문에 다음의 경로를 지정하자. tf.compat.v1.Session
텐서플로우 2부턴 경로가 바뀌었기 때문에 config에 다음과 같이 넣자.
메모리 할당 비율을 설정 훈련 전에 다음의 코드를 넣는다.
config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.4
session = tf.Session(config=config)