def test_targets_dict_to_numpy_cnn_no_scalars(self):
        """Ensures correct output from targets_dict_to_numpy.

        In this case, neural-net type is CNN with no scalar outputs.
        """

        this_scalar_target_matrix = (
            EXAMPLE_DICT[example_utils.SCALAR_TARGET_VALS_KEY] + 0.)
        this_scalar_target_matrix = numpy.full(
            (this_scalar_target_matrix.shape[0], 0), 0.)

        this_example_dict = copy.deepcopy(EXAMPLE_DICT)
        this_example_dict[example_utils.SCALAR_TARGET_VALS_KEY] = (
            this_scalar_target_matrix)

        these_matrices = neural_net.targets_dict_to_numpy(
            example_dict=this_example_dict,
            net_type_string=neural_net.CNN_TYPE_STRING)

        self.assertTrue(
            len(these_matrices) == len(CNN_TARGET_MATRICES_NO_SCALARS))

        for i in range(len(these_matrices)):
            self.assertTrue(
                numpy.allclose(these_matrices[i],
                               CNN_TARGET_MATRICES_NO_SCALARS[i],
                               atol=TOLERANCE))
    def test_targets_dict_to_numpy_u_net(self):
        """Ensures correct output from targets_dict_to_numpy.

        In this case, neural-net type is U-net.
        """

        these_matrices = neural_net.targets_dict_to_numpy(
            example_dict=EXAMPLE_DICT,
            net_type_string=neural_net.U_NET_TYPE_STRING)

        self.assertTrue(len(these_matrices) == len(U_NET_TARGET_MATRICES))

        for i in range(len(these_matrices)):
            self.assertTrue(
                numpy.allclose(these_matrices[i],
                               U_NET_TARGET_MATRICES[i],
                               atol=TOLERANCE))
Exemple #3
0
    def test_targets_dict_to_numpy_cnn_custom_loss(self):
        """Ensures correct output from targets_dict_to_numpy.

        In this case, neural-net type is CNN with custom loss function.
        """

        these_matrices = neural_net.targets_dict_to_numpy(
            example_dict=EXAMPLE_DICT,
            net_type_string=neural_net.CNN_TYPE_STRING,
            is_loss_constrained_mse=True)

        self.assertTrue(
            len(these_matrices) == len(CNN_TARGET_MATRICES_CUSTOM_LOSS))

        for i in range(len(these_matrices)):
            self.assertTrue(
                numpy.allclose(these_matrices[i],
                               CNN_TARGET_MATRICES_CUSTOM_LOSS[i],
                               atol=TOLERANCE))