opened
TheHong
username_0
I trained YOLOv2-tiny using Darknet on a computer. **During testing off the phone, all objects were detected.**
However, when inputting the same images to the tflite model on my Flutter app **on a phone, some detections were missing/incorrect.**

_At first I thought I was training the model poorly, but when I found out that the .weights detections were good on the computer and differed from the .tflite detections on the phone, it seemed like the model on the phone was not behaving the same way as on the computer._

I am more than happy to provide more information about this, if needed.

**Here is some more information:**
- Off the phone, I converted .weights file from Darknet to .pb and then to .tflite using https://prashantdandriyal.medium.com/darknet-to-tensorflow-to-tensorflowlite-b783d55b106a. 
- On the phone, my implementation in Flutter is the following (based on https://github.com/shaqian/flutter_tflite/blob/master/example/lib/main.dart):

```
import 'package:flutter/services.dart';
import 'package:tflite/tflite.dart';
import 'package:image/image.dart' as img;
static Future<List> runDetector(File imageFile) async {
    await Tflite.loadModel(
        model: "assets/$modelToLoad.tflite",
        labels: "assets/${modelToLoad}_labels.txt",
      );
    var imageBytes = (await rootBundle.load(imageFile.path)).buffer;
    img.Image oriImage = img.decodeJpg(imageBytes.asUint8List());
    img.Image resizedImage = img.copyResize(
      oriImage,
      width: 416,
      height: 416,
    );
    return await Tflite.detectObjectOnBinary(
      binary: imageToByteListFloat32(resizedImage,416,0.0,255.0,),
      model: "YOLO",
      threshold: 0.05,
      numResultsPerClass: 5,
      anchors: [1.08, 1.19, 3.42, 4.41, 6.63, 11.38, 9.42, 5.11, 16.62, 10.52], // based on .cfg file
      blockSize: 32, // defaults to 32
      numBoxesPerBlock: 5, // defaults to 5
      asynch: true, // defaults to true
    );
}

static Uint8List imageToByteListFloat32(
      img.Image image, int inputSize, double mean, double std) {
    var convertedBytes = Float32List(1 * inputSize * inputSize * 3);
    var buffer = Float32List.view(convertedBytes.buffer);
    int pixelIndex = 0;
    for (var i = 0; i < inputSize; i++) {
      for (var j = 0; j < inputSize; j++) {
        var pixel = image.getPixel(j, i);
        buffer[pixelIndex++] = (img.getRed(pixel) - mean) / std;
        buffer[pixelIndex++] = (img.getGreen(pixel) - mean) / std;
        buffer[pixelIndex++] = (img.getBlue(pixel) - mean) / std;
      }
    }
    return convertedBytes.buffer.asUint8List();
  }
```
YOLOv2-tiny detections on computer differ from detections on phone (using flutter_tflite)
issue