def labeled_loss_calculation(self, labeled_examples, labels): """Calculates the labeled loss.""" bin_index_labels = real_numbers_to_bin_indexes(labels, self.bins) predicted_logits = self.D(labeled_examples) labeled_loss = self.labeled_criterion(predicted_logits, bin_index_labels) labeled_loss *= self.settings.labeled_loss_multiplier return labeled_loss
def labeled_loss_calculation(self, labeled_examples, labels): """Calculates the labeled loss.""" predictions = self.D(labeled_examples) density_labels = labels predicted_density_labels, predicted_count_logits = predictions density_loss = torch.abs(predicted_density_labels - density_labels).pow(2).sum(1).sum(1).mean() count_labels = density_labels.sum(1).sum(1) bin_index_count_labels = real_numbers_to_bin_indexes(count_labels, self.bins) count_loss = self.labeled_criterion(predicted_count_logits, bin_index_count_labels) labeled_loss = count_loss + (density_loss * 10) labeled_loss *= self.settings.labeled_loss_multiplier return labeled_loss