Skip to content

Commit

Permalink
misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
david8862 committed Jun 23, 2021
1 parent 46d062f commit c15b8a2
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 32 deletions.
3 changes: 3 additions & 0 deletions common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def get_colors(number, bright=True):
To get visually distinct colors, generate them in HSV space then
convert to RGB.
"""
if number <= 0:
return []

brightness = 1.0 if bright else 0.7
hsv_tuples = [(x / number, 1., brightness)
for x in range(number)]
Expand Down
2 changes: 1 addition & 1 deletion eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ def compute_AP_COCO(annotation_records, gt_classes_records, pred_classes_records
'''
Compute MSCOCO AP list on AP 0.5:0.05:0.95
'''
iou_threshold_list = np.arange(0.50, 1.00, 0.05)
iou_threshold_list = [x/100 for x in range(50, 100, 5)]
APs = {}
pbar = tqdm(total=len(iou_threshold_list), desc='Eval COCO')
for iou_threshold in iou_threshold_list:
Expand Down
3 changes: 2 additions & 1 deletion inference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ Tensorflow-lite support both Float32 and UInt8 type model. We can dump out the k
* convert keras .h5 model to Float32 tflite model:
```
# tflite_convert --keras_model_file=model.h5 --output_file=model.tflite
# cd keras-YOLOv3-model-set/tools/model_converter/
# python custom_tflite_convert.py --keras_model_file=model.h5 --output_file=model.tflite
```
* convert keras .h5 model to UInt8 tflite model with TF 2.0 Post-training integer quantization:
Expand Down
4 changes: 2 additions & 2 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ def main(args):
help='Whether to use multiscale training')
parser.add_argument('--rescale_interval', type=int, required=False, default=10,
help = "Number of iteration(batches) interval to rescale input size, default=%(default)s")
parser.add_argument('--enhance_augment', type=str, required=False, default=None, choices=[None, 'mosaic', 'mosaic_v5'],
help = "enhance data augmentation type (None/mosaic/mosaic_v5), default=%(default)s")
parser.add_argument('--enhance_augment', type=str, required=False, default=None, choices=[None, 'mosaic'],
help = "enhance data augmentation type (None/mosaic), default=%(default)s")
parser.add_argument('--label_smoothing', type=float, required=False, default=0,
help = "Label smoothing factor (between 0 and 1) for classification loss, default=%(default)s")
parser.add_argument('--multi_anchor_assign', default=False, action="store_true",
Expand Down
8 changes: 4 additions & 4 deletions yolo2/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ def __getitem__(self, index):
if self.enhance_augment == 'mosaic':
# add random mosaic augment on batch ground truth data
image_data, box_data = random_mosaic_augment(image_data, box_data, prob=0.2)
elif self.enhance_augment == 'mosaic_v5':
#elif self.enhance_augment == 'mosaic_v5':
# mosaic augment from YOLOv5
image_data, box_data = random_mosaic_augment_v5(image_data, box_data, prob=0.2)
#image_data, box_data = random_mosaic_augment_v5(image_data, box_data, prob=0.2)

y_true_data = get_y_true_data(box_data, self.anchors, self.input_shape, self.num_classes, self.multi_anchor_assign)

Expand Down Expand Up @@ -240,9 +240,9 @@ def yolo2_data_generator(annotation_lines, batch_size, input_shape, anchors, num
if enhance_augment == 'mosaic':
# add random mosaic augment on batch ground truth data
image_data, box_data = random_mosaic_augment(image_data, box_data, prob=0.2)
elif enhance_augment == 'mosaic_v5':
#elif enhance_augment == 'mosaic_v5':
# mosaic augment from YOLOv5
image_data, box_data = random_mosaic_augment_v5(image_data, box_data, prob=0.2)
#image_data, box_data = random_mosaic_augment_v5(image_data, box_data, prob=0.2)

y_true_data = get_y_true_data(box_data, anchors, input_shape, num_classes, multi_anchor_assign)

Expand Down
4 changes: 3 additions & 1 deletion yolo2/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
create YOLOv2 models with different backbone & head
"""
import os
import warnings
import tensorflow.keras.backend as K
from tensorflow.keras.layers import Input, Lambda
Expand All @@ -21,14 +22,15 @@

from common.model_utils import add_metrics, get_pruning_model

ROOT_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')

# A map of model type to construction info list for YOLOv2
#
# info list format:
# [model_function, backbone_length, pretrain_weight_path]
#
yolo2_model_map = {
'yolo2_darknet': [yolo2_body, 60, 'weights/darknet19.h5'],
'yolo2_darknet': [yolo2_body, 60, os.path.join(ROOT_PATH, 'weights', 'darknet19.h5')],
'yolo2_mobilenet': [yolo2_mobilenet_body, 87, None],
'yolo2_mobilenet_lite': [yolo2lite_mobilenet_body, 87, None],
'yolo2_mobilenetv2': [yolo2_mobilenetv2_body, 155, None],
Expand Down
8 changes: 4 additions & 4 deletions yolo3/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ def __getitem__(self, index):
if self.enhance_augment == 'mosaic':
# add random mosaic augment on batch ground truth data
image_data, box_data = random_mosaic_augment(image_data, box_data, prob=0.2)
elif self.enhance_augment == 'mosaic_v5':
#elif self.enhance_augment == 'mosaic_v5':
# mosaic augment from YOLOv5
image_data, box_data = random_mosaic_augment_v5(image_data, box_data, prob=0.2)
#image_data, box_data = random_mosaic_augment_v5(image_data, box_data, prob=0.2)

y_true = preprocess_true_boxes(box_data, self.input_shape, self.anchors, self.num_classes, self.multi_anchor_assign)

Expand Down Expand Up @@ -276,9 +276,9 @@ def yolo3_data_generator(annotation_lines, batch_size, input_shape, anchors, num
if enhance_augment == 'mosaic':
# add random mosaic augment on batch ground truth data
image_data, box_data = random_mosaic_augment(image_data, box_data, prob=0.2)
elif enhance_augment == 'mosaic_v5':
#elif enhance_augment == 'mosaic_v5':
# mosaic augment from YOLOv5
image_data, box_data = random_mosaic_augment_v5(image_data, box_data, prob=0.2)
#image_data, box_data = random_mosaic_augment_v5(image_data, box_data, prob=0.2)

y_true = preprocess_true_boxes(box_data, input_shape, anchors, num_classes, multi_anchor_assign)
yield [image_data, *y_true], np.zeros(batch_size)
Expand Down
32 changes: 17 additions & 15 deletions yolo3/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
create YOLOv3/v4 models with different backbone & head
"""
import os
import warnings
from functools import partial

Expand All @@ -22,7 +23,7 @@
from yolo3.models.yolo3_mobilenetv3_large import yolo3_mobilenetv3large_body, yolo3lite_mobilenetv3large_body, tiny_yolo3_mobilenetv3large_body, tiny_yolo3lite_mobilenetv3large_body
from yolo3.models.yolo3_mobilenetv3_small import yolo3_mobilenetv3small_body, yolo3lite_mobilenetv3small_body, tiny_yolo3_mobilenetv3small_body, tiny_yolo3lite_mobilenetv3small_body, yolo3_ultralite_mobilenetv3small_body, tiny_yolo3_ultralite_mobilenetv3small_body
from yolo3.models.yolo3_peleenet import yolo3_peleenet_body, yolo3lite_peleenet_body, tiny_yolo3_peleenet_body, tiny_yolo3lite_peleenet_body, yolo3_ultralite_peleenet_body, tiny_yolo3_ultralite_peleenet_body
from yolo3.models.yolo3_resnet50 import yolo3_resnet50_body, yolo3lite_resnet50_body, yolo3lite_spp_resnet50_body, tiny_yolo3_resnet50_body, tiny_yolo3lite_resnet50_body
#from yolo3.models.yolo3_resnet50 import yolo3_resnet50_body, yolo3lite_resnet50_body, yolo3lite_spp_resnet50_body, tiny_yolo3_resnet50_body, tiny_yolo3lite_resnet50_body
#from yolo3.models.yolo3_resnet50v2 import yolo3_resnet50v2_body, yolo3lite_resnet50v2_body, yolo3lite_spp_resnet50v2_body, tiny_yolo3_resnet50v2_body, tiny_yolo3lite_resnet50v2_body


Expand All @@ -33,14 +34,15 @@
from yolo4.models.yolo4_mobilenetv3_large import yolo4_mobilenetv3large_body, yolo4lite_mobilenetv3large_body, tiny_yolo4_mobilenetv3large_body, tiny_yolo4lite_mobilenetv3large_body
from yolo4.models.yolo4_mobilenetv3_small import yolo4_mobilenetv3small_body, yolo4lite_mobilenetv3small_body, tiny_yolo4_mobilenetv3small_body, tiny_yolo4lite_mobilenetv3small_body
from yolo4.models.yolo4_efficientnet import yolo4_efficientnet_body, yolo4lite_efficientnet_body, tiny_yolo4_efficientnet_body, tiny_yolo4lite_efficientnet_body
from yolo4.models.yolo4_resnet50 import yolo4_resnet50_body, yolo4lite_resnet50_body, tiny_yolo4_resnet50_body, tiny_yolo4lite_resnet50_body
#from yolo4.models.yolo4_resnet50 import yolo4_resnet50_body, yolo4lite_resnet50_body, tiny_yolo4_resnet50_body, tiny_yolo4lite_resnet50_body
#from yolo4.models.yolo4_resnet50v2 import yolo4_resnet50v2_body, yolo4lite_resnet50v2_body, tiny_yolo4_resnet50v2_body, tiny_yolo4lite_resnet50v2_body

from yolo3.loss import yolo3_loss
from yolo3.postprocess import batched_yolo3_postprocess, batched_yolo3_prenms, Yolo3PostProcessLayer

from common.model_utils import add_metrics, get_pruning_model

ROOT_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')

# A map of model type to construction info list for YOLOv3
#
Expand All @@ -66,9 +68,9 @@
'yolo3_peleenet_lite': [yolo3lite_peleenet_body, 366, None],
'yolo3_peleenet_ultralite': [yolo3_ultralite_peleenet_body, 366, None],

'yolo3_resnet50': [yolo3_resnet50_body, 175, None],
'yolo3_resnet50_lite': [yolo3lite_resnet50_body, 175, None],
'yolo3_resnet50_lite_spp': [yolo3lite_spp_resnet50_body, 175, None],
#'yolo3_resnet50': [yolo3_resnet50_body, 175, None],
#'yolo3_resnet50_lite': [yolo3lite_resnet50_body, 175, None],
#'yolo3_resnet50_lite_spp': [yolo3lite_spp_resnet50_body, 175, None],

#'yolo3_resnet50v2': [yolo3_resnet50v2_body, 190, None],
#'yolo3_resnet50v2_lite': [yolo3lite_resnet50v2_body, 190, None],
Expand All @@ -84,8 +86,8 @@
'yolo3_efficientnet_lite': [yolo3lite_efficientnet_body, 382, None],
'yolo3_efficientnet_lite_spp': [yolo3lite_spp_efficientnet_body, 382, None],

'yolo3_darknet': [yolo3_body, 185, 'weights/darknet53.h5'],
'yolo3_darknet_spp': [custom_yolo3_spp_body, 185, 'weights/yolov3-spp.h5'],
'yolo3_darknet': [yolo3_body, 185, os.path.join(ROOT_PATH, 'weights', 'darknet53.h5')],
'yolo3_darknet_spp': [custom_yolo3_spp_body, 185, os.path.join(ROOT_PATH, 'weights', 'yolov3-spp.h5')],
#Doesn't have pretrained weights, so no need to return backbone length
'yolo3_darknet_lite': [yolo3lite_body, 0, None],
'yolo3_vgg16': [yolo3_vgg16_body, 19, None],
Expand All @@ -95,7 +97,7 @@

'yolo3_nano': [yolo3_nano_body, 268, None],

'yolo4_darknet': [yolo4_body, 250, 'weights/cspdarknet53.h5'],
'yolo4_darknet': [yolo4_body, 250, os.path.join(ROOT_PATH, 'weights', 'cspdarknet53.h5')],
'yolo4_mobilenet': [yolo4_mobilenet_body, 87, None],
'yolo4_mobilenet_lite': [yolo4lite_mobilenet_body, 87, None],

Expand All @@ -107,8 +109,8 @@
'yolo4_mobilenetv3small': [yolo4_mobilenetv3small_body, 166, None],
'yolo4_mobilenetv3small_lite': [yolo4lite_mobilenetv3small_body, 166, None],

'yolo4_resnet50': [yolo4_resnet50_body, 175, None],
'yolo4_resnet50_lite': [yolo4lite_resnet50_body, 175, None],
#'yolo4_resnet50': [yolo4_resnet50_body, 175, None],
#'yolo4_resnet50_lite': [yolo4lite_resnet50_body, 175, None],

#'yolo4_resnet50v2': [yolo4_resnet50v2_body, 190, None],
#'yolo4_resnet50v2_lite': [yolo4lite_resnet50v2_body, 190, None],
Expand Down Expand Up @@ -143,8 +145,8 @@
'tiny_yolo3_peleenet_lite': [tiny_yolo3lite_peleenet_body, 366, None],
'tiny_yolo3_peleenet_ultralite': [tiny_yolo3_ultralite_peleenet_body, 366, None],

'tiny_yolo3_resnet50': [tiny_yolo3_resnet50_body, 175, None],
'tiny_yolo3_resnet50_lite': [tiny_yolo3lite_resnet50_body, 175, None],
#'tiny_yolo3_resnet50': [tiny_yolo3_resnet50_body, 175, None],
#'tiny_yolo3_resnet50_lite': [tiny_yolo3lite_resnet50_body, 175, None],

#'tiny_yolo3_resnet50v2': [tiny_yolo3_resnet50v2_body, 190, None],
#'tiny_yolo3_resnet50v2_lite': [tiny_yolo3lite_resnet50v2_body, 190, None],
Expand All @@ -157,7 +159,7 @@
'tiny_yolo3_efficientnet': [tiny_yolo3_efficientnet_body, 235, None],
'tiny_yolo3_efficientnet_lite': [tiny_yolo3lite_efficientnet_body, 235, None],

'tiny_yolo3_darknet': [custom_tiny_yolo3_body, 20, 'weights/yolov3-tiny.h5'],
'tiny_yolo3_darknet': [custom_tiny_yolo3_body, 20, os.path.join(ROOT_PATH, 'weights', 'yolov3-tiny.h5')],
#Doesn't have pretrained weights, so no need to return backbone length
'tiny_yolo3_darknet_lite': [tiny_yolo3lite_body, 0, None],
'tiny_yolo3_vgg16': [tiny_yolo3_vgg16_body, 19, None],
Expand All @@ -179,8 +181,8 @@
'tiny_yolo4_mobilenetv3small_lite': [tiny_yolo4lite_mobilenetv3small_body, 166, None],
'tiny_yolo4_mobilenetv3small_lite_nospp': [partial(tiny_yolo4lite_mobilenetv3small_body, use_spp=False), 166, None],

'tiny_yolo4_resnet50': [tiny_yolo4_resnet50_body, 175, None],
'tiny_yolo4_resnet50_lite': [tiny_yolo4lite_resnet50_body, 175, None],
#'tiny_yolo4_resnet50': [tiny_yolo4_resnet50_body, 175, None],
#'tiny_yolo4_resnet50_lite': [tiny_yolo4lite_resnet50_body, 175, None],

#'tiny_yolo4_resnet50v2': [tiny_yolo4_resnet50v2_body, 190, None],
#'tiny_yolo4_resnet50v2_lite': [tiny_yolo4lite_resnet50v2_body, 190, None],
Expand Down
8 changes: 4 additions & 4 deletions yolo5/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ def __getitem__(self, index):
if self.enhance_augment == 'mosaic':
# add random mosaic augment on batch ground truth data
image_data, box_data = random_mosaic_augment(image_data, box_data, prob=0.2)
elif self.enhance_augment == 'mosaic_v5':
#elif self.enhance_augment == 'mosaic_v5':
# mosaic augment from YOLOv5
image_data, box_data = random_mosaic_augment_v5(image_data, box_data, prob=0.2)
#image_data, box_data = random_mosaic_augment_v5(image_data, box_data, prob=0.2)

y_true = preprocess_true_boxes(box_data, self.input_shape, self.anchors, self.num_classes, self.multi_anchor_assign)

Expand Down Expand Up @@ -203,9 +203,9 @@ def yolo5_data_generator(annotation_lines, batch_size, input_shape, anchors, num
if enhance_augment == 'mosaic':
# add random mosaic augment on batch ground truth data
image_data, box_data = random_mosaic_augment(image_data, box_data, prob=0.2)
elif enhance_augment == 'mosaic_v5':
#elif enhance_augment == 'mosaic_v5':
# mosaic augment from YOLOv5
image_data, box_data = random_mosaic_augment_v5(image_data, box_data, prob=0.2)
#image_data, box_data = random_mosaic_augment_v5(image_data, box_data, prob=0.2)

y_true = preprocess_true_boxes(box_data, input_shape, anchors, num_classes, multi_anchor_assign)
yield [image_data, *y_true], np.zeros(batch_size)
Expand Down

0 comments on commit c15b8a2

Please sign in to comment.