This branch provides detection and Android code complement to branch tf-only-export
.
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
.
git clone https://github.com/zldrobit/yolov5.git
cd yolov5
git checkout tf-android
and download pretrained weights from
https://github.com/ultralytics/yolov5.git
pip install -r requirements.txt
pip install tensorflow==2.4.1
- Convert weights to TensorFlow SavedModel, GraphDef and fp16 TFLite model, and verify them with
PYTHONPATH=. python models/tf.py --weights weights/yolov5s.pt --cfg models/yolov5s.yaml --img 320
python3 detect.py --weights weights/yolov5s.pb --img 320
python3 detect.py --weights weights/yolov5s_saved_model/ --img 320
- Convert weights to int8 TFLite model, and verify it with (Post-Training Quantization needs train or val images from COCO 2017 dataset)
PYTHONPATH=. python3 models/tf.py --weights weights/yolov5s.pt --cfg models/yolov5s.yaml --img 320 --tfl-int8 --source /data/dataset/coco/coco2017/train2017 --ncalib 100
python3 detect.py --weights weights/yolov5s-int8.tflite --img 320 --tfl-int8
- Convert weights to TensorFlow SavedModel and GraphDef integrated with NMS, and verify them with
PYTHONPATH=. python3 models/tf.py --img 320 --weights weights/yolov5s.pt --cfg models/yolov5s.yaml --tf-nms
python3 detect.py --img 320 --weights weights/yolov5s.pb --no-tf-nms
python3 detect.py --img 320 --weights weights/yolov5s_saved_model --no-tf-nms
inputSize
to--img
output_width
according to new/oldinputSize
ratioanchors
tom.anchor_grid
as ultralytics#1127 (comment) in android/app/src/main/java/org/tensorflow/lite/examples/detection/tflite/DetectorFactory.java
Then run the program in Android Studio.
If you have further question, plz ask in ultralytics#1127