Ejemplo n.º 1
0
 def test3_loss_nll(self, mock_activate, mock_mean):
     mock_activate.return_value = (self.input_ndarray, self.input_shape)
     mock_mean.return_value = 1
     self.output_layer = cl(input=self.input_tensor,
                            id=self.classifier_layer_name,
                            num_classes=self.classes,
                            input_shape=self.input_shape,
                            rng=self.rng,
                            borrow=self.borrow,
                            input_params=self.input_params_all,
                            verbose=self.verbose)
     self.assertEqual(
         self.output_layer.loss(theano.tensor.ivector('s'), 'nll'), -1)
Ejemplo n.º 2
0
 def test6_loss_hinge(self, mock_activate, mock_max, mock_mean):
     mock_mean.return_value = 1
     mock_activate.return_value = (self.input_ndarray, self.input_shape)
     mock_max.return_value = self.output_dropout_ndarray
     self.output_layer = cl(input=self.input_tensor,
                            id=self.classifier_layer_name,
                            num_classes=self.classes,
                            input_shape=self.input_shape,
                            rng=self.rng,
                            borrow=self.borrow,
                            input_params=self.input_params_all,
                            verbose=self.verbose)
     self.assertEqual(self.output_layer.loss(self.input_ndarray, 'hinge'),
                      0)
Ejemplo n.º 3
0
 def test2_output_params(self, mock_activate):
     mock_activate.return_value = (self.input_ndarray, self.input_shape)
     self.output_layer = cl(input=self.input_tensor,
                            id=self.classifier_layer_name,
                            num_classes=self.classes,
                            input_shape=self.input_shape,
                            rng=self.rng,
                            borrow=self.borrow,
                            input_params=self.input_params_all,
                            verbose=self.verbose)
     self.assertEqual(self.output_layer.id, self.classifier_layer_name)
     self.assertEqual(self.output_layer.output_shape, self.output_shape)
     self.assertTrue(
         numpy.allclose(self.output_layer.output, self.input_ndarray))
     self.assertTrue(
         numpy.allclose(self.output_layer.inference, self.input_ndarray))
Ejemplo n.º 4
0
 def test11_get_params(self, mock_activate, mock_max, mock_mean):
     self.val = T.dot(self.input_tensor, self.input_tensor)
     mock_mean.return_value = 1
     mock_activate.return_value = (self.input_ndarray, self.input_shape)
     mock_max.return_value = self.output_dropout_ndarray
     self.output_layer = cl(input=self.input_tensor,
                            id=self.classifier_layer_name,
                            num_classes=self.classes,
                            input_shape=self.input_shape,
                            rng=self.rng,
                            borrow=self.borrow,
                            input_params=self.input_params_all,
                            verbose=self.verbose)
     self.output_layer.params = [MockParam(), MockParam()]
     out = self.output_layer.get_params(borrow=True, verbose=self.verbose)
     self.assertTrue(numpy.allclose(out, [1, 1]))
Ejemplo n.º 5
0
 def test10_loss_exception(self, mock_activate, mock_max, mock_mean):
     mock_mean.return_value = 1
     mock_activate.return_value = (self.input_ndarray, self.input_shape)
     mock_max.return_value = self.output_dropout_ndarray
     self.output_layer = cl(input=self.input_tensor,
                            id=self.classifier_layer_name,
                            num_classes=self.classes,
                            input_shape=self.input_shape,
                            rng=self.rng,
                            borrow=self.borrow,
                            input_params=self.input_params_all,
                            verbose=self.verbose)
     try:
         self.output_layer.loss(self.input_ndarray, 'hinge1')
         self.assertEqual(True, False)
     except Exception, e:
         self.assertEqual(True, True)
Ejemplo n.º 6
0
    def test7_error(self, mock_activate, mock_max, mock_mean, mock_sum):
        mock_sum.return_value = 1
        mock_mean.return_value = 1
        mock_activate.return_value = (self.input_ndarray, self.input_shape)
        mock_max.return_value = self.output_dropout_ndarray
        self.output_layer = cl(input=self.input_tensor,
                               id=self.classifier_layer_name,
                               num_classes=self.classes,
                               input_shape=self.input_shape,
                               rng=self.rng,
                               borrow=self.borrow,
                               input_params=self.input_params_all,
                               verbose=self.verbose)

        self.output_layer.predictions = theano.tensor.ivector('s')
        self.assertEqual(
            self.output_layer.errors(self.output_layer.predictions), 1)
Ejemplo n.º 7
0
    def test9_error_exception(self, mock_activate, mock_max, mock_mean,
                              mock_sum):
        mock_sum.return_value = 1
        mock_mean.return_value = 1
        mock_activate.return_value = (self.input_ndarray, self.input_shape)
        mock_max.return_value = self.output_dropout_ndarray
        self.output_layer = cl(input=self.input_tensor,
                               id=self.classifier_layer_name,
                               num_classes=self.classes,
                               input_shape=self.input_shape,
                               rng=self.rng,
                               borrow=self.borrow,
                               input_params=self.input_params_all,
                               verbose=self.verbose)

        self.output_layer.predictions = theano.tensor.scalar('s')
        try:
            self.output_layer.errors(theano.tensor.scalar('s'))
            self.assertEqual(True, False)
        except NotImplementedError, e:
            self.assertEqual(True, True)