-
Notifications
You must be signed in to change notification settings - Fork 74k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error Cannot copy to a TensorFlowLite tensor #55341
Comments
@mohantym it's works but, why change that value if my model was trained with images of 150x150 in greyscale with pixels values between 0 and 1???? Can you explain me??? Also who can i set each pixel value from 0 to1?? I will really apreciet it |
@AndryCU ! The tensor buffer size is determined by datasize (float32: 4bytes) * flat size of the tensor shape (1 * height * width * 1). (4x22500 = 90000 bytes) . Can you allocate a buffer size of 90000 bytes in above method and let us know?
|
@mohantym sorry, can you explain better, i don't know what to do sorry, if you preffer you can text me on telegram @andryssd, of course i will post evething here, but i want more interchange only if you can |
@AndryCU ! Sorry ,I was proposing these changes to have a buffer size of 90000 bytes automatically. Attaching relevant thread for reference. Thanks!
|
It's work perfectly. Thanks, i only have to said that you wrote some lines in java, but, android studio detects it and convert to kotlin automatically. |
@AndryCU hi, i'm getting the same error that you got when i try to run ly model (tflite) in android studio for detecting object, Can you please tell me which file i need to modified to solve this issue please? |
hey, today I fixed the same issue. In my case, I stored the result of the preprocessing function in a Uint8List object, while my model expects a Float32 object instead. This size difference (4 bytes for float32 vs 1 byte for Uint8List) is causing the problem. I believe you are facing a similar issue because your model is expecting 90000 bytes but receiving only 22500, which is exactly a quarter of what it should be. |
When i traid to process my model got this error:
java.lang.IllegalArgumentException: Cannot copy to a TensorFlowLite tensor (serving_default_conv2d_input:0) with 90000 bytes from a Java Buffer with 22500 bytes.
Here are the libraries i'm using:
implementation 'org.tensorflow:tensorflow-lite:2.8.0'
implementation 'org.tensorflow:tensorflow-lite-support:0.3.1'
implementation 'org.tensorflow:tensorflow-lite-metadata:0.3.1'
Here you can see my model properties:
I'm traing to config the output of this way, i'm not sure if is of this way..
val p = photoFile.data!!.extras!!.get("data") as Bitmap
val tensorImage = TensorImage.fromBitmap(p)
val model = Modelo.newInstance(applicationContext)1
val imageProcessor: ImageProcessor = ImageProcessor.Builder()
.add(ResizeOp(150, 150, ResizeOp.ResizeMethod.NEAREST_NEIGHBOR))
.add(TransformToGrayscaleOp())
.add(NormalizeOp(0f,255f))
.build()
imageProcessor.process(tensorImage)
The text was updated successfully, but these errors were encountered: