본문 바로가기

프로그래밍/AI:ML:DL

[YOLO] shape_optimizer failed: Invalid argument, remapper failed: Invalid argument, layout failed: Invalid argument

반응형

qqwweee 의 keras-yolo3 를 실행하다가 다음과 같은 에러가 발생하였다.  ( 내 실행환경은 tensorflow 1.15 였음. )

E tensorflow/core/grappler/optimizers/meta_optimizer.cc:502] shape_optimizer failed: Invalid argument: Subshape must have computed start >= end since stride is negative, but is 0 and 2 (computed from start 0 and end 9223372036854775807 over shape with rank 2 and stride-1) 
E tensorflow/core/grappler/optimizers/meta_optimizer.cc:502] remapper failed: Invalid argument: Subshape must have computed start >= end since stride is negative, but is 0 and 2 (computed from start 0 and end 9223372036854775807 over shape with rank 2 and stride-1) 
E tensorflow/core/grappler/optimizers/meta_optimizer.cc:502] layout failed: Invalid argument: Subshape must have computed start >= end since stride is negative, but is 0 and 2 (computed from start 0 and end 9223372036854775807 over shape with rank 2 and stride-1) 
E tensorflow/core/grappler/optimizers/meta_optimizer.cc:502] shape_optimizer failed: Invalid argument: Subshape must have computed start >= end since stride is negative, but is 0 and 2 (computed from start 0 and end 9223372036854775807 over shape with rank 2 and stride-1) 
E tensorflow/core/grappler/optimizers/meta_optimizer.cc:502] remapper failed: Invalid argument: Subshape must have computed start >= end since stride is negative, but is 0 and 2 (computed from start 0 and end 9223372036854775807 over shape with rank 2 and stride-1) 



이 에러가 무엇인지 검색하여 다음과 같은 스택오버플로우의 질문/답변을 찾았다. 

https://stackoverflow.com/questions/57558476/training-a-keras-model-yields-multiple-optimizer-errors

아래에 답변만 번역하여 옮겨 놓는다.

----답변번역----

여기에서 해답을 찾았다.: https://github.com/tensorflow/tensorrt/issues/118

yolo3/model.py 소스파일의 140/141번째 줄을 다음과 같이 바꾸면 된다. :

box_xy = (K.sigmoid(feats[..., :2]) + grid) / K.cast(grid_shape[::-1], K.dtype(feats)) 
box_wh = K.exp(feats[..., 2:4]) * anchors_tensor / K.cast(input_shape[::-1], K.dtype(feats)) 

를 아래와 같이:

box_xy = (K.sigmoid(feats[..., :2]) + grid) / K.cast(grid_shape[...,::-1], K.dtype(feats)) 
box_wh = K.exp(feats[..., 2:4]) * anchors_tensor / K.cast(input_shape[...,::-1], K.dtype(feats)) 

그리고, 내 경우 배치사이즈( batch size )를 8에서 4로 줄이는 것도 도움이 됐다.

Piotr Golinski

덧글 : 대체 어디가 바뀐건지 열심히 찾을 사람들을 위해서. 위 두 부분의 차이점은, K.cast(grid_shape[::-1] 이 K.cast(grid_shape[...,::-1] 로 바뀐 것이고, input_shape 부분도 같은 방법으로 바뀌어 있음. - abacusreader

----답변번역끝----

728x90