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
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.
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).
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With