Exemplo n.º 1
0
    def __init__(self,
                 n_fg_class=None,
                 pretrained_model=None,
                 min_size=600,
                 max_size=1000,
                 ratios=[0.5, 1, 2],
                 anchor_scales=[8, 16, 32],
                 vgg_initialW=None,
                 rpn_initialW=None,
                 loc_initialW=None,
                 score_initialW=None,
                 proposal_creator_params={}):
        if n_fg_class is None:
            if pretrained_model not in self._models:
                raise ValueError(
                    'The n_fg_class needs to be supplied as an argument')
            n_fg_class = self._models[pretrained_model]['n_fg_class']

        if loc_initialW is None:
            loc_initialW = chainer.initializers.Normal(0.001)
        if score_initialW is None:
            score_initialW = chainer.initializers.Normal(0.01)
        if rpn_initialW is None:
            rpn_initialW = chainer.initializers.Normal(0.01)
        if vgg_initialW is None and pretrained_model:
            vgg_initialW = chainer.initializers.constant.Zero()

        extractor = VGG16FeatureExtractor(initialW=vgg_initialW)
        rpn = RegionProposalNetwork(
            512,
            512,
            ratios=ratios,
            anchor_scales=anchor_scales,
            feat_stride=self.feat_stride,
            initialW=rpn_initialW,
            proposal_creator_params=proposal_creator_params,
        )
        head = VGG16RoIHead(n_fg_class + 1,
                            roi_size=7,
                            spatial_scale=1. / self.feat_stride,
                            vgg_initialW=vgg_initialW,
                            loc_initialW=loc_initialW,
                            score_initialW=score_initialW)

        super(FasterRCNNVGG16,
              self).__init__(extractor,
                             rpn,
                             head,
                             mean=np.array([122.7717, 115.9465, 102.9801],
                                           dtype=np.float32)[:, None, None],
                             min_size=min_size,
                             max_size=max_size)

        if pretrained_model in self._models:
            path = download_model(self._models[pretrained_model]['url'])
            chainer.serializers.load_npz(path, self)
        elif pretrained_model == 'imagenet':
            self._copy_imagenet_pretrained_vgg16()
        elif pretrained_model:
            chainer.serializers.load_npz(pretrained_model, self)
Exemplo n.º 2
0
    def __init__(
        self,
        n_fg_class=None,
        pretrained_model=None,
        min_size=600,
        max_size=1000,
        ratios=[0.5, 1, 2],
        anchor_scales=[8, 16, 32],
        loc_normalize_mean=(0.0, 0.0, 0.0, 0.0),
        loc_normalize_std=(0.2, 0.2, 0.5, 0.5),
        iter2=True,
        resnet_initialW=None,
        rpn_initialW=None,
        head_initialW=None,
        proposal_creator_params={
            'nms_thresh': 0.7,
            'n_train_pre_nms': 6000,
            'n_train_post_nms': 300,
            'n_test_pre_nms': 6000,
            'n_test_post_nms': 300,
            'force_cpu_nms': False,
            'min_size': 16
        }):
        param, path = utils.prepare_pretrained_model(
            {'n_fg_class': n_fg_class}, pretrained_model, self._models)

        if rpn_initialW is None:
            rpn_initialW = chainer.initializers.Normal(0.01)
        if resnet_initialW is None and pretrained_model:
            resnet_initialW = chainer.initializers.constant.Zero()

        extractor = ResNet101Extractor(initialW=resnet_initialW)
        rpn = RegionProposalNetwork(
            1024,
            512,
            ratios=ratios,
            anchor_scales=anchor_scales,
            feat_stride=self.feat_stride,
            initialW=rpn_initialW,
            proposal_creator_params=proposal_creator_params)
        head = FCISResNet101Head(param['n_fg_class'] + 1,
                                 roi_size=21,
                                 group_size=7,
                                 spatial_scale=1. / self.feat_stride,
                                 loc_normalize_mean=loc_normalize_mean,
                                 loc_normalize_std=loc_normalize_std,
                                 iter2=iter2,
                                 initialW=head_initialW)

        mean = np.array([123.15, 115.90, 103.06], dtype=np.float32)[:, None,
                                                                    None]

        super(FCISResNet101,
              self).__init__(extractor, rpn, head, mean, min_size, max_size,
                             loc_normalize_mean, loc_normalize_std)

        if path:
            chainer.serializers.load_npz(path, self)
Exemplo n.º 3
0
    def __init__(self,
                 n_fg_class=None,
                 pretrained_model=None,
                 min_size=600,
                 max_size=1000,
                 ratios=[0.5, 1, 2],
                 anchor_scales=[8, 16, 32],
                 vgg_initialW=None,
                 rpn_initialW=None,
                 loc_initialW=None,
                 score_initialW=None,
                 proposal_creator_params={}):
        param, path = utils.prepare_pretrained_model(
            {'n_fg_class': n_fg_class}, pretrained_model, self._models)

        if loc_initialW is None:
            loc_initialW = chainer.initializers.Normal(0.001)
        if score_initialW is None:
            score_initialW = chainer.initializers.Normal(0.01)
        if rpn_initialW is None:
            rpn_initialW = chainer.initializers.Normal(0.01)
        if vgg_initialW is None and pretrained_model:
            vgg_initialW = chainer.initializers.constant.Zero()

        extractor = VGG16(initialW=vgg_initialW)
        extractor.pick = 'conv5_3'
        # Delete all layers after conv5_3.
        extractor.remove_unused()
        rpn = RegionProposalNetwork(
            512,
            512,
            ratios=ratios,
            anchor_scales=anchor_scales,
            feat_stride=self.feat_stride,
            initialW=rpn_initialW,
            proposal_creator_params=proposal_creator_params,
        )
        head = VGG16RoIHead(param['n_fg_class'] + 1,
                            roi_size=7,
                            spatial_scale=1. / self.feat_stride,
                            vgg_initialW=vgg_initialW,
                            loc_initialW=loc_initialW,
                            score_initialW=score_initialW)

        super(FasterRCNNVGG16,
              self).__init__(extractor,
                             rpn,
                             head,
                             mean=np.array([122.7717, 115.9465, 102.9801],
                                           dtype=np.float32)[:, None, None],
                             min_size=min_size,
                             max_size=max_size)

        if path == 'imagenet':
            self._copy_imagenet_pretrained_vgg16()
        elif path:
            chainer.serializers.load_npz(path, self)
Exemplo n.º 4
0
 def __init__(self,
              n_fg_class=None,
              pretrained_model=None,
              min_size=800,
              max_size=1024,
              ratios=[0.5, 1, 2],
              anchor_scales=[2, 4, 8, 16, 32],
              initialW=None,
              rpn_initialW=None,
              loc_initialW=None,
              score_initialW=None,
              proposal_creator_params=dict(),
              roi_size=7,
              n_layers=50,
              roi_align=True):
     print("MaskRNNResNet initialization")
     if n_fg_class is None:
         raise ValueError('supply n_fg_class!')
     if loc_initialW is None:
         loc_initialW = chainer.initializers.Normal(0.001)
     if score_initialW is None:
         score_initialW = chainer.initializers.Normal(0.01)
     if rpn_initialW is None:
         rpn_initialW = chainer.initializers.Normal(0.01)
     if initialW is None:  # and pretrained_model:
         print("setting initialW")
         initialW = chainer.initializers.Normal(0.01)
     self.roi_size = roi_size
     if pretrained_model is not None:
         pretrained_model = 'auto'
     extractor = ExtractorResNet(pretrained_model, n_layers=n_layers)
     rpn = RegionProposalNetwork(
         1024,
         1024,
         ratios=ratios,
         anchor_scales=anchor_scales,
         feat_stride=self.feat_stride,
         initialW=rpn_initialW,
         proposal_creator_params=proposal_creator_params,
     )
     head = MaskRCNNHead(n_fg_class + 1,
                         roi_size=self.roi_size,
                         spatial_scale=1. / self.feat_stride,
                         initialW=initialW,
                         loc_initialW=loc_initialW,
                         score_initialW=score_initialW,
                         roi_align=roi_align)
     super(MaskRCNNResNet,
           self).__init__(extractor,
                          rpn,
                          head,
                          mean=np.array([122.7717, 115.9465, 102.9801],
                                        dtype=np.float32)[:, None, None],
                          min_size=min_size,
                          max_size=max_size)
Exemplo n.º 5
0
    def __init__(
            self,
            n_class=81,
            ratios=[0.5, 1, 2],
            anchor_scales=[4, 8, 16, 32],
            n_train_pre_nms=6000,
            n_train_post_nms=300,
            n_test_pre_nms=6000,
            n_test_post_nms=300,
            nms_thresh=0.7,
            rpn_min_size=2,
            group_size=7,
            roi_size=21,
            loc_normalize_mean=(0.0, 0.0, 0.0, 0.0),
            loc_normalize_std=(0.2, 0.2, 0.5, 0.5),
    ):
        proposal_creator_params = {
            'nms_thresh': nms_thresh,
            'n_train_pre_nms': n_train_pre_nms,
            'n_train_post_nms': n_train_post_nms,
            'n_test_pre_nms': n_test_pre_nms,
            'n_test_post_nms': n_test_post_nms,
            'force_cpu_nms': False,
            'min_size': rpn_min_size,
        }

        self.n_class = n_class
        self.loc_normalize_mean = loc_normalize_mean
        self.loc_normalize_std = loc_normalize_std
        spatial_scale = 1. / self.feat_stride

        extractor = ResNet101Extractor()
        rpn = RegionProposalNetwork(
            1024,
            512,
            ratios=ratios,
            anchor_scales=anchor_scales,
            feat_stride=self.feat_stride,
            initialW=chainer.initializers.Normal(0.01),
            proposal_creator_params=proposal_creator_params)
        head = FCISResNet101Head(n_class, 2048, 1024, spatial_scale,
                                 group_size, roi_size, loc_normalize_mean,
                                 loc_normalize_std)

        super(FCISResNet101, self).__init__(extractor, rpn, head)
Exemplo n.º 6
0
    def __init__(
        self,
        n_fg_class=None,
        pretrained_model=None,
        min_size=600,
        max_size=1000,
        ratios=(0.5, 1, 2),
        anchor_scales=(8, 16, 32),
        vgg_initialW=None,
        rpn_initialW=None,
        loc_initialW=None,
        score_initialW=None,
        mask_initialW=None,
        proposal_creator_params=None,
        pooling_func=functions.roi_align_2d,
        roi_size=7,
    ):
        if n_fg_class is None:
            if pretrained_model not in self._models:
                raise ValueError(
                    'The n_fg_class needs to be supplied as an argument')
            n_fg_class = self._models[pretrained_model]['n_fg_class']

        if loc_initialW is None:
            loc_initialW = chainer.initializers.Normal(0.001)
        if score_initialW is None:
            score_initialW = chainer.initializers.Normal(0.01)
        if mask_initialW is None:
            mask_initialW = chainer.initializers.Normal(0.01)
        if rpn_initialW is None:
            rpn_initialW = chainer.initializers.Normal(0.01)
        if vgg_initialW is None and pretrained_model:
            vgg_initialW = chainer.initializers.constant.Zero()

        if proposal_creator_params is None:
            proposal_creator_params = dict(
                n_train_pre_nms=12000,
                n_train_post_nms=2000,
                n_test_pre_nms=6000,
                n_test_post_nms=1000,
                min_size=0,
            )

        extractor = VGG16(initialW=vgg_initialW)
        extractor.pick = 'conv5_3'
        # Delete all layers after conv5_3.
        extractor.remove_unused()
        rpn = RegionProposalNetwork(
            512,
            512,
            ratios=ratios,
            anchor_scales=anchor_scales,
            feat_stride=self.feat_stride,
            initialW=rpn_initialW,
            proposal_creator_params=proposal_creator_params,
        )
        head = VGG16RoIHead(
            n_fg_class + 1,
            roi_size=roi_size,
            spatial_scale=1. / self.feat_stride,
            vgg_initialW=vgg_initialW,
            loc_initialW=loc_initialW,
            score_initialW=score_initialW,
            mask_initialW=mask_initialW,
            pooling_func=pooling_func,
        )

        super(MaskRCNNVGG16,
              self).__init__(extractor,
                             rpn,
                             head,
                             mean=np.array([122.7717, 115.9465, 102.9801],
                                           dtype=np.float32)[:, None, None],
                             min_size=min_size,
                             max_size=max_size)

        if pretrained_model in self._models:
            path = download_model(self._models[pretrained_model]['url'])
            chainer.serializers.load_npz(path, self)
        elif pretrained_model == 'imagenet':
            self._copy_imagenet_pretrained_vgg16()
        elif pretrained_model:
            chainer.serializers.load_npz(pretrained_model, self)
Exemplo n.º 7
0
    def __init__(
        self,
        n_layers,
        n_fg_class=None,
        pretrained_model=None,
        min_size=600,
        max_size=1000,
        mask_loss='softmax',
        ratios=(0.5, 1, 2),
        anchor_scales=(4, 8, 16, 32),
        mean=(123.152, 115.903, 103.063),
        res_initialW=None,
        rpn_initialW=None,
        loc_initialW=None,
        score_initialW=None,
        mask_initialW=None,
        proposal_creator_params=dict(
            min_size=0,
            n_test_pre_nms=6000,
            n_test_post_nms=1000,
        ),
        pooling_func=functions.roi_align_2d,
        rpn_dim=1024,
        roi_size=7,
    ):
        if loc_initialW is None:
            loc_initialW = chainer.initializers.Normal(0.001)
        if score_initialW is None:
            score_initialW = chainer.initializers.Normal(0.01)
        if mask_initialW is None:
            mask_initialW = chainer.initializers.Normal(0.01)
        if rpn_initialW is None:
            rpn_initialW = chainer.initializers.Normal(0.01)
        if res_initialW is None and pretrained_model:
            res_initialW = chainer.initializers.constant.Zero()

        if n_layers == 50:
            extractor = ResNet50Extractor(
                pretrained_model=None if pretrained_model else 'auto',
                remove_layers=['res5', 'fc6'],
            )
        elif n_layers == 101:
            extractor = ResNet101Extractor(
                pretrained_model=None if pretrained_model else 'auto',
                remove_layers=['res5', 'fc6'],
            )
        else:
            raise ValueError

        rpn = RegionProposalNetwork(
            1024,
            rpn_dim,
            ratios=ratios,
            anchor_scales=anchor_scales,
            feat_stride=self.feat_stride,
            initialW=rpn_initialW,
            proposal_creator_params=proposal_creator_params,
        )
        head = ResNetRoIHead(
            n_layers=n_layers,
            n_class=n_fg_class + 1,
            roi_size=roi_size,
            spatial_scale=1. / self.feat_stride,
            res_initialW=res_initialW,
            loc_initialW=loc_initialW,
            score_initialW=score_initialW,
            mask_initialW=mask_initialW,
            pooling_func=pooling_func,
            mask_loss=mask_loss,
        )

        if len(mean) != 3:
            raise ValueError('The mean must be tuple of RGB values.')
        mean = np.asarray(mean, dtype=np.float32)[:, None, None]

        super(MaskRCNNResNet, self).__init__(
            extractor,
            rpn,
            head,
            mean=mean,
            min_size=min_size,
            max_size=max_size,
            mask_loss=mask_loss,
        )

        if pretrained_model:
            chainer.serializers.load_npz(pretrained_model, self)
Exemplo n.º 8
0
    def __init__(self,
                 n_fg_class,
                 n_keypoints=None,
                 pretrained_model=None,
                 min_size=600,
                 max_size=1000,
                 ratios=[0.5, 1, 2],
                 anchor_scales=[8],
                 rpn_initialW=None,
                 loc_initialW=None,
                 score_initialW=None,
                 proposal_creator_params={},
                 backbone='fpn',
                 head_arch='fpn'):
        if n_fg_class is None:
            raise ValueError(
                'The n_fg_class needs to be supplied as an argument')

        if loc_initialW is None:
            loc_initialW = chainer.initializers.Normal(0.001)
        if score_initialW is None:
            score_initialW = chainer.initializers.Normal(0.01)
        if rpn_initialW is None:
            rpn_initialW = chainer.initializers.Normal(0.01)

        if backbone == 'fpn':
            extractor = FeaturePyramidNetwork()
            print('feat_strides:', extractor.feat_strides, 'spatial_scales:',
                  extractor.spatial_scales)
            rpn_in_channels = 256
            rpn_mid_channels = 256  # ??
            rpn = MultilevelRegionProposalNetwork(
                anchor_scales=extractor.anchor_scales,
                feat_strides=extractor.feat_strides)
        elif backbone == 'c4':
            extractor = C4Backbone('auto')
            rpn_in_channels = 1024
            rpn_mid_channels = 516  # ??
            rpn = RegionProposalNetwork(
                1024,
                516,
                ratios=ratios,
                anchor_scales=anchor_scales,
                feat_stride=self.feat_stride,
                initialW=rpn_initialW,
                proposal_creator_params=proposal_creator_params,
            )
        else:
            raise ValueError(
                'select backbone frome fpn or c4: {}'.format(backbone))

        if head_arch == 'res5':
            head = ResnetRoIMaskHead(
                n_fg_class + 1,
                roi_size=7,
                spatial_scale=1. / self.feat_stride,
                loc_initialW=loc_initialW,
                score_initialW=score_initialW,
                mask_initialW=chainer.initializers.Normal(0.01))
            self.predict_mask = True

        elif head_arch == 'light':
            head = LightRoIMaskHead(
                n_fg_class + 1,
                roi_size=7,
                loc_initialW=loc_initialW,
                score_initialW=score_initialW,
                mask_initialW=chainer.initializers.Normal(0.01))
            self.predict_mask = True
        elif head_arch == 'fpn':
            head = FPNRoIMaskHead(
                n_fg_class + 1,
                roi_size_box=7,
                roi_size_mask=14,
                loc_initialW=loc_initialW,
                score_initialW=score_initialW,
                mask_initialW=chainer.initializers.Normal(0.01))
            self.predict_mask = True
        elif head_arch == 'fpn_keypoint':
            if n_keypoints == None:
                raise ValueError(
                    'n_keypoints must be set in keypoint detection')
            head = FPNRoIKeypointHead(
                2,
                n_keypoints,
                roi_size_box=7,
                roi_size_mask=14,
                loc_initialW=loc_initialW,
                score_initialW=score_initialW,
                mask_initialW=chainer.initializers.Normal(0.01))
            self.predict_mask = False
        else:
            raise ValueError(
                'unknown head archtecture specified. {}'.format(head_arch))

        super().__init__(extractor,
                         rpn,
                         head,
                         mean=np.array([122.7717, 115.9465, 102.9801],
                                       dtype=np.float32)[:, None, None],
                         min_size=min_size,
                         max_size=max_size)
Exemplo n.º 9
0
    def __init__(
            self,
            n_layers,
            n_fg_class=None,
            pretrained_model=None,
            min_size=600,
            max_size=1000,
            ratios=[0.5, 1, 2],
            anchor_scales=[8, 16, 32],
            res_initialW=None,
            rpn_initialW=None,
            loc_initialW=None,
            score_initialW=None,
            proposal_creator_params=dict(),
            pooling_func=F.roi_pooling_2d,
    ):
        if n_fg_class is None:
            if pretrained_model not in self._models:
                raise ValueError(
                    'The n_fg_class needs to be supplied as an argument')
            n_fg_class = self._models[pretrained_model]['n_fg_class']

        if loc_initialW is None:
            loc_initialW = chainer.initializers.Normal(0.001)
        if score_initialW is None:
            score_initialW = chainer.initializers.Normal(0.01)
        if rpn_initialW is None:
            rpn_initialW = chainer.initializers.Normal(0.01)
        if res_initialW is None and pretrained_model:
            res_initialW = chainer.initializers.constant.Zero()

        if n_layers == 50:
            self._ResNetLayers = ResNet50Layers
        elif n_layers == 101:
            self._ResNetLayers = ResNet101Layers
        else:
            raise ValueError

        class Extractor(self._ResNetLayers):
            def __init__(self, *args, **kwargs):
                super(Extractor, self).__init__(*args, **kwargs)
                # Remove no need layers to save memory
                self.res5 = chainer.Link()
                self.fc6 = chainer.Link()

            def __call__(self, x):
                pick = 'res4'
                with chainer.using_config('train', False):
                    feat = super(Extractor, self).__call__(x, layers=[pick])
                return feat[pick]

        extractor = Extractor(pretrained_model=None)
        rpn = RegionProposalNetwork(
            1024,
            512,
            ratios=ratios,
            anchor_scales=anchor_scales,
            feat_stride=self.feat_stride,
            initialW=rpn_initialW,
            proposal_creator_params=proposal_creator_params,
        )
        head = ResNetRoIHead(
            n_fg_class + 1,
            roi_size=7,
            spatial_scale=1. / self.feat_stride,
            res_initialW=res_initialW,
            loc_initialW=loc_initialW,
            score_initialW=score_initialW,
            pooling_func=pooling_func,
        )

        super(FasterRCNNResNet,
              self).__init__(extractor,
                             rpn,
                             head,
                             mean=np.array([123.152, 115.903, 103.063],
                                           dtype=np.float32)[:, None, None],
                             min_size=min_size,
                             max_size=max_size)

        if pretrained_model in self._models:
            path = download_model(self._models[pretrained_model]['url'])
            chainer.serializers.load_npz(path, self)
        elif pretrained_model == 'imagenet':
            self._copy_imagenet_pretrained_resnet()
        elif pretrained_model:
            chainer.serializers.load_npz(pretrained_model, self)
    def __init__(
            self,
            n_class=81,
            ratios=[0.5, 1, 2],
            anchor_scales=[4, 8, 16, 32],
            n_train_pre_nms=6000,
            n_train_post_nms=300,
            n_test_pre_nms=6000,
            n_test_post_nms=300,
            nms_thresh=0.7,
            rpn_min_size=2,
            group_size=7,
            roi_size=21,
            loc_normalize_mean=(0.0, 0.0, 0.0, 0.0),
            loc_normalize_std=(0.2, 0.2, 0.5, 0.5),
    ):
        super(FCISResNet101, self).__init__()
        proposal_creator_params = {
            'nms_thresh': nms_thresh,
            'n_train_pre_nms': n_train_pre_nms,
            'n_train_post_nms': n_train_post_nms,
            'n_test_pre_nms': n_test_pre_nms,
            'n_test_post_nms': n_test_post_nms,
            'force_cpu_nms': False,
            'min_size': rpn_min_size,
        }

        self.n_class = n_class
        self.spatial_scale = 1. / self.feat_stride
        self.group_size = group_size
        self.roi_size = roi_size
        self.loc_normalize_mean = loc_normalize_mean
        self.loc_normalize_std = loc_normalize_std

        initialW = chainer.initializers.Normal(0.01)

        with self.init_scope():
            # ResNet
            self.res1 = ResNet101C1()
            self.res2 = ResNet101C2()
            self.res3 = ResNet101C3()
            self.res4 = ResNet101C4()
            self.res5 = ResNet101C5()

            # RPN
            self.rpn = RegionProposalNetwork(
                1024,
                512,
                ratios=ratios,
                anchor_scales=anchor_scales,
                feat_stride=self.feat_stride,
                initialW=initialW,
                proposal_creator_params=proposal_creator_params)

            # PSROI Pooling
            self.psroi_conv1 = L.Convolution2D(2048,
                                               1024,
                                               1,
                                               1,
                                               0,
                                               initialW=initialW)
            self.psroi_conv2 = L.Convolution2D(1024,
                                               group_size * group_size *
                                               self.n_class * 2,
                                               1,
                                               1,
                                               0,
                                               initialW=initialW)
            self.psroi_conv3 = L.Convolution2D(1024,
                                               group_size * group_size * 2 * 4,
                                               1,
                                               1,
                                               0,
                                               initialW=initialW)
Exemplo n.º 11
0
    def __init__(self,
                 n_layers,
                 n_fg_class=None,
                 pretrained_model=None,
                 min_size=600, max_size=1000,
                 ratios=[0.5, 1, 2], anchor_scales=[4, 8, 16, 32],
                 res_initialW=None, rpn_initialW=None,
                 loc_initialW=None, score_initialW=None,
                 proposal_creator_params=dict(),
                 pooling_func=functions.roi_align_2d,
                 rpn_hidden=1024, roi_size=7,
                 ):
        if n_fg_class is None:
            if pretrained_model not in self._models:
                raise ValueError(
                    'The n_fg_class needs to be supplied as an argument')
            n_fg_class = self._models[pretrained_model]['n_fg_class']

        if loc_initialW is None:
            loc_initialW = chainer.initializers.Normal(0.001)
        if score_initialW is None:
            score_initialW = chainer.initializers.Normal(0.01)
        if rpn_initialW is None:
            rpn_initialW = chainer.initializers.Normal(0.01)
        if res_initialW is None and pretrained_model:
            res_initialW = chainer.initializers.constant.Zero()

        if n_layers == 50:
            extractor = ResNet50Extractor(pretrained_model=None)
        elif n_layers == 101:
            extractor = ResNet101Extractor(pretrained_model=None)
        else:
            raise ValueError
        self._n_layers = n_layers

        rpn = RegionProposalNetwork(
            1024, rpn_hidden,
            ratios=ratios,
            anchor_scales=anchor_scales,
            feat_stride=self.feat_stride,
            initialW=rpn_initialW,
            proposal_creator_params=proposal_creator_params,
        )
        head = ResNetRoIHead(
            n_fg_class + 1,
            roi_size=roi_size,
            spatial_scale=1. / self.feat_stride,
            res_initialW=res_initialW,
            loc_initialW=loc_initialW,
            score_initialW=score_initialW,
            pooling_func=pooling_func,
        )

        super(MaskRCNNResNet, self).__init__(
            extractor,
            rpn,
            head,
            mean=np.array([123.152, 115.903, 103.063],
                          dtype=np.float32)[:, None, None],
            min_size=min_size,
            max_size=max_size
        )

        if pretrained_model in self._models:
            path = download_model(self._models[pretrained_model]['url'])
            chainer.serializers.load_npz(path, self)
        elif pretrained_model == 'imagenet':
            self._copy_imagenet_pretrained_resnet()
        elif pretrained_model:
            chainer.serializers.load_npz(pretrained_model, self)