예제 #1
0
        help='Log directory. Will remove the old one if already exists.',
        default='train_log/maskrcnn')
    parser.add_argument(
        '--config',
        help='A list of KEY=VALUE to overwrite those defined in config.py',
        nargs='+')

    if get_tf_version_tuple() < (1, 6):
        # https://github.com/tensorflow/tensorflow/issues/14657
        logger.warn(
            "TF<1.6 has a bug which may lead to crash in FasterRCNN if you're unlucky."
        )

    args = parser.parse_args()
    if args.config:
        sfx = cfg.update_args(args.config)
        if not args.simple_path:
            args.logdir = os.path.join(args.logdir, sfx)
    #VOC config
    if 'VOC' in cfg.DATA.TRAIN[0]:
        voc_config = [
            'TRAIN.BASE_LR=0.001', 'TRAIN.WARMUP_INIT_LR=0.001',
            'TRAIN.LR_SCHEDULE=[7500,40000]', 'RPN.ANCHOR_SIZES=(8,16,32)',
            'PREPROC.TRAIN_SHORT_EDGE_SIZE=[600, 600]',
            'PREPROC.TEST_SHORT_EDGE_SIZE=600', 'TEST.FRCNN_NMS_THRESH=0.3',
            'TEST.RESULT_SCORE_THRESH=0.0001', 'PREPROC.MAX_SIZE=1000',
            'FRCNN.BATCH_PER_IM=256', 'TRAIN.EVAL_PERIOD=10',
            'DATA.NUM_WORKERS=32'
        ]
        cfg.update_args(voc_config)
        sfx = cfg.update_args(args.config)
예제 #2
0
from tensorpack.tfutils import SmartInit
from tensorpack.tfutils.export import ModelExporter

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--config',
        help="A list of KEY=VALUE to overwrite those defined in config.py",
        nargs='+')
    parser.add_argument('--load',
                        help='load a model for evaluation.',
                        required=True)
    parser.add_argument('--output-pb', help='Save a model to .pb')

    args = parser.parse_args()
    if args.config:
        cfg.update_args(args.config)
    register_coco(cfg.DATA.BASEDIR)  # add COCO datasets to the registry
    register_ic(cfg.DATA.BASEDIR)

    cfg.TEST.RESULT_SCORE_THRESH = cfg.TEST.RESULT_SCORE_THRESH_VIS

    MODEL = ResNetFPNModel() if cfg.MODE_FPN else ResNetC4Model()

    predcfg = PredictConfig(model=MODEL,
                            session_init=SmartInit(args.load),
                            input_names=MODEL.get_inference_tensor_names()[0],
                            output_names=MODEL.get_inference_tensor_names()[1])

    ModelExporter(predcfg).export_compact(args.output_pb, optimize=False)
예제 #3
0
파일: train.py 프로젝트: tobyma/tensorpack
    parser.add_argument('--load', help='load a model for evaluation or training')
    parser.add_argument('--logdir', help='log directory', default='train_log/maskrcnn')
    parser.add_argument('--config', help="A list of KEY=VALUE to overwrite those defined in config.py",
                        nargs='+')
    parser.add_argument('--visualize', action='store_true', help='visualize intermediate results')
    parser.add_argument('--evaluate', help="Run evaluation on COCO. "
                                           "This argument is the path to the output json evaluation file")
    parser.add_argument('--predict', help="Run prediction on a given image. "
                                          "This argument is the path to the input image file")

    if get_tf_version_number() < 1.6:
        # https://github.com/tensorflow/tensorflow/issues/14657
        logger.warn("TF<1.6 has a bug which may lead to crash in FasterRCNN training if you're unlucky.")

    args = parser.parse_args()
    cfg.update_args(args.config)

    MODEL = ResNetFPNModel() if cfg.MODE_FPN else ResNetC4Model()

    if args.visualize or args.evaluate or args.predict:
        assert args.load
        finalize_configs(is_training=False)

        if args.predict or args.visualize:
            cfg.TEST.RESULT_SCORE_THRESH = cfg.TEST.RESULT_SCORE_THRESH_VIS

        if args.visualize:
            assert not cfg.MODE_FPN, "FPN visualize is not supported!"
            visualize(args.load)
        else:
            pred = OfflinePredictor(PredictConfig(