def build(self):
        """
        Build Retina Net architecture.
        """

        # Image size must be dividable by 2 multiple times.
        h, w = self.cf.patch_size[:2]
        if h / 2**5 != int(h / 2**5) or w / 2**5 != int(w / 2**5):
            raise Exception(
                "Image size must be dividable by 2 at least 5 times "
                "to avoid fractions when downscaling and upscaling."
                "For example, use 256, 320, 384, 448, 512, ... etc. ")

        # instanciate abstract multi dimensional conv class and backbone model.
        conv = mutils.NDConvGenerator(self.cf.dim)
        backbone = utils.import_module('bbone', self.cf.backbone_path)

        # build Anchors, FPN, Classifier / Bbox-Regressor -head
        self.np_anchors = mutils.generate_pyramid_anchors(self.logger, self.cf)
        self.anchors = torch.from_numpy(self.np_anchors).float().cuda()
        self.Fpn = backbone.FPN(self.cf,
                                conv,
                                operate_stride1=self.cf.operate_stride1)
        self.Classifier = Classifier(self.cf, conv)
        self.BBRegressor = BBRegressor(self.cf, conv)
        self.final_conv = conv(self.cf.end_filts,
                               self.cf.num_seg_classes,
                               ks=1,
                               pad=0,
                               norm=self.cf.norm,
                               relu=None)
Exemplo n.º 2
0
    def build(self):
        """
        Build Retina Net architecture.
        """

        # Image size must be dividable by 2 multiple times.
        h, w = self.cf.patch_size[:2]
        if h / 2 ** 5 != int(h / 2 ** 5) or w / 2 ** 5 != int(w / 2 ** 5):
            raise Exception("Image size must be dividable by 2 at least 5 times "
                            "to avoid fractions when downscaling and upscaling."
                            "For example, use 256, 320, 384, 448, 512, ... etc. ")

        # instanciate abstract multi dimensional conv class and backbone model.
        conv = mutils.NDConvGenerator(self.cf.dim)
        backbone = utils.import_module('bbone', self.cf.backbone_path)

        # build Anchors, FPN, Classifier / Bbox-Regressor -head
        self.np_anchors = mutils.generate_pyramid_anchors(self.logger, self.cf)
        self.anchors = torch.from_numpy(self.np_anchors).float().cuda()
        # self.Fpn = backbone.FPN(self.cf, conv, operate_stride1=self.cf.operate_stride1)
        self.num_classes=self.cf.head_classes
        
        # i3d_rgb = backbone.I3D(num_classes=self.num_classes)
        ######## HEART OF I3D RGB Weight Transfer
        # print("Transferring weight from i3d_rgb model...........")
        # i3d_rgb = backbone.I3D(num_classes=self.num_classes)
        # i3d_rgb.load_state_dict(torch.load('weight/model_rgb.pth'), strict=False)

        # print('Success..........')
        # self.Fpn = i3d_rgb
        self.Fpn = backbone.I3D(num_classes=self.num_classes)
        self.Classifier = Classifier(self.cf, conv)
        self.BBRegressor = BBRegressor(self.cf, conv)
Exemplo n.º 3
0
    def build(self):
        """Build Retina Net architecture."""

        # Image size must be dividable by 2 multiple times.
        h, w = self.cf.patch_size[:2]
        if h / 2 ** 5 != int(h / 2 ** 5) or w / 2 ** 5 != int(w / 2 ** 5):
            raise Exception("Image size must be divisible by 2 at least 5 times "
                            "to avoid fractions when downscaling and upscaling."
                            "For example, use 256, 320, 384, 448, 512, ... etc. ")

        backbone = utils.import_module('bbone', self.cf.backbone_path)
        self.logger.info("loaded backbone from {}".format(self.cf.backbone_path))
        conv = backbone.ConvGenerator(self.cf.dim)


        # build Anchors, FPN, Classifier / Bbox-Regressor -head
        self.np_anchors = mutils.generate_pyramid_anchors(self.logger, self.cf)
        self.anchors = torch.from_numpy(self.np_anchors).float().cuda()
        self.fpn = backbone.FPN(self.cf, conv, operate_stride1=self.cf.operate_stride1).cuda()
        self.classifier = Classifier(self.cf, conv).cuda()
        self.bb_regressor = BBRegressor(self.cf, conv).cuda()

        if 'regression' in self.cf.prediction_tasks:
            self.roi_regressor = RoIRegressor(self.cf, conv, self.cf.regression_n_features).cuda()
        elif 'regression_bin' in self.cf.prediction_tasks:
            # classify into bins of regression values
            self.roi_regressor = RoIRegressor(self.cf, conv, len(self.cf.bin_labels)).cuda()
        else:
            self.roi_regressor = lambda x: [torch.tensor([]).cuda()]

        if self.cf.model == 'retina_unet':
            self.final_conv = conv(self.cf.end_filts, self.cf.num_seg_classes, ks=1, pad=0, norm=None, relu=None)
Exemplo n.º 4
0
    def build(self):
        """Build Mask R-CNN architecture."""

        # Image size must be dividable by 2 multiple times.
        h, w = self.cf.patch_size[:2]
        if h / 2**5 != int(h / 2**5) or w / 2**5 != int(w / 2**5):
            raise Exception(
                "Image size must be divisible by 2 at least 5 times "
                "to avoid fractions when downscaling and upscaling."
                "For example, use 256, 288, 320, 384, 448, 512, ... etc.,i.e.,"
                "any number x*32 will do!")

        # instantiate abstract multi-dimensional conv generator and load backbone module.
        backbone = utils.import_module('bbone', self.cf.backbone_path)
        self.logger.info("loaded backbone from {}".format(
            self.cf.backbone_path))
        conv = backbone.ConvGenerator(self.cf.dim)

        # build Anchors, FPN, RPN, Classifier / Bbox-Regressor -head, Mask-head
        self.np_anchors = mutils.generate_pyramid_anchors(self.logger, self.cf)
        self.anchors = torch.from_numpy(self.np_anchors).float().cuda()
        self.fpn = backbone.FPN(self.cf,
                                conv,
                                relu_enc=self.cf.relu,
                                operate_stride1=False).cuda()
        self.rpn = RPN(self.cf, conv)
        self.classifier = Classifier(self.cf, conv)
        self.mask = Mask(self.cf, conv)
    def build(self):
        # build Anchors, FPN, Classifier / Bbox-Regressor -head
        self.np_anchors = mutils.generate_pyramid_anchors(self.logger, self.cf)
        self.anchors = torch.from_numpy(self.np_anchors).float().cuda()

        self.Fpn = backbone.FPN(
            input_channels=
            7,  # (3*2+1)feed +/- 3 neighbouring slices into channel dimension.
            start_filts=48,
            out_channels=192,
            res_architecture='resnet50',
            dropout=self.mc_var)

        self.Classifier = Classifier(n_input_channels=192,
                                     n_features=256,
                                     n_classes=2,
                                     pred_var=self.pred_var)

        self.BBRegressor = BBRegressor(n_input_channels=192,
                                       n_features=256,
                                       anchor_stride=1)