Exemple #1
0
    def model_loss(self, data_ph, model_params):
        with tf.variable_scope("loss"):
            label = data_ph.get_label()
            mask = data_ph.get_mask()

            l2_loss_list = list()
            for i, deconv in enumerate(self.predict_list):
                deconv = self._filter_mask(deconv, mask)
                label = self._filter_mask(label, mask)
                l2_loss = mf.image_l2_loss(deconv, label, "l2_loss_%d" % i)
                l2_loss_list.append(l2_loss)
                tf.add_to_collection("losses", l2_loss)

                l1_loss = mf.image_l1_loss(deconv, label, "l1_loss_%d" % i)
            self.l1_loss = l1_loss
            self.l2_loss = tf.add_n(l2_loss_list)

            # Add domain loss
            if model_params['use_da']:
                pred = tf.reshape(self.da_cls, [-1, 2])
                da_label = data_ph.get_da_label()
                total_da_loss = tf.nn.softmax_cross_entropy_with_logits(
                    pred, da_label
                )
                weight_da_loss = data_ph.get_da_weight() * total_da_loss
                self.da_loss = tf.reduce_mean(weight_da_loss)
                tf.add_to_collection("losses", self.da_loss)

            self.loss = tf.add_n(tf.get_collection('losses'), name='total_loss')
    def model_loss(self, data_ph, model_params):
        with tf.variable_scope("loss"):
            label = data_ph.get_label()
            mask = data_ph.get_mask()

            l1_loss_list = list()
            l2_loss_list = list()
            for i, deconv in enumerate(self.predict_list):
                deconv = self._filter_mask(deconv, mask)
                label = self._filter_mask(label, mask)
                l2_loss = mf.image_l2_loss(deconv, label, "l2_loss_%d" % i)
                l2_loss_list.append(l2_loss)
                tf.add_to_collection("losses", l2_loss)
                l1_loss = mf.image_l1_loss(deconv, label, "l1_loss_%d" % i)
                tf.add_to_collection("losses", l1_loss)
                l1_loss_list.append(l1_loss)

            self.l1_loss = l1_loss_list
            self.l2_loss = tf.add_n(l2_loss_list)

            self.loss = tf.add_n(tf.get_collection('losses'),
                                 name='total_loss')