コード例 #1
0
ファイル: efficientdet.py プロジェクト: wavce/letsdet
    def __init__(self, model_name="efficientdet-d0", image_size=None, **kwargs):
        super(EfficientDet, self).__init__(**kwargs)
        cfg = build_configs(model_name)

        self.input_size = cfg.input_size if image_size is None else image_size
        cfg.override(dict(image_size=self.input_size))
       
        self.model = build_detector(cfg.detector, cfg=cfg).model
        
        self.nms = build_nms("combined_non_max_suppression", 
                             pre_nms_size=cfg.postprocess.pre_nms_size,
                             post_nms_size=cfg.postprocess.post_nms_size,
                             iou_threshold=cfg.postprocess.iou_threshold,
                             score_threshold=cfg.postprocess.score_threshold,
                             num_classes=cfg.num_classes)
        self.delta2box = Delta2Box(mean=cfg.bbox_mean, std=cfg.bbox_std)
        self.aspect_ratios = cfg.anchor.aspect_ratios
        self.anchor_scales = cfg.anchor.scales
        # base_scale = cfg.anchor_scale
        # strides = [8, 16, 32, 64, 128]
        # self.anchor_scales = [[2 ** (i / 3) * s * base_scale for i in range(3)] for s in strides]
        # anchors_configs = _generate_anchor_configs(3, 7, 3, [(1.0, 1.0), (1.4, 0.7), (0.7, 1.4)])
        # anchors = _generate_anchor_boxes(self.input_size, 4, anchors_configs)
 
        # self.anchors = tf.convert_to_tensor([anchors], tf.float32)
        # self.normalizer = tf.convert_to_tensor(
        #     [[[self.input_size[0], self.input_size[1], self.input_size[0], self.input_size[1]]]], tf.float32)
        self.anchor_generator = AnchorGenerator()
コード例 #2
0
    def __init__(self, image_size=None, **kwargs):
        super(EfficientDet, self).__init__(**kwargs)
        cfg = build_configs("efficientdet")

        self.input_size = cfg.val.dataset.input_size if image_size is None else image_size
        self.model = build_detector(cfg.detector, cfg=cfg).model

        self.nms = build_nms("combined_non_max_suppression",
                             pre_nms_size=5000,
                             post_nms_size=100,
                             iou_threshold=0.5,
                             score_threshold=0.2,
                             num_classes=90)
        self.delta2box = Delta2Box(mean=None, std=None)
        self.aspect_ratios = [1., 0.5, 2.]
        base_scale = 4
        strides = [8, 16, 32, 64, 128]
        self.anchor_scales = [[2**(i / 3) * s * base_scale for i in range(3)]
                              for s in strides]
        anchors_configs = _generate_anchor_configs(3, 7, 3, [(1.0, 1.0),
                                                             (1.4, 0.7),
                                                             (0.7, 1.4)])
        anchors = _generate_anchor_boxes(self.input_size, 4, anchors_configs)

        # self.anchors = tf.convert_to_tensor([anchors], tf.float32)
        # self.normalizer = tf.convert_to_tensor(
        #     [[[self.input_size[0], self.input_size[1], self.input_size[0], self.input_size[1]]]], tf.float32)
        self.anchor_generator = AnchorGenerator()
コード例 #3
0
def main(_):
    # logger = tf.get_logger()
    # logger.setLevel(logging.DEBUG)

    # tf.random.set_seed(2333)
    tf.config.optimizer.set_jit(True)
    # tf.config.optimizer.set_experimental_options()
    # tf.debugging.enable_check_numerics()

    physical_devices = tf.config.experimental.list_physical_devices("GPU")
    for device in physical_devices:
        tf.config.experimental.set_memory_growth(device, True)

    if FLAGS.multi_gpu_training:
        trainer = MultiGPUTrainer(build_configs(FLAGS.name))
    else:
        trainer = SingleGPUTrainer(build_configs(FLAGS.name))

    trainer.run()
コード例 #4
0
ファイル: train.py プロジェクト: wavce/letsdet
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--detector",
        type=str,
        default="CenterNet",
        help="The detector name, e.g.`efficientdet`, `efficient_fcos`.")
    parser.add_argument(
        "--gpus",
        type=str,
        default="0,1,2,3",
        help="Use multi-gpu training or not, default False, means use one gpu."
    )
    parser.add_argument("--cfg",
                        type=str,
                        default=None,
                        help="The conifg file (yaml), if None, using default.")
    parser.add_argument("--num_classes",
                        type=int,
                        default=80,
                        help="The number of classes, default 80 (COCO).")

    args = parser.parse_args()

    os.environ["CUDA_VISIBLE_DEVICES"] = args.gpus

    tf.random.set_seed(2333)
    # tf.config.optimizer.set_jit(True)

    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    logging.basicConfig(format="%(asctime)s %(levelname)s - %(message)s",
                        datefmt="%Y-%m-%d %H:%M:%S")

    physical_devices = tf.config.experimental.list_physical_devices("GPU")
    for device in physical_devices:
        tf.config.experimental.set_memory_growth(device, True)

    if args.cfg is None:
        cfg = build_configs(args.detector)(args.num_classes)
    else:
        cfg = Config()
        cfg.parse_from_yaml(args.cfg)

    num_gpus = len(args.gpus.strip().split(","))
    if num_gpus > 1:
        trainer = MultiGPUTrainer(cfg=cfg, logger=logger)
    else:
        trainer = SingleGPUTrainer(cfg=cfg, logger=logger)

    trainer.run()
コード例 #5
0
ファイル: export_saved_model.py プロジェクト: wavce/letsdet
                    help="The kernel type of MatrixNMS.")
parser.add_argument("--nms_sigma",
                    default=2.0,
                    type=float,
                    help="The sigma for MatrixNMS or SoftNMS.")
parser.add_argument(
    "--nms_type",
    type=str,
    default=None,
    help=
    "If [--nms] is NonMaxSuppressionWithQuality, the [--nms_type] is necessary."
)

args = parser.parse_args()

cfg = build_configs(args.detector)

if args.config is None:
    cfg.test.nms = args.nms
    cfg.test.iou_threshold = args.iou_threshold
    cfg.test.score_threshold = args.score_threshold
    cfg.test.pre_nms_size = args.pre_nms_size
    cfg.test.post_nms_size = args.post_nms_size

    if args.nms == "MatrixNonMaxSuppression":
        cfg.test.update_threshold = args.update_threshold
        cfg.test.kernel = args.nms_kernel

    if args.nms == "NonMaxSuppressionWithQuality":
        assert args.nms_type is not None, "When [--nms] is `NonMaxSuppressionWithQuality`, [--nms_type] is necessary."
コード例 #6
0
import argparse
import tensorflow as tf
from models import build_model
from configs import build_configs
from core import build_optimizer

parser = argparse.ArgumentParser()
parser.add_argument("--model", required=True, type=str)
parser.add_argument("--ckpt_dir", default=None, type=str)
parser.add_argument("--num_classes", default=None, type=int)
parser.add_argument("--use_sigmoid", default=None, type=bool)
parser.add_argument("--saved_model_dir", required=True, type=str)

args = parser.parse_args()

cfg = build_configs(args.model)
if args.num_classes is not None:
    cfg.num_classes = args.num_classes
    cfg.model.num_classes = args.num_classes

if args.ckpt_dir is not None:
    cfg.checkpoint_dir = args.ckpt_dir

if args.use_sigmoid is not None:
    cfg.use_sigmoid = args.use_sigmoid
if cfg.num_classes == 1:
    cfg.use_sigmoid = True

base_model = build_model(**cfg.model.as_dict())

x = base_model.output