Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Keras, is there documentation describing the string name to class mappings for initializers, optimizers, etc?

Is there any documentation describing what string names map to what objects in Keras? For example, below I create an Embedding layer from tf.keras.layers and I can use 'uniform' to map to the tf.keras.initializers.RandomUniform class.

tf.keras.layers.Embedding(1000, 64, embeddings_initializer='uniform')

But I only know that by seeing examples of that usage. I presume the supported string forms are documented somewhere, but I can't seem to find such documentation, and digging through the code got too abstract to follow easily.

Version: TF 1.13.1

like image 562
David Parks Avatar asked May 16 '19 20:05

David Parks


People also ask

What is TensorFlow keras models?

Keras is a neural network Application Programming Interface (API) for Python that is tightly integrated with TensorFlow, which is used to build machine learning models. Keras' models offer a simple, user-friendly way to define a neural network, which will then be built for you by TensorFlow.

What is Glorot_uniform?

glorot_uniform . Draws samples from a uniform distribution within [-limit, limit] , where limit = sqrt(6 / (fan_in + fan_out)) ( fan_in is the number of input units in the weight tensor and fan_out is the number of output units).

How is a TensorFlow model defined?

Defining models and layers in TensorFlow. Most models are made of layers. Layers are functions with a known mathematical structure that can be reused and have trainable variables. In TensorFlow, most high-level implementations of layers and models, such as Keras or Sonnet, are built on the same foundational class: tf.


1 Answers

There is no list of string constants available in keras implementation in TF (and, I suppose, in original keras neither).

For the initializer case the 'uniform' string is converted to config and a fabric method is called on that config with a hint to create an object from initializers namespace (can be found here as def deserialize_keras_object):

config = {'class_name': str(identifier), 'config': {}}

deserialize_keras_object(
      config,
      module_objects=globals(),
      custom_objects=custom_objects,
      printable_module_name='initializer')

Therefore, I can not think of a better way to, for example, list all initializers than:

import tensorflow as tf

for k, v in tf.keras.initializers.__dict__.items():
    if not k[0].isupper() and not k[0] == "_":
        print(k)

And output, although with extra values, is like:

constant
glorot_normal
glorot_uniform
identity
ones
orthogonal
zeros
he_normal
he_uniform
lecun_normal
lecun_uniform
normal
random_normal
random_uniform
uniform
truncated_normal
deserialize
get
serialize
like image 83
y.selivonchyk Avatar answered Sep 28 '22 16:09

y.selivonchyk