hunglc007 / tensorflow-yolov4-tflite

YOLOv4, YOLOv4-tiny, YOLOv3, YOLOv3-tiny Implemented in Tensorflow 2.0, Android. Convert YOLO v4 .weights tensorflow, tensorrt and tflite
https://github.com/hunglc007/tensorflow-yolov4-tflite
MIT License
2.23k stars 1.24k forks source link

yolv4-tiny on Android #328

Closed mhyeonsoo closed 3 years ago

mhyeonsoo commented 3 years ago

Hello,

I am now trying to implement yolov4-tiny on the Android, but when I try making apk file and open at my phone, it has been broken everytime.

Can anyone fix/modify my settings/configurations for the yolov4-tiny? I came through the way starting from Alexey's Darknet to this repo.

  1. Darknet yolov4-tiny cfg for training ( my custom data has 1 class )
    
    [net]
    # Testing
    #batch=1
    #subdivisions=1
    # Training
    batch=64
    subdivisions=32
    width=416
    height=416
    channels=3
    momentum=0.9
    decay=0.0005
    angle=0
    saturation = 1.5
    exposure = 1.5
    hue=.1

learning_rate=0.00261 burn_in=1000 max_batches = 3000 policy=steps steps=2400,2700 scales=.1,.1

[convolutional] batch_normalize=1 filters=32 size=3 stride=2 pad=1 activation=leaky

[convolutional] batch_normalize=1 filters=64 size=3 stride=2 pad=1 activation=leaky

[convolutional] batch_normalize=1 filters=64 size=3 stride=1 pad=1 activation=leaky

[route] layers=-1 groups=2 group_id=1

[convolutional] batch_normalize=1 filters=32 size=3 stride=1 pad=1 activation=leaky

[convolutional] batch_normalize=1 filters=32 size=3 stride=1 pad=1 activation=leaky

[route] layers = -1,-2

[convolutional] batch_normalize=1 filters=64 size=1 stride=1 pad=1 activation=leaky

[route] layers = -6,-1

[maxpool] size=2 stride=2

[convolutional] batch_normalize=1 filters=128 size=3 stride=1 pad=1 activation=leaky

[route] layers=-1 groups=2 group_id=1

[convolutional] batch_normalize=1 filters=64 size=3 stride=1 pad=1 activation=leaky

[convolutional] batch_normalize=1 filters=64 size=3 stride=1 pad=1 activation=leaky

[route] layers = -1,-2

[convolutional] batch_normalize=1 filters=128 size=1 stride=1 pad=1 activation=leaky

[route] layers = -6,-1

[maxpool] size=2 stride=2

[convolutional] batch_normalize=1 filters=256 size=3 stride=1 pad=1 activation=leaky

[route] layers=-1 groups=2 group_id=1

[convolutional] batch_normalize=1 filters=128 size=3 stride=1 pad=1 activation=leaky

[convolutional] batch_normalize=1 filters=128 size=3 stride=1 pad=1 activation=leaky

[route] layers = -1,-2

[convolutional] batch_normalize=1 filters=256 size=1 stride=1 pad=1 activation=leaky

[route] layers = -6,-1

[maxpool] size=2 stride=2

[convolutional] batch_normalize=1 filters=512 size=3 stride=1 pad=1 activation=leaky

##################################

[convolutional] batch_normalize=1 filters=256 size=1 stride=1 pad=1 activation=leaky

[convolutional] batch_normalize=1 filters=512 size=3 stride=1 pad=1 activation=leaky

[convolutional] size=1 stride=1 pad=1 filters=18 activation=linear

[yolo] mask = 3,4,5 anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 classes=1 num=6 jitter=.3 scale_x_y = 1.05 cls_normalizer=1.0 iou_normalizer=0.07 iou_loss=ciou ignore_thresh = .7 truth_thresh = 1 random=0 nms_kind=greedynms beta_nms=0.6

[route] layers = -4

[convolutional] batch_normalize=1 filters=128 size=1 stride=1 pad=1 activation=leaky

[upsample] stride=2

[route] layers = -1, 23

[convolutional] batch_normalize=1 filters=256 size=3 stride=1 pad=1 activation=leaky

[convolutional] size=1 stride=1 pad=1 filters=18 activation=linear

[yolo] mask = 1,2,3 anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 classes=1 num=6 jitter=.3 scale_x_y = 1.05 cls_normalizer=1.0 iou_normalizer=0.07 iou_loss=ciou ignore_thresh = .7 truth_thresh = 1 random=0 nms_kind=greedynms beta_nms=0.6

2. config.py at  tensorflow-yolov4-tflite converting

! /usr/bin/env python

coding=utf-8

from easydict import EasyDict as edict

__C = edict()

Consumers can get config by: from config import cfg

cfg = __C

YOLO options

__C.YOLO = edict()

C.YOLO.CLASSES = "./data/classes/obj.names" C.YOLO.ANCHORS = [12,16, 19,36, 40,28, 36,75, 76,55, 72,146, 142,110, 192,243, 459,401] __C.YOLO.ANCHORS_V3 = [10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326]

__C.YOLO.ANCHORS_TINY = [23,27, 37,58, 81,82, 81,82, 135,169, 344,319]

C.YOLO.ANCHORS_TINY = [10,14, 23,27, 37,58, 81,82, 135,169, 344,319] C.YOLO.STRIDES = [8, 16, 32] C.YOLO.STRIDES_TINY = [16, 32] C.YOLO.XYSCALE = [1.2, 1.1, 1.05] __C.YOLO.XYSCALE_TINY = [1.05, 1.05] C.YOLO.ANCHOR_PER_SCALE = 3 C.YOLO.IOU_LOSS_THRESH = 0.5

Train options

__C.TRAIN = edict()

__C.TRAIN.ANNOT_PATH = "./data/obj.txt" __C.TRAIN.BATCH_SIZE = 2

__C.TRAIN.INPUT_SIZE = [320, 352, 384, 416, 448, 480, 512, 544, 576, 608]

C.TRAIN.INPUT_SIZE = 416 __C.TRAIN.DATA_AUG = True C.TRAIN.LR_INIT = 1e-3 C.TRAIN.LR_END = 1e-6 __C.TRAIN.WARMUP_EPOCHS = 2 C.TRAIN.FISRT_STAGE_EPOCHS = 20 __C.TRAIN.SECOND_STAGE_EPOCHS = 30

TEST options

__C.TEST = edict()

C.TEST.ANNOT_PATH = "./obj.txt" __C.TEST.BATCH_SIZE = 2 C.TEST.INPUT_SIZE = 416 C.TEST.DATA_AUG = False C.TEST.DECTECTED_IMAGE_PATH = "./data/detection/" C.TEST.SCORE_THRESHOLD = 0.25 C.TEST.IOU_THRESHOLD = 0.5

3. Yolo & Yolo-tiny config from android YoloV4Classifier.java

//config yolov4 private static final int INPUT_SIZE = 416; private static final int[] OUTPUT_WIDTH = new int[]{52, 26, 13};

private static final int[][] MASKS = new int[][]{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
private static final int[] ANCHORS = new int[]{
        12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401
};
private static final float[] XYSCALE = new float[]{1.2f, 1.1f, 1.05f};

private static final int NUM_BOXES_PER_BLOCK = 3;

// Number of threads in the java app
private static final int NUM_THREADS = 4;
private static boolean isNNAPI = false;
private static boolean isGPU = true;

// tiny or not
private static boolean isTiny = true;

// config yolov4 tiny
private static final int[] OUTPUT_WIDTH_TINY = new int[]{2535, 2535};
private static final int[] OUTPUT_WIDTH_FULL = new int[]{10647, 10647};
private static final int[][] MASKS_TINY = new int[][]{{3, 4, 5}, {1, 2, 3}};
private static final int[] ANCHORS_TINY = new int[]{
        23, 27, 37, 58, 81, 82, 81, 82, 135, 169, 344, 319};
private static final float[] XYSCALE_TINY = new float[]{1.05f, 1.05f};

private boolean isModelQuantized;


Thanks for reading long texts.
mhyeonsoo commented 3 years ago

solved from my side

AmokraneMancer commented 3 years ago

solved from my side

Hi, I am facing the same issue; How did you solve it ?