Python gluoncv.model_zoo.get_model() Examples
The following are 20
code examples of gluoncv.model_zoo.get_model().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gluoncv.model_zoo
, or try the search function
.
Example #1
Source File: oth_centernet2.py From imgclsmob with MIT License | 7 votes |
def __init__(self, base_network='resnet18_v1b', deconv_filters=(256, 128, 64), deconv_kernels=(4, 4, 4), pretrained_backbone=True, in_channels=3, **kwargs): super(DeconvResnet, self).__init__(**kwargs) assert 'resnet' in base_network from gluoncv.model_zoo import get_model net = get_model(base_network, pretrained=pretrained_backbone) feat = nn.HybridSequential() feat.add(*[net.conv1, net.bn1, net.relu, net.maxpool, net.layer1, net.layer2, net.layer3, net.layer4]) self.base_network = feat with self.name_scope(): self.deconv = self._make_deconv_layer(deconv_filters, deconv_kernels)
Example #2
Source File: oth_simple_pose_resnet.py From imgclsmob with MIT License | 5 votes |
def oth_mobilenet_v2_0_25(pretrained=False, **kwargs): if "in_channels" in kwargs: del kwargs["in_channels"] from gluoncv.model_zoo import get_model net = get_model( 'mobilenetv2_0.25', pretrained=pretrained, **kwargs) net.in_size = (224, 224) return net
Example #3
Source File: test.py From alpr_utils with GNU General Public License v3.0 | 5 votes |
def test(images, dims, threshold, plt_hw, seq_len, no_yolo, beam, beam_size, context): print("Loading model...") if not no_yolo: yolo = model_zoo.get_model('yolo3_darknet53_voc', pretrained=True, ctx=context) wpod = WpodNet() wpod.load_parameters("model/wpod_net.params", ctx=context) vocab = Vocabulary() vocab.load("model/vocabulary.json") ocr = OcrNet(plt_hw, vocab.size(), seq_len) ocr.load_parameters("model/ocr_net.params", ctx=context) for path in images: print(path) raw = load_image(path) if no_yolo: detect_plate(wpod, vocab, ocr, raw, dims, threshold, plt_hw, beam, beam_size, context) else: ts = time.time() x, _ = data.transforms.presets.yolo.transform_test(raw, short=512) classes, scores, bboxes = yolo(x.as_in_context(context)) bboxes[0, :, 0::2] = bboxes[0, :, 0::2] / x.shape[3] * raw.shape[1] bboxes[0, :, 1::2] = bboxes[0, :, 1::2] / x.shape[2] * raw.shape[0] vehicles = [ fixed_crop(raw, bboxes[0, i]) for i in range(classes.shape[1]) if (yolo.classes[int(classes[0, i].asscalar())] == 'car' or yolo.classes[int(classes[0, i].asscalar())] == 'bus') and scores[0, i].asscalar() > 0.5 ] print("yolo profiling: %f" % (time.time() - ts)) for i, raw in enumerate(vehicles): print("vehicle[%d]:" % i) detect_plate(wpod, vocab, ocr, raw, dims, threshold, plt_hw, beam, beam_size, context)
Example #4
Source File: imagenet_gen_qsym_mkldnn.py From training_results_v0.6 with Apache License 2.0 | 5 votes |
def convert_from_gluon(model_name, image_shape, classes=1000, logger=None): dir_path = os.path.dirname(os.path.realpath(__file__)) model_path = os.path.join(dir_path, 'model') if logger is not None: logger.info('Converting model from Gluon-CV ModelZoo %s... into path %s' % (model_name, model_path)) net = get_model(name=model_name, classes=classes, pretrained=True) net.hybridize() x = mx.sym.var('data') y = net(x) y = mx.sym.SoftmaxOutput(data=y, name='softmax') symnet = mx.symbol.load_json(y.tojson()) params = net.collect_params() args = {} auxs = {} for param in params.values(): v = param._reduce() k = param.name if 'running' in k: auxs[k] = v else: args[k] = v mod = mx.mod.Module(symbol=symnet, context=mx.cpu(), label_names = ['softmax_label']) mod.bind(for_training=False, data_shapes=[('data', (1,) + tuple([int(i) for i in image_shape.split(',')]))]) mod.set_params(arg_params=args, aux_params=auxs) dst_dir = os.path.join(dir_path, 'model') prefix = os.path.join(dir_path, 'model', model_name) if not os.path.isdir(dst_dir): os.mkdir(dst_dir) mod.save_checkpoint(prefix, 0) return prefix
Example #5
Source File: oth_mobile_pose.py From imgclsmob with MIT License | 5 votes |
def __init__(self, base_name, base_attrs=('features',), num_joints=17, fixed_size=True, pretrained_base=False, pretrained_ctx=cpu(), in_channels=3, in_size=(256, 192), **kwargs): super(MobilePose, self).__init__(**kwargs) assert (in_channels == 3) self.in_size = in_size with self.name_scope(): from gluoncv.model_zoo import get_model base_model = get_model(base_name, pretrained=pretrained_base, ctx=pretrained_ctx) self.features = nn.HybridSequential() if base_name.startswith('mobilenetv2'): self.features.add(base_model.features[:-1]) elif base_name.startswith('mobilenetv3'): self.features.add(base_model.features[:-4]) elif base_name.startswith('mobilenet'): self.features.add(base_model.features[:-2]) else: for layer in base_attrs: self.features.add(getattr(base_model, layer)) self.upsampling = nn.HybridSequential() self.upsampling.add( nn.Conv2D(256, 1, 1, 0, use_bias=False), DUC(512, 2), DUC(256, 2), DUC(128, 2), nn.Conv2D(num_joints, 1, use_bias=False, weight_initializer=initializer.Normal(0.001)), )
Example #6
Source File: oth_centernet.py From imgclsmob with MIT License | 5 votes |
def __init__(self, base_network='resnet18_v1b', deconv_filters=(256, 128, 64), deconv_kernels=(4, 4, 4), pretrained_base=True, norm_layer=nn.BatchNorm, norm_kwargs=None, use_dcnv2=False, in_channels=3, classes=1000, **kwargs): super(DeconvResnet, self).__init__(**kwargs) assert 'resnet' in base_network from gluoncv.model_zoo import get_model net = get_model(base_network, pretrained=pretrained_base) self._norm_layer = norm_layer self._norm_kwargs = norm_kwargs if norm_kwargs is not None else {} self._use_dcnv2 = use_dcnv2 if 'v1b' in base_network: feat = nn.HybridSequential() feat.add(*[net.conv1, net.bn1, net.relu, net.maxpool, net.layer1, net.layer2, net.layer3, net.layer4]) self.base_network = feat else: raise NotImplementedError() with self.name_scope(): self.deconv = self._make_deconv_layer(deconv_filters, deconv_kernels)
Example #7
Source File: faster_rcnn.py From dgl with Apache License 2.0 | 5 votes |
def reset_class(self, classes, reuse_weights=None): """Reset class categories and class predictors. Parameters ---------- classes : iterable of str The new categories. ['apple', 'orange'] for example. reuse_weights : dict A {new_integer : old_integer} or mapping dict or {new_name : old_name} mapping dict, or a list of [name0, name1,...] if class names don't change. This allows the new predictor to reuse the previously trained weights specified. Example ------- >>> net = gluoncv.model_zoo.get_model('faster_rcnn_resnet50_v1b_coco', pretrained=True) >>> # use direct name to name mapping to reuse weights >>> net.reset_class(classes=['person'], reuse_weights={'person':'person'}) >>> # or use interger mapping, person is the 14th category in VOC >>> net.reset_class(classes=['person'], reuse_weights={0:14}) >>> # you can even mix them >>> net.reset_class(classes=['person'], reuse_weights={'person':14}) >>> # or use a list of string if class name don't change >>> net.reset_class(classes=['person'], reuse_weights=['person']) """ super(FasterRCNN, self).reset_class(classes, reuse_weights) self._target_generator = RCNNTargetGenerator(self.num_class, self.sampler._max_pos, self._batch_size)
Example #8
Source File: oth_simple_pose_resnet.py From imgclsmob with MIT License | 5 votes |
def oth_mobilenet_v2_0_5(pretrained=False, **kwargs): if "in_channels" in kwargs: del kwargs["in_channels"] from gluoncv.model_zoo import get_model net = get_model( 'mobilenetv2_0.5', pretrained=pretrained, **kwargs) net.in_size = (224, 224) return net
Example #9
Source File: oth_simple_pose_resnet.py From imgclsmob with MIT License | 5 votes |
def oth_mobilenet_v2_1_0(pretrained=False, **kwargs): if "in_channels" in kwargs: del kwargs["in_channels"] from gluoncv.model_zoo import get_model net = get_model( 'mobilenetv2_1.0', pretrained=pretrained, **kwargs) net.in_size = (224, 224) return net
Example #10
Source File: oth_simple_pose_resnet.py From imgclsmob with MIT License | 5 votes |
def oth_resnet152_v1d(pretrained=False, **kwargs): from gluoncv.model_zoo import get_model net = get_model( 'resnet152_v1d', pretrained=pretrained, **kwargs) net.in_size = (224, 224) return net
Example #11
Source File: oth_simple_pose_resnet.py From imgclsmob with MIT License | 5 votes |
def oth_resnet101_v1d(pretrained=False, **kwargs): from gluoncv.model_zoo import get_model net = get_model( 'resnet101_v1d', pretrained=pretrained, **kwargs) net.in_size = (224, 224) return net
Example #12
Source File: oth_simple_pose_resnet.py From imgclsmob with MIT License | 5 votes |
def oth_resnet50_v1d(pretrained=False, **kwargs): from gluoncv.model_zoo import get_model net = get_model( 'resnet50_v1d', pretrained=pretrained, **kwargs) net.in_size = (224, 224) return net
Example #13
Source File: test.py From gluon-cv with Apache License 2.0 | 5 votes |
def main(): """SiamRPN test. function ---------- record the output of the model. The output information of each video is recorded in the txt corresponding to the video name. if you want to evaluation, you need to python benchmark.py according to txt of text result. Currently only supports test OTB 2015 dataset Parameters ---------- dataset_root : str, default '~/mxnet/datasets/OTB2015' Path to folder test the dataset. model_path : str, Path of test model . results_path: str, Path to store txt of test reslut . """ opt = parse_args() if opt.use_gpu: ctx = mx.gpu() else: ctx = mx.cpu() # dataloader dataset = OTBDataset(name=opt.dataset, dataset_root=opt.dataset_root, load_img=False) net = get_model(opt.model_name, pretrained=True) net.collect_params().reset_ctx(ctx) if opt.mode == 'hybrid': net.hybridize(static_alloc=True, static_shape=True) if opt.model_path: net.load_parameters(opt.model_path, ctx=ctx) print('Pre-trained model %s is successfully loaded.' % (opt.model_path)) else: print('Pre-trained model is successfully loaded from the model zoo.') # bulid tracker tracker = build_tracker(net) # record the output of the model. test(dataset, tracker, opt, ctx)
Example #14
Source File: oth_simple_pose_resnet.py From imgclsmob with MIT License | 4 votes |
def __init__(self, base_name='resnet50_v1b', pretrained_base=False, pretrained_ctx=cpu(), num_joints=17, num_deconv_layers=3, num_deconv_filters=(256, 256, 256), num_deconv_kernels=(4, 4, 4), final_conv_kernel=1, deconv_with_bias=False, in_channels=3, in_size=(256, 192), **kwargs): super(SimplePoseResNet, self).__init__(**kwargs) assert (in_channels == 3) self.in_size = in_size from gluoncv.model_zoo import get_model base_network = get_model( base_name, pretrained=pretrained_base, ctx=pretrained_ctx, norm_layer=gcv.nn.BatchNormCudnnOff) self.resnet = nn.HybridSequential() if base_name.endswith('v1'): for layer in ['features']: self.resnet.add(getattr(base_network, layer)) else: for layer in ['conv1', 'bn1', 'relu', 'maxpool', 'layer1', 'layer2', 'layer3', 'layer4']: self.resnet.add(getattr(base_network, layer)) self.deconv_with_bias = deconv_with_bias # used for deconv layers self.deconv_layers = self._make_deconv_layer( num_deconv_layers, num_deconv_filters, num_deconv_kernels, ) self.final_layer = nn.Conv2D( channels=num_joints, kernel_size=final_conv_kernel, strides=1, padding=1 if final_conv_kernel == 3 else 0, weight_initializer=initializer.Normal(0.001), bias_initializer=initializer.Zero() )
Example #15
Source File: actionrec_resnetv1b.py From gluon-cv with Apache License 2.0 | 4 votes |
def resnet50_v1b_custom(nclass=400, pretrained=False, pretrained_base=True, use_tsn=False, partial_bn=False, num_segments=1, num_crop=1, root='~/.mxnet/models', ctx=mx.cpu(), use_kinetics_pretrain=True, **kwargs): r"""ResNet50 model customized for any dataset. Parameters ---------- nclass : int. Number of categories in the dataset. pretrained : bool or str. Boolean value controls whether to load the default pretrained weights for model. String value represents the hashtag for a certain version of pretrained weights. pretrained_base : bool or str, optional, default is True. Load pretrained base network, the extra layers are randomized. Note that if pretrained is `True`, this has no effect. ctx : Context, default CPU. The context in which to load the pretrained weights. root : str, default $MXNET_HOME/models Location for keeping the model parameters. num_segments : int, default is 1. Number of segments used to evenly divide a video. num_crop : int, default is 1. Number of crops used during evaluation, choices are 1, 3 or 10. partial_bn : bool, default False. Freeze all batch normalization layers during training except the first layer. use_kinetics_pretrain : bool, default True. Whether to load pretrained weights on Kinetics400 dataset as model initialization. """ model = ActionRecResNetV1b(depth=50, nclass=nclass, partial_bn=partial_bn, num_segments=num_segments, num_crop=num_crop, dropout_ratio=0.5, init_std=0.01) if use_kinetics_pretrain and not pretrained: from gluoncv.model_zoo import get_model kinetics_model = get_model('resnet50_v1b_kinetics400', nclass=400, pretrained=True) source_params = kinetics_model.collect_params() target_params = model.collect_params() assert len(source_params.keys()) == len(target_params.keys()) pretrained_weights = [] for layer_name in source_params.keys(): pretrained_weights.append(source_params[layer_name].data()) for i, layer_name in enumerate(target_params.keys()): if i + 2 == len(source_params.keys()): # skip the last dense layer break target_params[layer_name].set_data(pretrained_weights[i]) model.collect_params().reset_ctx(ctx) return model
Example #16
Source File: test.py From panoptic-fpn-gluon with Apache License 2.0 | 4 votes |
def test(args): # output folder outdir = 'outdir' if not os.path.exists(outdir): os.makedirs(outdir) # image transform input_transform = transforms.Compose([ transforms.ToTensor(), transforms.Normalize([.485, .456, .406], [.229, .224, .225]), ]) # dataset and dataloader if args.eval: testset = get_segmentation_dataset( args.dataset, split='val', mode='testval', transform=input_transform) total_inter, total_union, total_correct, total_label = \ np.int64(0), np.int64(0), np.int64(0), np.int64(0) else: testset = get_segmentation_dataset( args.dataset, split='test', mode='test', transform=input_transform) test_data = gluon.data.DataLoader( testset, args.test_batch_size, shuffle=False, last_batch='keep', batchify_fn=ms_batchify_fn, num_workers=args.workers) # create network if args.model_zoo is not None: model = get_model(args.model_zoo, pretrained=True) else: model = get_segmentation_model(model=args.model, dataset=args.dataset, ctx=args.ctx, backbone=args.backbone, norm_layer=args.norm_layer, norm_kwargs=args.norm_kwargs, aux=args.aux, base_size=args.base_size, crop_size=args.crop_size) # load pretrained weight assert args.resume is not None, '=> Please provide the checkpoint using --resume' if os.path.isfile(args.resume): model.load_parameters(args.resume, ctx=args.ctx) else: raise RuntimeError("=> no checkpoint found at '{}'" \ .format(args.resume)) print(model) evaluator = MultiEvalModel(model, testset.num_class, ctx_list=args.ctx) metric = gluoncv.utils.metrics.SegmentationMetric(testset.num_class) tbar = tqdm(test_data) for i, (data, dsts) in enumerate(tbar): if args.eval: predicts = [pred[0] for pred in evaluator.parallel_forward(data)] targets = [target.as_in_context(predicts[0].context) \ for target in dsts] metric.update(targets, predicts) pixAcc, mIoU = metric.get() tbar.set_description( 'pixAcc: %.4f, mIoU: %.4f' % (pixAcc, mIoU)) else: im_paths = dsts predicts = evaluator.parallel_forward(data) for predict, impath in zip(predicts, im_paths): predict = mx.nd.squeeze(mx.nd.argmax(predict[0], 1)).asnumpy() + \ testset.pred_offset mask = get_color_pallete(predict, args.dataset) outname = os.path.splitext(impath)[0] + '.png' mask.save(os.path.join(outdir, outname))
Example #17
Source File: train.py From panoptic-fpn-gluon with Apache License 2.0 | 4 votes |
def __init__(self, args): self.args = args # image transform input_transform = transforms.Compose([ transforms.ToTensor(), transforms.Normalize([.485, .456, .406], [.229, .224, .225]), ]) # dataset and dataloader data_kwargs = {'transform': input_transform, 'base_size': args.base_size, 'crop_size': args.crop_size} trainset = get_segmentation_dataset( args.dataset, split=args.train_split, mode='train', **data_kwargs) valset = get_segmentation_dataset( args.dataset, split='val', mode='val', **data_kwargs) self.train_data = gluon.data.DataLoader( trainset, args.batch_size, shuffle=True, last_batch='rollover', num_workers=args.workers) self.eval_data = gluon.data.DataLoader(valset, args.test_batch_size, last_batch='rollover', num_workers=args.workers) # create network if args.model_zoo is not None: model = get_model(args.model_zoo, pretrained=True) else: model = get_segmentation_model(model=args.model, dataset=args.dataset, backbone=args.backbone, norm_layer=args.norm_layer, norm_kwargs=args.norm_kwargs, aux=args.aux, crop_size=args.crop_size) model.cast(args.dtype) print(model) self.net = DataParallelModel(model, args.ctx, args.syncbn) self.evaluator = DataParallelModel(SegEvalModel(model), args.ctx) # resume checkpoint if needed if args.resume is not None: if os.path.isfile(args.resume): model.load_parameters(args.resume, ctx=args.ctx) else: raise RuntimeError("=> no checkpoint found at '{}'" \ .format(args.resume)) # create criterion criterion = MixSoftmaxCrossEntropyLoss(args.aux, aux_weight=args.aux_weight) self.criterion = DataParallelCriterion(criterion, args.ctx, args.syncbn) # optimizer and lr scheduling self.lr_scheduler = LRScheduler(mode='poly', base_lr=args.lr, nepochs=args.epochs, iters_per_epoch=len(self.train_data), power=0.9) kv = mx.kv.create(args.kvstore) optimizer_params = {'lr_scheduler': self.lr_scheduler, 'wd':args.weight_decay, 'momentum': args.momentum} if args.dtype == 'float16': optimizer_params['multi_precision'] = True if args.no_wd: for k, v in self.net.module.collect_params('.*beta|.*gamma|.*bias').items(): v.wd_mult = 0.0 self.optimizer = gluon.Trainer(self.net.module.collect_params(), 'sgd', optimizer_params, kvstore = kv) # evaluation metrics self.metric = gluoncv.utils.metrics.SegmentationMetric(trainset.num_class)
Example #18
Source File: infer_imagenet_gpu.py From deeplearning-benchmark with Apache License 2.0 | 4 votes |
def main(): opt = arg_parser() logging.basicConfig(level=logging.INFO) logging.info(opt) batch_size = opt.batch_size classes = 1000 num_gpus = len(opt.num_gpus.split(',')) batch_size *= max(1, num_gpus) context = [mx.gpu(int(i)) for i in opt.num_gpus.split(',')] if num_gpus > 0 else [mx.cpu()] num_workers = opt.num_workers kv = mx.kv.create(opt.kvstore) model_name = opt.model kwargs = {'ctx': context, 'pretrained': opt.use_pretrained, 'classes': classes} if opt.use_rec: val_data, batch_fn = get_data_rec(opt.rec_val, opt.rec_val_idx, batch_size, num_workers) else: val_data, batch_fn = get_data_loader(opt.data_dir, batch_size, num_workers, opt) acc_top1 = mx.metric.Accuracy() acc_top5 = mx.metric.TopKAccuracy(5) net = get_model(model_name, **kwargs) if opt.mode == 'symbolic': data = mx.sym.var('data') if opt.dtype == 'float16': data = mx.sym.Cast(data=data, dtype=np.float16) net.cast(np.float16) out = net(data) if opt.dtype == 'float16': out = mx.sym.Cast(data=out, dtype=np.float32) softmax = mx.sym.SoftmaxOutput(out, name='softmax') mod = mx.mod.Module(softmax, context=context) net.hybridize() if opt.dtype == 'float16': net(mx.nd.random_normal(shape=(1,3,256,256), ctx=context[0], dtype=np.float16)) else: net(mx.nd.random_normal(shape=(1,3,256,256), ctx=context[0])) net.export('preresnet50',0) sym, arg_params, aux_params = mx.model.load_checkpoint('preresnet50',0) mod.bind(data_shapes=val_data.provide_data, label_shapes=val_data.provide_label) mod.set_params(arg_params, aux_params) for count in range(0,10): if count>0: mod.score( eval_data=val_data, eval_metric=mx.metric.Accuracy(), batch_end_callback=mx.callback.Speedometer(batch_size, opt.log_interval) ) else: mod.score( eval_data=val_data, eval_metric=mx.metric.Accuracy() ) else: if opt.mode == 'hybrid': net.hybridize(static_alloc=True, static_shape=True) for cnt in range(0, 10): infer(context, cnt, val_data, batch_fn, opt, net, batch_size, acc_top1, acc_top5)
Example #19
Source File: server.py From alpr_utils with GNU General Public License v3.0 | 4 votes |
def _main(): parser = argparse.ArgumentParser(description="Start a ALPR demo server.") parser.add_argument("--dims", help="set the sample dimentions (default: 208)", type=int, default=208) parser.add_argument("--threshold", help="set the positive threshold (default: 0.9)", type=float, default=0.9) parser.add_argument("--plt_w", help="set the max width of output plate images (default: 144)", type=int, default=144) parser.add_argument("--plt_h", help="set the max height of output plate images (default: 48)", type=int, default=48) parser.add_argument("--seq_len", help="set the max length of output sequences (default: 8)", type=int, default=8) parser.add_argument("--beam_size", help="set the size of beam (default: 5)", type=int, default=5) parser.add_argument("--addr", help="set address of ALPR server (default: 0.0.0.0)", type=str, default="0.0.0.0") parser.add_argument("--port", help="set port of ALPR server (default: 80)", type=int, default=80) parser.add_argument("--device_id", help="select device that the model using (default: 0)", type=int, default=0) parser.add_argument("--gpu", help="using gpu acceleration", action="store_true") args = parser.parse_args() if args.gpu: context = mx.gpu(args.device_id) else: context = mx.cpu(args.device_id) print("This is ALPR demo server", flush=True) wpod = WpodNet() wpod.load_parameters("model/wpod_net.params", ctx=context) vocab = Vocabulary() vocab.load("model/vocabulary.json") ocr = OcrNet((args.plt_h, args.plt_w), vocab.size(), args.seq_len) ocr.load_parameters("model/ocr_net.params", ctx=context) yolo = model_zoo.get_model('yolo3_darknet53_voc', pretrained=True, ctx=context) handler = config_handler( context = context, dims = args.dims, threshold = args.threshold, plt_hw = (args.plt_h, args.plt_w), seq_len = args.seq_len, beam_size = args.beam_size, wpod = wpod, vocab = vocab, ocr = ocr, yolo = yolo ) httpd = http.server.HTTPServer((args.addr, args.port), handler) httpd.serve_forever()
Example #20
Source File: faster_rcnn.py From dgl with Apache License 2.0 | 4 votes |
def faster_rcnn_resnet50_v1b_custom(classes, transfer=None, pretrained_base=True, pretrained=False, **kwargs): r"""Faster RCNN model with resnet50_v1b base network on custom dataset. Parameters ---------- classes : iterable of str Names of custom foreground classes. `len(classes)` is the number of foreground classes. transfer : str or None If not `None`, will try to reuse pre-trained weights from faster RCNN networks trained on other datasets. pretrained : bool or str Boolean value controls whether to load the default pretrained weights for model. String value represents the hashtag for a certain version of pretrained weights. pretrained_base : bool or str Boolean value controls whether to load the default pretrained weights for model. String value represents the hashtag for a certain version of pretrained weights. ctx : Context, default CPU The context in which to load the pretrained weights. root : str, default '~/.mxnet/models' Location for keeping the model parameters. Returns ------- mxnet.gluon.HybridBlock Hybrid faster RCNN network. """ if pretrained: warnings.warn("Custom models don't provide `pretrained` weights, ignored.") if transfer is None: from gluoncv.model_zoo.resnetv1b import resnet50_v1b base_network = resnet50_v1b(pretrained=pretrained_base, dilated=False, use_global_stats=True, **kwargs) features = nn.HybridSequential() top_features = nn.HybridSequential() for layer in ['conv1', 'bn1', 'relu', 'maxpool', 'layer1', 'layer2', 'layer3']: features.add(getattr(base_network, layer)) for layer in ['layer4']: top_features.add(getattr(base_network, layer)) train_patterns = '|'.join(['.*dense', '.*rpn', '.*down(2|3|4)_conv', '.*layers(2|3|4)_conv']) return get_faster_rcnn( name='resnet50_v1b', dataset='custom', pretrained=pretrained, features=features, top_features=top_features, classes=classes, short=600, max_size=1000, train_patterns=train_patterns, nms_thresh=0.7, nms_topk=400, post_nms=100, roi_mode='align', roi_size=(14, 14), strides=16, clip=4.14, rpn_channel=1024, base_size=16, scales=(2, 4, 8, 16, 32), ratios=(0.5, 1, 2), alloc_size=(128, 128), rpn_nms_thresh=0.7, rpn_train_pre_nms=12000, rpn_train_post_nms=2000, rpn_test_pre_nms=6000, rpn_test_post_nms=300, rpn_min_size=16, num_sample=128, pos_iou_thresh=0.5, pos_ratio=0.25, max_num_gt=3000, **kwargs) else: from gluoncv.model_zoo import get_model net = get_model('faster_rcnn_resnet50_v1b_' + str(transfer), pretrained=True, **kwargs) reuse_classes = [x for x in classes if x in net.classes] net.reset_class(classes, reuse_weights=reuse_classes) return net