def build_model(self):
        # backbone encoder
        backbone, skips = self.get_backbone()

        # decoder construction
        prediction = self.create_decoder(backbone, skips)

        network = keras.Model(inputs=backbone.input,
                              outputs=prediction,
                              name="FPN_NET")

        network.summary()

        # get the optimizer
        optimizer = self.build_optimizer()

        metrics = self.build_metrics_NYU()

        if self.config.model.loss == "focal_loss":
            loss = CategoricalFocalLoss(gamma=self.config.model.gamma,
                                        alpha=self.config.model.alpha)
        elif self.config.model.loss == "lovasz":
            loss = MultiClassLovaszSoftmaxLoss()
        else:
            loss = 'categorical_crossentropy'

        network.compile(loss=loss, optimizer=optimizer, metrics=metrics)

        return network
Exemple #2
0
    def build_model(self):
        # backbone encoder
        backbone, skips = self.get_backbone()

        # joint decoder (resolution 1/4)
        decoder = self.decoder(backbone, skips)

        # segmentation head
        segmentation_mask = self.segmentation_head(decoder)

        # depth estimation head
        depth_estimation = self.depth_head(decoder)

        # create model
        network = keras.Model(inputs=backbone.input,
                              outputs=[segmentation_mask, depth_estimation],
                              name="JOINT_BI_FPN")

        network.summary()

        # get the optimizer
        optimizer = self.build_optimizer()

        # define segmentation loss
        if self.config.model.seg_loss == "focal_loss":
            seg_loss = CategoricalFocalLoss(gamma=self.config.model.gamma,
                                            alpha=self.config.model.alpha)
        elif self.config.model.seg_loss == "lovasz":
            seg_loss = MultiClassLovaszSoftmaxLoss()
        else:
            seg_loss = 'categorical_crossentropy'

        # define depth loss
        if self.config.model.depth_loss == "Huber":
            depth_loss = tf.keras.losses.Huber()
        else:
            depth_loss = tf.keras.losses.MeanSquaredError()

        # composed loss
        losses = {"seg_out": seg_loss, "dep_out": depth_loss}

        loss_weights = {
            "seg_out": self.config.model.loss_weights.seg_loss,
            "dep_out": self.config.model.loss_weights.depth_loss
        }

        # define metrics
        metrics = {
            "seg_out": self._generate_metrics(),
            "dep_out": [tf.keras.metrics.RootMeanSquaredError()]
        }

        network.compile(loss=losses,
                        loss_weights=loss_weights,
                        optimizer=optimizer,
                        metrics=metrics)

        return network
Exemple #3
0
    def segmentation_loss(self):
        # define segmentation loss
        if self.config.model.seg_loss == "focal_loss":
            seg_loss = CategoricalFocalLoss(gamma=self.config.model.gamma,
                                            alpha=self.config.model.alpha)
        elif self.config.model.seg_loss == "lovasz":
            seg_loss = MultiClassLovaszSoftmaxLoss()
        elif self.config.model.seg_loss == "focal_tversky":
            seg_loss = focal_tversky_loss
        elif self.config.model.seg_loss == "tversky":
            seg_loss = class_tversky
        else:
            seg_loss = 'categorical_crossentropy'

        return seg_loss