1

I have trained the yolov4-tiny file and successfully converted it to tflite. There were no problems during the computer test, but I encountered difficulties in installing it on the phone.

As I put my tflite into the flutter, I had different test results from my computer. And the result is not good, the accuracy is much lower, and the recognition error is often. I think the problem appear at classierYOLOv4, but i'm not sure where is wrong.

Is there any suggestion for me to fix this problem?

Thanks a lot for your help!

Here is computer test image: broccoli banana

Here is the code:https://github.com/piggychu0w0/flutter-yolov4tiny-tflite

CYH
  • 345
  • 1
  • 2
  • 9

1 Answers1

0

I think the problem here is your input not being scaled to (0,1). You have to add a normalize layer into your model or scale your input first.

Edit: Using this code to normalize image

TensorImage getProcessedImage(TensorImage inputImage) {
    padSize = max(inputImage.height, inputImage.width);
    if (imageProcessor == null) {
      imageProcessor = ImageProcessorBuilder()
          .add(ResizeWithCropOrPadOp(padSize, padSize))
          .add(ResizeOp(INPUT_SIZE, INPUT_SIZE, ResizeMethod.BILINEAR))
          .add(DequantizeOp(0, 255.0))
          .build();
    }
    inputImage = imageProcessor.process(inputImage);
    return inputImage;
  }

and load the input image

TensorImage inputImage =  TensorImage(TfLiteType.float32);
inputImage.loadImage(image);
inputImage = getProcessedImage(inputImage);
  • I'm having a similar issue. Could you provide a little more information on what you mean by the input? ```TensorImage getProcessedImage(TensorImage inputImage)``` ? As well as some info into how to scale it? – greenzebra Apr 20 '22 at 22:37
  • Sorry for late response, the problem here is the input image not being scaled in the same way when training and making inference. When training with yolov5, the input is scaled between (0,1). But when making inference using the code in the github link above, the input is between (0,255). That's why the result is bad. – Trần Tuấn Ngọc Apr 25 '22 at 02:16
  • Thanks for the response, but that made things worse for me. (I'm using yolov4tiny btw). – greenzebra Apr 26 '22 at 18:28
  • What's your problem. I suppose you use the code in the [github link](https://github.com/piggychu0w0/flutter-yolov4tiny-tflite) of OP above. You just modify it a little bit with the code in file [classifierYolov4.dart](https://github.com/piggychu0w0/flutter-yolov4tiny-tflite/blob/main/tflite/classifierYolov4.dart) with the code i written above – Trần Tuấn Ngọc Apr 29 '22 at 07:00
  • Have you tested it? the classifierYolov4.dart looks exactly the same as the code from https://github.com/TexMexMax/object_detection_flutter which is what i'm using. – greenzebra Apr 29 '22 at 22:19
  • I mean the classifierYolov4.dart is the file you need to modify by the code i written above. – Trần Tuấn Ngọc May 02 '22 at 12:43