Giter VIP home page Giter VIP logo

yolov5's Introduction

Info

This branch provides detection and Android code complement to branch tf-only-export. Since the release of YOLOv5 v6.0, TFLite models can be exported by export.py in ultralytics' master branch. Using models/tf.py to export models is deprecated, and this repo is mainly for Anrdroid demo app. models/tf.py uses TF2 API to construct a tf.Keras model according to *.yaml config files and reads weights from *.pt, without using ONNX.

Because this branch persistently rebases to master branch of ultralytics/yolov5, use git pull --rebase or git pull -f instead of git pull.

Usage

1. Git clone Ultralytics yolov5

git clone https://github.com/ultralytics/yolov5.git
cd yolov5

2. Convert and verify

  • Convert weights to fp16 TFLite model, and verify it with
python export.py --weights yolov5s.pt --include tflite --img 320
python detect.py --weights yolov5s-fp16.tflite --img 320

or

  • Convert weights to int8 TFLite model, and verify it with
python export.py --weights yolov5s.pt --include tflite --int8 --img 320 --data data/coco128.yaml
python detect.py --weights yolov5s-int8.tflite --img 320

Note that:

  • int8 quantization needs dataset images to calibrate weights and activations, and the default COCO128 dataset is downloaded automatically.
  • Change --img to the input resolution of your model, if it isn't 320.

3. Clone this repo (tf-android branch) for Android app

git clone https://github.com/zldrobit/yolov5.git yolov5-android

4. Put TFLite models in assets folder of Android project, and change

  • inputSize to --img
  • output_width according to new/old inputSize ratio
  • anchors to m.anchor_grid as ultralytics#1127 (comment) in android/app/src/main/java/org/tensorflow/lite/examples/detection/tflite/DetectorFactory.java
  • labelFilename according to the classes of the model in
    if (modelFilename.equals("yolov5s.tflite")) {
    labelFilename = "file:///android_asset/coco.txt";
    isQuantized = false;
    inputSize = 640;
    output_width = new int[]{80, 40, 20};
    masks = new int[][]{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
    anchors = new int[]{
    10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
    };
    }
    else if (modelFilename.equals("yolov5s-fp16.tflite")) {
    labelFilename = "file:///android_asset/coco.txt";
    isQuantized = false;
    inputSize = 320;
    output_width = new int[]{40, 20, 10};
    masks = new int[][]{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
    anchors = new int[]{
    10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
    };
    }
    else if (modelFilename.equals("yolov5s-int8.tflite")) {
    labelFilename = "file:///android_asset/coco.txt";
    isQuantized = true;
    inputSize = 320;
    output_width = new int[]{40, 20, 10};
    masks = new int[][]{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
    anchors = new int[]{
    10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
    };
    }
    .

Then run the program in Android Studio.

TODO:

  • Add NNAPI support

EDIT:

  • Update according YOLOv5 v6.0 release

If you have further question, plz ask in ultralytics#1127

Reference:

https://github.com/hunglc007/tensorflow-yolov4-tflite.git

yolov5's People

Contributors

ab-101 avatar aehogan avatar albinxavi avatar alexstoken avatar alexwang1900 avatar anon-artist avatar ayushexel avatar borda avatar cristifati avatar dependabot-preview[bot] avatar developer0hye avatar dlawrences avatar edurenye avatar fcakyon avatar glenn-jocher avatar kinoute avatar laughing-q avatar lorenzomammana avatar lornatang avatar nanocode012 avatar olehb avatar ownmarc avatar skalskip avatar taoxiesz avatar tkianai avatar toretak avatar wanghaoyang0106 avatar yeric1789 avatar yxnong avatar zldrobit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.