활연개랑

[ERROR 해결] Input to reshape is a tensor with 8192 values, but the requested shape requires a multiple of 16384 본문

딥러닝

[ERROR 해결] Input to reshape is a tensor with 8192 values, but the requested shape requires a multiple of 16384

승해tmdhey 2023. 6. 6. 18:21
반응형

 

Traceback (most recent call last):
  File "/inference.py", line 244, in <module>
    pred = model(input_img, is_training=False)
  File "/home/.local/lib/python3.8/site-packages/keras/engine/base_layer.py", line 1037, in __call__
    outputs = call_fn(inputs, *args, **kwargs)
  File "/home/.local/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 885, in __call__
    result = self._call(*args, **kwds)
  File "/home/.local/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 950, in _call
    return self._stateless_fn(*args, **kwds)
  File "/home/.local/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 3039, in __call__
    return graph_function._call_flat(
  File "/home/.local/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 1963, in _call_flat
    return self._build_call_outputs(self._inference_function.call(
  File "/home/.local/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 591, in call
    outputs = execute.execute(
  File "/home/.local/lib/python3.8/site-packages/tensorflow/python/eager/execute.py", line 59, in quick_execute
    tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
tensorflow.python.framework.errors_impl.InvalidArgumentError:  Input to reshape is a tensor with 8192 values, but the requested shape requires a multiple of 16384
	 [[node flatten/Reshape (defined at inference.py:94) ]] [Op:__inference_call_1414]

Errors may have originated from an input operation.
Input Source operations connected to node flatten/Reshape:
 max_pooling3d_3/MaxPool3D (defined at inference.py:92)

Function call stack:
call


Process finished with exit code 1

 

이 오류는 입력 데이터의 shape 문제로 인해 발생하는 것입니다.

저의 경우에는 입력 데이터의 shape이 (8192,)인데, 이를 (16384,) shape으로 변환하려고 시도하고 있다는 것을 알 수 있습니다.

 

 

이런 오류가 나타날 경우, 경험상 두 가지를 확인해 볼 수 있습니다.

 

첫번째는, 실제로 model에 들어가는 input shape이 다른 경우 입니다. 

 

두번째는 제 실수로 일어난 문제인데요, 학습시킨 모델의 네트워크 채널과 인퍼런스과정에서의 모델 채널이 다른 경우입니다. training에서는 channel이 {32-64-128-256}이 되도록 학습시키고, inference 과정에서는 {64-128-256-512}가 되도록 학습시키면서 위와 같은 오류가 나오게 되었습니다.

 

* tfrecords를 사용한다면, 추가적으로 data type이 바뀌지는 않았는지 확인해 볼 수 있습니다.

 

 

이런 오류가 발생했을 때 위처럼 두 가지 방법과 추가적인 방법을 확인해보면 좋을 것 같아요~ 

감사합니다.