Skip to content
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

Cannot copy from a TensorFlowLite tensor (Identity) with shape [1, 6, 8400] to a Java object with shape [1, 80, 80, 21]. #12426

Closed
1 task done
HoangBee102 opened this issue Nov 25, 2023 · 5 comments
Labels
question Further information is requested Stale Stale and schedule for closing soon

Comments

@HoangBee102
Copy link

Search before asking

Question

Cannot copy from a TensorFlowLite tensor (Identity) with shape [1, 6, 8400] to a Java object with shape [1, 80, 80, 21].
Help me fix this error for my app, pls!

Additional

No response

@HoangBee102 HoangBee102 added the question Further information is requested label Nov 25, 2023
@glenn-jocher
Copy link
Member

@HoangBee102 this error indicates a shape mismatch between the TensorFlowLite tensor and the Java object. To resolve this, ensure that the output format of the model matches the input requirements of your application. You might need to reshape or transpose the tensor accordingly. Check the model's output configuration and the input expectations of your Java object for compatibility.

If you need further assistance, consider sharing additional details about your inference pipeline, including the model configuration and relevant code snippets.

For comprehensive information on YOLOv5 usage, refer to the Ultralytics Docs at https://docs.ultralytics.com/yolov5/.

@HoangBee102
Copy link
Author

`public void setInput(Bitmap resizedbitmap){
boolean quantized_mode = TfliteRunMode.isQuantizedMode(this.runmode);
int numBytesPerChannel = quantized_mode ? numBytesPerChannel_int : numBytesPerChannel_float;
ByteBuffer imgData = ByteBuffer.allocateDirect(1 * inputSize * inputSize * 3 * numBytesPerChannel);

    int[] intValues = new int[inputSize * inputSize];
    resizedbitmap.getPixels(intValues, 0, resizedbitmap.getWidth(), 0, 0, resizedbitmap.getWidth(), resizedbitmap.getHeight());

    imgData.order(ByteOrder.nativeOrder());
    imgData.rewind();
    for (int i = 0; i < inputSize; ++i) {
        for (int j = 0; j < inputSize; ++j) {
            int pixelValue = intValues[i * inputSize + j];
            if (quantized_mode) {
                // Quantized model
                imgData.put((byte) ((pixelValue >> 16) & 0xFF));
                imgData.put((byte) ((pixelValue >> 8) & 0xFF));
                imgData.put((byte) (pixelValue & 0xFF));
            } else { // Float model
                float r = (((pixelValue >> 16) & 0xFF)) / 255.0f;
                float g = (((pixelValue >> 8) & 0xFF)) / 255.0f;
                float b = ((pixelValue & 0xFF)) / 255.0f;
                imgData.putFloat(r);
                imgData.putFloat(g);
                imgData.putFloat(b);
            }
        }
    }
    this.inputArray = new Object[]{imgData};
    this.outputMap = new HashMap<>();
    outputMap.put(0, this.rawres.out1);
    outputMap.put(1, this.rawres.out2);
    outputMap.put(2, this.rawres.out3);
}`

My custom train has 2 class, model export from ultralytic hub .tflite
Model in netron app: image

Model in demo app work fine:
image

Author say me:

I think you don't follow this instruction. https://github.com/lp6m/yolov5s_android/tree/master/convert_model#onnx---openvino

Pls help me howto fix???

@glenn-jocher
Copy link
Member

@HoangBee102 i see that you're trying to use a custom YOLOv5 model in a demo app, and it seems you are facing some issues related to the model input and output configurations. It's important to ensure that the input preprocessing in your custom code matches the input requirements of the model and the post-processing matches the model's output format.

It looks like there might be a discrepancy between the input processing in your code and the model's expected input format.

Regarding the author's suggestion, it would be helpful to review the instruction link provided and confirm if the conversion steps have been followed accurately.

For comprehensive guidance on using custom YOLOv5 models, including input preprocessing and output post-processing, I recommend referring to the Ultralytics Docs at https://docs.ultralytics.com/yolov5/.

Feel free to provide additional details or code snippets if you need further assistance.

Copy link
Contributor

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale Stale and schedule for closing soon label Dec 26, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 5, 2024
@hyunjincho84
Copy link

@HoangBee102 did you sloved the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale Stale and schedule for closing soon
Projects
None yet
Development

No branches or pull requests

3 participants