moo-nerim

Cannot copy to a TensorFlowLite tensor (serving_default_input_1:0) with 4915200 bytes from a Java Buffer with 2076672 bytes 에러 해결 방법 본문

에러 해결🛠️

Cannot copy to a TensorFlowLite tensor (serving_default_input_1:0) with 4915200 bytes from a Java Buffer with 2076672 bytes 에러 해결 방법

무네림 2022. 6. 4. 13:10

안드로이드 스튜디오와 YOLOV5 모델을 TensorFlowLite API 를 사용하는 과정에 'Cannot copy to a TensorFlowLite tensor (serving_default_input_1:0) with 4915200 bytes from a Java Buffer with 2076672 bytes' 다음과 같은 에러가 발생했다.

그래서 바로 구글링해봤는데, github의 이슈로 나와 같은 오류를 겪어 토론을 하고 있는 모습을 발견했다.

 

: Cannot copy to a TensorFlowLite tensor (serving_default_input_1:0) with 1769472 bytes from a Java Buffer with 1732800 bytes.

Search before asking I have searched the YOLOv5 issues and found no similar bug report. YOLOv5 Component No response Bug I'm coding yolov5 tflite on android studio, the code is working fine on ...

github.com

뭔가 inputSize와 관련해서 문제가 있다는 것을 깨달았고, 내가 onnx로 export한 image 크기와 현재 API에서 사용하는 size를 유심히 살펴봤다.

 

학습이 끝난 pt 파일의 모델을 onnx 파일로 export할 때 arg로  --img 640 으로 넣었다. 이미지 라벨링 시에 모든 이미지의 크기를 640 x 640 으로 resize했기 때문에 동일하게 640으로 설정했다. 

 

사용한 Tensorflow lite API 는 아래와 같다.

 

GitHub - tensorflow/examples: TensorFlow examples

TensorFlow examples. Contribute to tensorflow/examples development by creating an account on GitHub.

github.com

안드로이드와 .tflite로 conver한 모델을 연결할 때 inputSize 라는 변수를 확인했고, 기존에 416 값이 저장되어 있었다.

default 값인 416으로 설정한 뒤 app을 실행하여 결론적으로 해당 오류가 발생했다.

 

따라서, inputSize 변수의 값을 export할 때 인자로 넣은 --img 640 과 같은 size를 넣어주면 정상적으로 실행되는 걸 확인할 수 있다.

반응형
Comments