개발 공부용

java.lang.IllegalArgumentException: Cannot copy to a TensorFlowLite tensor (serving_default_input_1:0) with 4915200 bytes from a Java Buffer with 1638400 bytes. 본문

Error

java.lang.IllegalArgumentException: Cannot copy to a TensorFlowLite tensor (serving_default_input_1:0) with 4915200 bytes from a Java Buffer with 1638400 bytes.

솝제로 2024. 8. 2. 03:19

TensorFlowLite 모델의 output과 이 output을 저장할 JavaBuffer의 크기가 맞지 않아서 생기는 오류.

https://netron.app/ 에서 모델을 열고 output 크기를 확인한 뒤 맞춰서 JavaBuffer를 만들어 주면 된다.

 

 

우리 모델은 float32[1, 25200, 6]으로 3차원 배열이었다.

 

        // 이미지 데이터를 ByteBuffer로 변환
        ByteBuffer byteBuffer = convertBitmapToByteBuffer(resizedBitmap);
        float[][][] result = new float[1][25200][6];
        interpreter.run(byteBuffer, result);

 

따라서 이렇게 만들어 주었다.