aten_model.py
def compile(self, learning_rate, momentum):
        """Gets the model ready for training. Adds losses, regularization, and
        metrics. Then calls the Keras compile() function.
        """
        # Optimizer object
        optimizer = keras.optimizers.SGD(lr=learning_rate, momentum=momentum,
                                         clipnorm=5.0)
        # Add Losses
        # First, clear previously set losses to avoid duplication
        self.keras_model._losses = []
        self.keras_model._per_input_losses = {}
        loss_names = ["rpn_class_loss", "rpn_bbox_loss",
                      "mrcnn_class_loss", "mrcnn_bbox_loss", "mrcnn_mask_loss", 
                      "mrcnn_global_parsing_loss"]
        for name in loss_names:
            layer = self.keras_model.get_layer(name)
            if layer.output in self.keras_model.losses:
                continue
            self.keras_model.add_loss(
                tf.reduce_mean(layer.output, keep_dims=True))

        # Add L2 Regularization
        reg_losses = [keras.regularizers.l2(self.config.WEIGHT_DECAY)(w)
                      for w in self.keras_model.trainable_weights
                      if ('gamma' not in w.name) and ('beta' not in w.name) and ('bias' not in w.name)]

        self.keras_model.add_loss(tf.add_n(reg_losses))

        # Compile
        self.keras_model.compile(optimizer=optimizer, loss=[
                                 None] * len(self.keras_model.outputs))

        # Add metrics for losses
        for name in loss_names:
            if name in self.keras_model.metrics_names:
                continue
            layer = self.keras_model.get_layer(name)
            self.keras_model.metrics_names.append(name)
            self.keras_model.metrics_tensors.append(tf.reduce_mean(
                layer.output, keep_dims=True))
Gets the model ready for training. Adds losses, regularization, and
        metrics. Then calls the Keras compile() function.
        
Gets the model ready for training. Adds losses, regularization, and
metrics. Then calls the Keras compile() function.
Gets the model ready for training . Adds losses regularization and metrics . Then calls the Keras compile () function .
def compile(self, learning_rate, momentum):
        optimizer = keras.optimizers.SGD(lr=learning_rate, momentum=momentum,
                                         clipnorm=5.0)
        self.keras_model._losses = []
        self.keras_model._per_input_losses = {}
        loss_names = ["rpn_class_loss", "rpn_bbox_loss",
                      "mrcnn_class_loss", "mrcnn_bbox_loss", "mrcnn_mask_loss", 
                      "mrcnn_global_parsing_loss"]
        for name in loss_names:
            layer = self.keras_model.get_layer(name)
            if layer.output in self.keras_model.losses:
                continue
            self.keras_model.add_loss(
                tf.reduce_mean(layer.output, keep_dims=True))
        reg_losses = [keras.regularizers.l2(self.config.WEIGHT_DECAY)(w)
                      for w in self.keras_model.trainable_weights
                      if ('gamma' not in w.name) and ('beta' not in w.name) and ('bias' not in w.name)]
        self.keras_model.add_loss(tf.add_n(reg_losses))
        self.keras_model.compile(optimizer=optimizer, loss=[
                                 None] * len(self.keras_model.outputs))
        for name in loss_names:
            if name in self.keras_model.metrics_names:
                continue
            layer = self.keras_model.get_layer(name)
            self.keras_model.metrics_names.append(name)
            self.keras_model.metrics_tensors.append(tf.reduce_mean(
                layer.output, keep_dims=True))
def compile ( self , learning_rate , momentum ) : optimizer = keras . optimizers . SGD ( lr = learning_rate , momentum = momentum , clipnorm = 5.0 ) self . keras_model . _losses = [ ] self . keras_model . _per_input_losses = { } loss_names = [ "rpn_class_loss" , "rpn_bbox_loss" , "mrcnn_class_loss" , "mrcnn_bbox_loss" , "mrcnn_mask_loss" , "mrcnn_global_parsing_loss" ] for name in loss_names : layer = self . keras_model . get_layer ( name ) if layer . output in self . keras_model . losses : continue self . keras_model . add_loss ( tf . reduce_mean ( layer . output , keep_dims = True ) ) reg_losses = [ keras . regularizers . l2 ( self . config . WEIGHT_DECAY ) ( w ) for w in self . keras_model . trainable_weights if ( 'gamma' not in w . name ) and ( 'beta' not in w . name ) and ( 'bias' not in w . name ) ] self . keras_model . add_loss ( tf . add_n ( reg_losses ) ) self . keras_model . compile ( optimizer = optimizer , loss = [ None ] * len ( self . keras_model . outputs ) ) for name in loss_names : if name in self . keras_model . metrics_names : continue layer = self . keras_model . get_layer ( name ) self . keras_model . metrics_names . append ( name ) self . keras_model . metrics_tensors . append ( tf . reduce_mean ( layer . output , keep_dims = True ) )
Gets the model ready for training.
Gets the model ready for training .
"""Gets the model ready for training. Adds losses, regularization, and
        metrics. Then calls the Keras compile() function.
        """ # Optimizer object # Add Losses # First, clear previously set losses to avoid duplication # Add L2 Regularization # Compile # Add metrics for losses
self
learning_rate
momentum