Exemplo n.º 1
0
    def __init__(self,
                 mode,
                 graph_fn,
                 loss=None,
                 optimizer=None,
                 summaries='all',
                 metrics=None,
                 clip_gradients=0.5,
                 clip_embed_gradients=0.1,
                 one_hot_encode=None,
                 n_classes=None,
                 name="Classifier"):
        if one_hot_encode and (n_classes is None
                               or not isinstance(n_classes, int)):
            raise ValueError(
                '`n_classes` must be an integer non negative value '
                'when `one_hot_encode` is set to `True`, '
                'received instead: {}'.format(n_classes))

        self.one_hot_encode = one_hot_encode
        self.n_classes = n_classes
        loss = loss or SigmoidCrossEntropyConfig()
        super(Classifier,
              self).__init__(mode=mode,
                             name=name,
                             model_type=self.Types.CLASSIFIER,
                             graph_fn=graph_fn,
                             loss=loss,
                             optimizer=optimizer,
                             metrics=metrics,
                             summaries=summaries,
                             clip_gradients=clip_gradients,
                             clip_embed_gradients=clip_embed_gradients)
Exemplo n.º 2
0
    def __init__(self,
                 mode,
                 encoder_fn,
                 decoder_fn,
                 bridge_fn,
                 loss=None,
                 optimizer=None,
                 summaries='all',
                 metrics=None,
                 clip_gradients=0.5,
                 clip_embed_gradients=0.1,
                 name="Generator"):
        optimizer = optimizer or AdadeltaConfig(learning_rate=0.4)
        loss = loss or SigmoidCrossEntropyConfig()
        self._check_subgraph_fn(function=encoder_fn, function_name='encoder_fn')
        self._check_subgraph_fn(function=decoder_fn, function_name='decoder_fn')
        self._check_bridge_fn(function=bridge_fn)
        self._encode_fn = encoder_fn
        self._decoder_fn = decoder_fn
        self._bridge_fn = bridge_fn

        graph_fn = self._build_graph_fn()

        super(Generator, self).__init__(
            mode=mode,
            name=name,
            model_type=self.Types.GENERATOR,
            graph_fn=graph_fn,
            loss=loss,
            optimizer=optimizer,
            metrics=metrics,
            summaries=summaries,
            clip_gradients=clip_gradients,
            clip_embed_gradients=clip_embed_gradients)
Exemplo n.º 3
0
 def test_sigmoid_crossentropy_loss_config(self):
     config_dict = {
         'input_layer': 'images',
         'output_layer': 'relu_1',
         'label_smoothing': 0.,
         'weights': 1.0,
         'name': 'l',
         'collect': False
     }
     config = SigmoidCrossEntropyConfig.from_dict(config_dict)
     self.assert_equal_losses(config.to_dict(), config_dict)
Exemplo n.º 4
0
def model_fn(features, labels, params, mode, config):
    model = plx.models.Classifier(mode=mode,
                                  graph_fn=graph_fn,
                                  loss=SigmoidCrossEntropyConfig(),
                                  optimizer=AdamConfig(learning_rate=0.001),
                                  metrics=[AccuracyConfig()],
                                  summaries='all',
                                  one_hot_encode=True,
                                  n_classes=10)
    return model(features=features,
                 labels=labels,
                 params=params,
                 config=config)