Type tf.keras.utils
Namespace tensorflow
Methods
- convert_all_kernels_in_model
- convert_all_kernels_in_model_dyn
- custom_object_scope
- custom_object_scope_dyn
- deserialize_keras_object
- deserialize_keras_object
- deserialize_keras_object_dyn
- get_custom_objects
- get_custom_objects_dyn
- get_file
- get_file_dyn
- get_source_inputs
- get_source_inputs
- get_source_inputs_dyn
- model_to_dot
- model_to_dot
- model_to_dot_dyn
- multi_gpu_model
- multi_gpu_model
- multi_gpu_model
- multi_gpu_model_dyn
- normalize
- normalize_dyn
- plot_model
- plot_model_dyn
- serialize_keras_object
- serialize_keras_object
- serialize_keras_object_dyn
- to_categorical
- to_categorical_dyn
Properties
Public static methods
void convert_all_kernels_in_model(object model)
Converts all convolution kernels in a model from Theano to TensorFlow. Also works from TensorFlow to Theano.
Parameters
-
objectmodel - target model for the conversion.
object convert_all_kernels_in_model_dyn(object model)
Converts all convolution kernels in a model from Theano to TensorFlow. Also works from TensorFlow to Theano.
Parameters
-
objectmodel - target model for the conversion.
CustomObjectScope custom_object_scope(Object[] args)
Provides a scope that changes to `_GLOBAL_CUSTOM_OBJECTS` cannot escape. Convenience wrapper for `CustomObjectScope`.
Code within a `with` statement will be able to access custom objects
by name. Changes to global custom objects persist
within the enclosing `with` statement. At end of the `with` statement,
global custom objects are reverted to state
at beginning of the `with` statement. Example: Consider a custom object `MyObject`
Parameters
-
Object[]args - Variable length list of dictionaries of name, class pairs to add to custom objects.
Returns
-
CustomObjectScope - Object of type `CustomObjectScope`.
Show Example
with custom_object_scope({'MyObject':MyObject}):
layer = Dense(..., kernel_regularizer='MyObject')
# save, load, etc. will recognize custom object by name
object custom_object_scope_dyn(Object[] args)
Provides a scope that changes to `_GLOBAL_CUSTOM_OBJECTS` cannot escape. Convenience wrapper for `CustomObjectScope`.
Code within a `with` statement will be able to access custom objects
by name. Changes to global custom objects persist
within the enclosing `with` statement. At end of the `with` statement,
global custom objects are reverted to state
at beginning of the `with` statement. Example: Consider a custom object `MyObject`
Parameters
-
Object[]args - Variable length list of dictionaries of name, class pairs to add to custom objects.
Returns
-
object - Object of type `CustomObjectScope`.
Show Example
with custom_object_scope({'MyObject':MyObject}):
layer = Dense(..., kernel_regularizer='MyObject')
# save, load, etc. will recognize custom object by name
object deserialize_keras_object(PythonClassContainer identifier, IDictionary<string, object> module_objects, IDictionary<string, object> custom_objects, string printable_module_name)
object deserialize_keras_object(object identifier, IDictionary<string, object> module_objects, IDictionary<string, object> custom_objects, string printable_module_name)
object deserialize_keras_object_dyn(object identifier, object module_objects, object custom_objects, ImplicitContainer<T> printable_module_name)
IDictionary<object, object> get_custom_objects()
Retrieves a live reference to the global dictionary of custom objects. Updating and clearing custom objects using `custom_object_scope`
is preferred, but `get_custom_objects` can
be used to directly access `_GLOBAL_CUSTOM_OBJECTS`. Example:
Returns
-
IDictionary<object, object> - Global dictionary of names to classes (`_GLOBAL_CUSTOM_OBJECTS`).
Show Example
get_custom_objects().clear()
get_custom_objects()['MyObject'] = MyObject
object get_custom_objects_dyn()
Retrieves a live reference to the global dictionary of custom objects. Updating and clearing custom objects using `custom_object_scope`
is preferred, but `get_custom_objects` can
be used to directly access `_GLOBAL_CUSTOM_OBJECTS`. Example:
Returns
-
object - Global dictionary of names to classes (`_GLOBAL_CUSTOM_OBJECTS`).
Show Example
get_custom_objects().clear()
get_custom_objects()['MyObject'] = MyObject
object get_file(string fname, string origin, bool untar, string md5_hash, string file_hash, string cache_subdir, string hash_algorithm, bool extract, string archive_format, object cache_dir)
Downloads a file from a URL if it not already in the cache. By default the file at the url `origin` is downloaded to the
cache_dir `~/.keras`, placed in the cache_subdir `datasets`,
and given the filename `fname`. The final location of a file
`example.txt` would therefore be `~/.keras/datasets/example.txt`. Files in tar, tar.gz, tar.bz, and zip formats can also be extracted.
Passing a hash will verify the file after download. The command line
programs `shasum` and `sha256sum` can compute the hash.
Parameters
-
stringfname - Name of the file. If an absolute path `/path/to/file.txt` is specified the file will be saved at that location.
-
stringorigin - Original URL of the file.
-
booluntar - Deprecated in favor of 'extract'. boolean, whether the file should be decompressed
-
stringmd5_hash - Deprecated in favor of 'file_hash'. md5 hash of the file for verification
-
stringfile_hash - The expected hash string of the file after download. The sha256 and md5 hash algorithms are both supported.
-
stringcache_subdir - Subdirectory under the Keras cache dir where the file is saved. If an absolute path `/path/to/folder` is specified the file will be saved at that location.
-
stringhash_algorithm - Select the hash algorithm to verify the file. options are 'md5', 'sha256', and 'auto'. The default 'auto' detects the hash algorithm in use.
-
boolextract - True tries extracting the file as an Archive, like tar or zip.
-
stringarchive_format - Archive format to try for extracting the file. Options are 'auto', 'tar', 'zip', and None. 'tar' includes tar, tar.gz, and tar.bz files. The default 'auto' is ['tar', 'zip']. None or an empty list will return no matches found.
-
objectcache_dir - Location to store cached files, when None it defaults to the [Keras Directory](/faq/#where-is-the-keras-configuration-filed-stored).
Returns
-
object - Path to the downloaded file
object get_file_dyn(object fname, object origin, ImplicitContainer<T> untar, object md5_hash, object file_hash, ImplicitContainer<T> cache_subdir, ImplicitContainer<T> hash_algorithm, ImplicitContainer<T> extract, ImplicitContainer<T> archive_format, object cache_dir)
Downloads a file from a URL if it not already in the cache. By default the file at the url `origin` is downloaded to the
cache_dir `~/.keras`, placed in the cache_subdir `datasets`,
and given the filename `fname`. The final location of a file
`example.txt` would therefore be `~/.keras/datasets/example.txt`. Files in tar, tar.gz, tar.bz, and zip formats can also be extracted.
Passing a hash will verify the file after download. The command line
programs `shasum` and `sha256sum` can compute the hash.
Parameters
-
objectfname - Name of the file. If an absolute path `/path/to/file.txt` is specified the file will be saved at that location.
-
objectorigin - Original URL of the file.
-
ImplicitContainer<T>untar - Deprecated in favor of 'extract'. boolean, whether the file should be decompressed
-
objectmd5_hash - Deprecated in favor of 'file_hash'. md5 hash of the file for verification
-
objectfile_hash - The expected hash string of the file after download. The sha256 and md5 hash algorithms are both supported.
-
ImplicitContainer<T>cache_subdir - Subdirectory under the Keras cache dir where the file is saved. If an absolute path `/path/to/folder` is specified the file will be saved at that location.
-
ImplicitContainer<T>hash_algorithm - Select the hash algorithm to verify the file. options are 'md5', 'sha256', and 'auto'. The default 'auto' detects the hash algorithm in use.
-
ImplicitContainer<T>extract - True tries extracting the file as an Archive, like tar or zip.
-
ImplicitContainer<T>archive_format - Archive format to try for extracting the file. Options are 'auto', 'tar', 'zip', and None. 'tar' includes tar, tar.gz, and tar.bz files. The default 'auto' is ['tar', 'zip']. None or an empty list will return no matches found.
-
objectcache_dir - Location to store cached files, when None it defaults to the [Keras Directory](/faq/#where-is-the-keras-configuration-filed-stored).
Returns
-
object - Path to the downloaded file
object get_source_inputs(IGraphNodeBase tensor, object layer, object node_index)
Returns the list of input tensors necessary to compute `tensor`. Output will always be a list of tensors
(potentially with 1 element).
Parameters
-
IGraphNodeBasetensor - The tensor to start from.
-
objectlayer - Origin layer of the tensor. Will be determined via tensor._keras_history if not provided.
-
objectnode_index - Origin node index of the tensor.
Returns
-
object - List of input tensors.
object get_source_inputs(IEnumerable<IGraphNodeBase> tensor, object layer, object node_index)
Returns the list of input tensors necessary to compute `tensor`. Output will always be a list of tensors
(potentially with 1 element).
Parameters
-
IEnumerable<IGraphNodeBase>tensor - The tensor to start from.
-
objectlayer - Origin layer of the tensor. Will be determined via tensor._keras_history if not provided.
-
objectnode_index - Origin node index of the tensor.
Returns
-
object - List of input tensors.
object get_source_inputs_dyn(object tensor, object layer, object node_index)
Returns the list of input tensors necessary to compute `tensor`. Output will always be a list of tensors
(potentially with 1 element).
Parameters
-
objecttensor - The tensor to start from.
-
objectlayer - Origin layer of the tensor. Will be determined via tensor._keras_history if not provided.
-
objectnode_index - Origin node index of the tensor.
Returns
-
object - List of input tensors.
object model_to_dot(Layer model, bool show_shapes, bool show_layer_names, string rankdir, bool expand_nested, int dpi, bool subgraph)
Convert a Keras model to dot format.
Parameters
-
Layermodel - A Keras model instance.
-
boolshow_shapes - whether to display shape information.
-
boolshow_layer_names - whether to display layer names.
-
stringrankdir - `rankdir` argument passed to PyDot, a string specifying the format of the plot: 'TB' creates a vertical plot; 'LR' creates a horizontal plot.
-
boolexpand_nested - whether to expand nested models into clusters.
-
intdpi - Dots per inch.
-
boolsubgraph - whether to return a `pydot.Cluster` instance.
Returns
-
object - A `pydot.Dot` instance representing the Keras model or a `pydot.Cluster` instance representing nested model if `subgraph=True`.
object model_to_dot(Network model, bool show_shapes, bool show_layer_names, string rankdir, bool expand_nested, int dpi, bool subgraph)
Convert a Keras model to dot format.
Parameters
-
Networkmodel - A Keras model instance.
-
boolshow_shapes - whether to display shape information.
-
boolshow_layer_names - whether to display layer names.
-
stringrankdir - `rankdir` argument passed to PyDot, a string specifying the format of the plot: 'TB' creates a vertical plot; 'LR' creates a horizontal plot.
-
boolexpand_nested - whether to expand nested models into clusters.
-
intdpi - Dots per inch.
-
boolsubgraph - whether to return a `pydot.Cluster` instance.
Returns
-
object - A `pydot.Dot` instance representing the Keras model or a `pydot.Cluster` instance representing nested model if `subgraph=True`.
object model_to_dot_dyn(object model, ImplicitContainer<T> show_shapes, ImplicitContainer<T> show_layer_names, ImplicitContainer<T> rankdir, ImplicitContainer<T> expand_nested, ImplicitContainer<T> dpi, ImplicitContainer<T> subgraph)
Convert a Keras model to dot format.
Parameters
-
objectmodel - A Keras model instance.
-
ImplicitContainer<T>show_shapes - whether to display shape information.
-
ImplicitContainer<T>show_layer_names - whether to display layer names.
-
ImplicitContainer<T>rankdir - `rankdir` argument passed to PyDot, a string specifying the format of the plot: 'TB' creates a vertical plot; 'LR' creates a horizontal plot.
-
ImplicitContainer<T>expand_nested - whether to expand nested models into clusters.
-
ImplicitContainer<T>dpi - Dots per inch.
-
ImplicitContainer<T>subgraph - whether to return a `pydot.Cluster` instance.
Returns
-
object - A `pydot.Dot` instance representing the Keras model or a `pydot.Cluster` instance representing nested model if `subgraph=True`.
Model multi_gpu_model(Model model, IEnumerable<int> gpus, bool cpu_merge, bool cpu_relocation)
Replicates a model on different GPUs. Specifically, this function implements single-machine
multi-GPU data parallelism. It works in the following way: - Divide the model's input(s) into multiple sub-batches.
- Apply a model copy on each sub-batch. Every model copy
is executed on a dedicated GPU.
- Concatenate the results (on CPU) into one big batch. E.g. if your `batch_size` is 64 and you use `gpus=2`,
then we will divide the input into 2 sub-batches of 32 samples,
process each sub-batch on one GPU, then return the full
batch of 64 processed samples. This induces quasi-linear speedup on up to 8 GPUs. This function is only available with the TensorFlow backend
for the time being.
Parameters
-
Modelmodel - A Keras model instance. To avoid OOM errors, this model could have been built on CPU, for instance (see usage example below).
-
IEnumerable<int>gpus - Integer >= 2, number of on GPUs on which to create model replicas.
-
boolcpu_merge - A boolean value to identify whether to force merging model weights under the scope of the CPU or not.
-
boolcpu_relocation - A boolean value to identify whether to create the model's weights under the scope of the CPU. If the model is not defined under any preceding device scope, you can still rescue it by activating this option.
Returns
-
Model - A Keras `Model` instance which can be used just like the initial `model` argument, but which distributes its workload on multiple GPUs. Example 1: Training models with weights merge on CPU ```python import tensorflow as tf from keras.applications import Xception from keras.utils import multi_gpu_model import numpy as np num_samples = 1000 height = 224 width = 224 num_classes = 1000 # Instantiate the base model (or "template" model). # We recommend doing this with under a CPU device scope, # so that the model's weights are hosted on CPU memory. # Otherwise they may end up hosted on a GPU, which would # complicate weight sharing. with tf.device('/cpu:0'): model = Xception(weights=None, input_shape=(height, width, 3), classes=num_classes) # Replicates the model on 8 GPUs. # This assumes that your machine has 8 available GPUs. parallel_model = multi_gpu_model(model, gpus=8) parallel_model.compile(loss='categorical_crossentropy', optimizer='rmsprop') # Generate dummy data. x = np.random.random((num_samples, height, width, 3)) y = np.random.random((num_samples, num_classes)) # This `fit` call will be distributed on 8 GPUs. # Since the batch size is 256, each GPU will process 32 samples. parallel_model.fit(x, y, epochs=20, batch_size=256) # Save model via the template model (which shares the same weights): model.save('my_model.h5') ``` Example 2: Training models with weights merge on CPU using cpu_relocation ```python .. # Not needed to change the device scope for model definition: model = Xception(weights=None,..) try: model = multi_gpu_model(model, cpu_relocation=True) print("Training using multiple GPUs..") except: print("Training using single GPU or CPU..") model.compile(..) .. ``` Example 3: Training models with weights merge on GPU (recommended for NV-link) ```python .. # Not needed to change the device scope for model definition: model = Xception(weights=None,..) try: model = multi_gpu_model(model, cpu_merge=False) print("Training using multiple GPUs..") except: print("Training using single GPU or CPU..") model.compile(..) .. ```
Model multi_gpu_model(Model model, ValueTuple<IEnumerable<object>, object> gpus, bool cpu_merge, bool cpu_relocation)
Replicates a model on different GPUs. Specifically, this function implements single-machine
multi-GPU data parallelism. It works in the following way: - Divide the model's input(s) into multiple sub-batches.
- Apply a model copy on each sub-batch. Every model copy
is executed on a dedicated GPU.
- Concatenate the results (on CPU) into one big batch. E.g. if your `batch_size` is 64 and you use `gpus=2`,
then we will divide the input into 2 sub-batches of 32 samples,
process each sub-batch on one GPU, then return the full
batch of 64 processed samples. This induces quasi-linear speedup on up to 8 GPUs. This function is only available with the TensorFlow backend
for the time being.
Parameters
-
Modelmodel - A Keras model instance. To avoid OOM errors, this model could have been built on CPU, for instance (see usage example below).
-
ValueTuple<IEnumerable<object>, object>gpus - Integer >= 2, number of on GPUs on which to create model replicas.
-
boolcpu_merge - A boolean value to identify whether to force merging model weights under the scope of the CPU or not.
-
boolcpu_relocation - A boolean value to identify whether to create the model's weights under the scope of the CPU. If the model is not defined under any preceding device scope, you can still rescue it by activating this option.
Returns
-
Model - A Keras `Model` instance which can be used just like the initial `model` argument, but which distributes its workload on multiple GPUs. Example 1: Training models with weights merge on CPU ```python import tensorflow as tf from keras.applications import Xception from keras.utils import multi_gpu_model import numpy as np num_samples = 1000 height = 224 width = 224 num_classes = 1000 # Instantiate the base model (or "template" model). # We recommend doing this with under a CPU device scope, # so that the model's weights are hosted on CPU memory. # Otherwise they may end up hosted on a GPU, which would # complicate weight sharing. with tf.device('/cpu:0'): model = Xception(weights=None, input_shape=(height, width, 3), classes=num_classes) # Replicates the model on 8 GPUs. # This assumes that your machine has 8 available GPUs. parallel_model = multi_gpu_model(model, gpus=8) parallel_model.compile(loss='categorical_crossentropy', optimizer='rmsprop') # Generate dummy data. x = np.random.random((num_samples, height, width, 3)) y = np.random.random((num_samples, num_classes)) # This `fit` call will be distributed on 8 GPUs. # Since the batch size is 256, each GPU will process 32 samples. parallel_model.fit(x, y, epochs=20, batch_size=256) # Save model via the template model (which shares the same weights): model.save('my_model.h5') ``` Example 2: Training models with weights merge on CPU using cpu_relocation ```python .. # Not needed to change the device scope for model definition: model = Xception(weights=None,..) try: model = multi_gpu_model(model, cpu_relocation=True) print("Training using multiple GPUs..") except: print("Training using single GPU or CPU..") model.compile(..) .. ``` Example 3: Training models with weights merge on GPU (recommended for NV-link) ```python .. # Not needed to change the device scope for model definition: model = Xception(weights=None,..) try: model = multi_gpu_model(model, cpu_merge=False) print("Training using multiple GPUs..") except: print("Training using single GPU or CPU..") model.compile(..) .. ```
Model multi_gpu_model(Model model, int gpus, bool cpu_merge, bool cpu_relocation)
Replicates a model on different GPUs. Specifically, this function implements single-machine
multi-GPU data parallelism. It works in the following way: - Divide the model's input(s) into multiple sub-batches.
- Apply a model copy on each sub-batch. Every model copy
is executed on a dedicated GPU.
- Concatenate the results (on CPU) into one big batch. E.g. if your `batch_size` is 64 and you use `gpus=2`,
then we will divide the input into 2 sub-batches of 32 samples,
process each sub-batch on one GPU, then return the full
batch of 64 processed samples. This induces quasi-linear speedup on up to 8 GPUs. This function is only available with the TensorFlow backend
for the time being.
Parameters
-
Modelmodel - A Keras model instance. To avoid OOM errors, this model could have been built on CPU, for instance (see usage example below).
-
intgpus - Integer >= 2, number of on GPUs on which to create model replicas.
-
boolcpu_merge - A boolean value to identify whether to force merging model weights under the scope of the CPU or not.
-
boolcpu_relocation - A boolean value to identify whether to create the model's weights under the scope of the CPU. If the model is not defined under any preceding device scope, you can still rescue it by activating this option.
Returns
-
Model - A Keras `Model` instance which can be used just like the initial `model` argument, but which distributes its workload on multiple GPUs. Example 1: Training models with weights merge on CPU ```python import tensorflow as tf from keras.applications import Xception from keras.utils import multi_gpu_model import numpy as np num_samples = 1000 height = 224 width = 224 num_classes = 1000 # Instantiate the base model (or "template" model). # We recommend doing this with under a CPU device scope, # so that the model's weights are hosted on CPU memory. # Otherwise they may end up hosted on a GPU, which would # complicate weight sharing. with tf.device('/cpu:0'): model = Xception(weights=None, input_shape=(height, width, 3), classes=num_classes) # Replicates the model on 8 GPUs. # This assumes that your machine has 8 available GPUs. parallel_model = multi_gpu_model(model, gpus=8) parallel_model.compile(loss='categorical_crossentropy', optimizer='rmsprop') # Generate dummy data. x = np.random.random((num_samples, height, width, 3)) y = np.random.random((num_samples, num_classes)) # This `fit` call will be distributed on 8 GPUs. # Since the batch size is 256, each GPU will process 32 samples. parallel_model.fit(x, y, epochs=20, batch_size=256) # Save model via the template model (which shares the same weights): model.save('my_model.h5') ``` Example 2: Training models with weights merge on CPU using cpu_relocation ```python .. # Not needed to change the device scope for model definition: model = Xception(weights=None,..) try: model = multi_gpu_model(model, cpu_relocation=True) print("Training using multiple GPUs..") except: print("Training using single GPU or CPU..") model.compile(..) .. ``` Example 3: Training models with weights merge on GPU (recommended for NV-link) ```python .. # Not needed to change the device scope for model definition: model = Xception(weights=None,..) try: model = multi_gpu_model(model, cpu_merge=False) print("Training using multiple GPUs..") except: print("Training using single GPU or CPU..") model.compile(..) .. ```
object multi_gpu_model_dyn(object model, object gpus, ImplicitContainer<T> cpu_merge, ImplicitContainer<T> cpu_relocation)
Replicates a model on different GPUs. Specifically, this function implements single-machine
multi-GPU data parallelism. It works in the following way: - Divide the model's input(s) into multiple sub-batches.
- Apply a model copy on each sub-batch. Every model copy
is executed on a dedicated GPU.
- Concatenate the results (on CPU) into one big batch. E.g. if your `batch_size` is 64 and you use `gpus=2`,
then we will divide the input into 2 sub-batches of 32 samples,
process each sub-batch on one GPU, then return the full
batch of 64 processed samples. This induces quasi-linear speedup on up to 8 GPUs. This function is only available with the TensorFlow backend
for the time being.
Parameters
-
objectmodel - A Keras model instance. To avoid OOM errors, this model could have been built on CPU, for instance (see usage example below).
-
objectgpus - Integer >= 2, number of on GPUs on which to create model replicas.
-
ImplicitContainer<T>cpu_merge - A boolean value to identify whether to force merging model weights under the scope of the CPU or not.
-
ImplicitContainer<T>cpu_relocation - A boolean value to identify whether to create the model's weights under the scope of the CPU. If the model is not defined under any preceding device scope, you can still rescue it by activating this option.
Returns
-
object - A Keras `Model` instance which can be used just like the initial `model` argument, but which distributes its workload on multiple GPUs. Example 1: Training models with weights merge on CPU ```python import tensorflow as tf from keras.applications import Xception from keras.utils import multi_gpu_model import numpy as np num_samples = 1000 height = 224 width = 224 num_classes = 1000 # Instantiate the base model (or "template" model). # We recommend doing this with under a CPU device scope, # so that the model's weights are hosted on CPU memory. # Otherwise they may end up hosted on a GPU, which would # complicate weight sharing. with tf.device('/cpu:0'): model = Xception(weights=None, input_shape=(height, width, 3), classes=num_classes) # Replicates the model on 8 GPUs. # This assumes that your machine has 8 available GPUs. parallel_model = multi_gpu_model(model, gpus=8) parallel_model.compile(loss='categorical_crossentropy', optimizer='rmsprop') # Generate dummy data. x = np.random.random((num_samples, height, width, 3)) y = np.random.random((num_samples, num_classes)) # This `fit` call will be distributed on 8 GPUs. # Since the batch size is 256, each GPU will process 32 samples. parallel_model.fit(x, y, epochs=20, batch_size=256) # Save model via the template model (which shares the same weights): model.save('my_model.h5') ``` Example 2: Training models with weights merge on CPU using cpu_relocation ```python .. # Not needed to change the device scope for model definition: model = Xception(weights=None,..) try: model = multi_gpu_model(model, cpu_relocation=True) print("Training using multiple GPUs..") except: print("Training using single GPU or CPU..") model.compile(..) .. ``` Example 3: Training models with weights merge on GPU (recommended for NV-link) ```python .. # Not needed to change the device scope for model definition: model = Xception(weights=None,..) try: model = multi_gpu_model(model, cpu_merge=False) print("Training using multiple GPUs..") except: print("Training using single GPU or CPU..") model.compile(..) .. ```
object normalize(object x, int axis, int order)
Normalizes a Numpy array.
Parameters
-
objectx - Numpy array to normalize.
-
intaxis - axis along which to normalize.
-
intorder - Normalization order (e.g. 2 for L2 norm).
Returns
-
object - A normalized copy of the array.
object normalize_dyn(object x, ImplicitContainer<T> axis, ImplicitContainer<T> order)
Normalizes a Numpy array.
Parameters
-
objectx - Numpy array to normalize.
-
ImplicitContainer<T>axis - axis along which to normalize.
-
ImplicitContainer<T>order - Normalization order (e.g. 2 for L2 norm).
Returns
-
object - A normalized copy of the array.
void plot_model(Model model, string to_file, bool show_shapes, bool show_layer_names, string rankdir, bool expand_nested, int dpi)
Converts a Keras model to dot format and save to a file.
Parameters
-
Modelmodel - A Keras model instance
-
stringto_file - File name of the plot image.
-
boolshow_shapes - whether to display shape information.
-
boolshow_layer_names - whether to display layer names.
-
stringrankdir - `rankdir` argument passed to PyDot, a string specifying the format of the plot: 'TB' creates a vertical plot; 'LR' creates a horizontal plot.
-
boolexpand_nested - Whether to expand nested models into clusters.
-
intdpi - Dots per inch.
Returns
-
void - A Jupyter notebook Image object if Jupyter is installed. This enables in-line display of the model plots in notebooks.
object plot_model_dyn(object model, ImplicitContainer<T> to_file, ImplicitContainer<T> show_shapes, ImplicitContainer<T> show_layer_names, ImplicitContainer<T> rankdir, ImplicitContainer<T> expand_nested, ImplicitContainer<T> dpi)
Converts a Keras model to dot format and save to a file.
Parameters
-
objectmodel - A Keras model instance
-
ImplicitContainer<T>to_file - File name of the plot image.
-
ImplicitContainer<T>show_shapes - whether to display shape information.
-
ImplicitContainer<T>show_layer_names - whether to display layer names.
-
ImplicitContainer<T>rankdir - `rankdir` argument passed to PyDot, a string specifying the format of the plot: 'TB' creates a vertical plot; 'LR' creates a horizontal plot.
-
ImplicitContainer<T>expand_nested - Whether to expand nested models into clusters.
-
ImplicitContainer<T>dpi - Dots per inch.
Returns
-
object - A Jupyter notebook Image object if Jupyter is installed. This enables in-line display of the model plots in notebooks.
object serialize_keras_object(object instance)
object serialize_keras_object(PythonFunctionContainer instance)
object serialize_keras_object_dyn(object instance)
object to_categorical(ndarray y, Nullable<int> num_classes, string dtype)
Converts a class vector (integers) to binary class matrix. E.g. for use with categorical_crossentropy.
Parameters
-
ndarrayy - class vector to be converted into a matrix (integers from 0 to num_classes).
-
Nullable<int>num_classes - total number of classes.
-
stringdtype - The data type expected by the input. Default: `'float32'`.
Returns
-
object - A binary matrix representation of the input. The classes axis is placed last.
object to_categorical_dyn(object y, object num_classes, ImplicitContainer<T> dtype)
Converts a class vector (integers) to binary class matrix. E.g. for use with categorical_crossentropy.
Parameters
-
objecty - class vector to be converted into a matrix (integers from 0 to num_classes).
-
objectnum_classes - total number of classes.
-
ImplicitContainer<T>dtype - The data type expected by the input. Default: `'float32'`.
Returns
-
object - A binary matrix representation of the input. The classes axis is placed last.