Exemplo n.º 1
0
 def test_serialization_with_layers(self):
     activation = advanced_activations.LeakyReLU(alpha=0.1)
     layer = core.Dense(3, activation=activation)
     config = serialization.serialize(layer)
     # with custom objects
     deserialized_layer = serialization.deserialize(
         config, custom_objects={'LeakyReLU': activation})
     self.assertEqual(deserialized_layer.__class__.__name__,
                      layer.__class__.__name__)
     self.assertEqual(deserialized_layer.activation.__class__.__name__,
                      activation.__class__.__name__)
     # without custom objects
     deserialized_layer = serialization.deserialize(config)
     self.assertEqual(deserialized_layer.__class__.__name__,
                      layer.__class__.__name__)
     self.assertEqual(deserialized_layer.activation.__class__.__name__,
                      activation.__class__.__name__)
Exemplo n.º 2
0
  def _from_config(cls_initializer, config):
    """All shared from_config logic for fused layers."""
    config = config.copy()
    # use_bias is not an argument of this class, as explained by
    # comment in __init__.
    config.pop('use_bias')
    is_advanced_activation = 'class_name' in config['post_activation']
    if is_advanced_activation:
      config['post_activation'] = serialization.deserialize(
          config['post_activation'])
    else:
      config['post_activation'] = activations.deserialize(
          config['post_activation'])

    return cls_initializer(**config)