Show / Hide Table of Contents

Class Util

Inheritance
System.Object
Keras
Base
Util
Implements
System.IDisposable
Inherited Members
Base.Parameters
Base.None
Base.Init()
Base.ToPython()
Base.InvokeStaticMethod(Object, String, Dictionary<String, Object>)
Base.InvokeMethod(String, Dictionary<String, Object>)
Base.Item[String]
Keras.Instance
Keras.keras
Keras.keras2onnx
Keras.tfjs
Keras.Dispose()
Keras.ToTuple(Array)
Keras.ToList(Array)
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Keras.Utils
Assembly: Keras.dll
Syntax
public class Util : Base, IDisposable

Methods

| Improve this Doc View Source

MultiGPUModel(BaseModel, Int32[], Boolean, Boolean)

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.

Declaration
public static BaseModel MultiGPUModel(BaseModel model, int[] gpus, bool cpu_merge = true, bool cpu_relocation = false)
Parameters
Type Name Description
BaseModel model

A Keras model instance. To avoid OOM errors, this model could have been built on CPU, for instance.

System.Int32[] gpus

Integer >= 2 or list of integers, number of GPUs or list of GPU IDs on which to create model replicas.

System.Boolean cpu_merge

Integer >= 2 or list of integers, number of GPUs or list of GPU IDs on which to create model replicas.

System.Boolean 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
Type Description
BaseModel

A Keras Model instance which can be used just like the initial model argument, but which distributes its workload on multiple GPUs.

| Improve this Doc View Source

Normalize(NDarray, Int32, Int32)

Normalizes a Numpy array.

Declaration
public static NDarray Normalize(NDarray y, int axis = -1, int order = 2)
Parameters
Type Name Description
Numpy.NDarray y

Numpy array to normalize.

System.Int32 axis

axis along which to normalize.

System.Int32 order

Normalization order (e.g. 2 for L2 norm).

Returns
Type Description
Numpy.NDarray
| Improve this Doc View Source

PlotModel(BaseModel, String, Boolean, Boolean, String, Boolean, Int32)

Converts a Keras model to dot format and save to a file.

Declaration
public static void PlotModel(BaseModel model, string to_file = "model.png", bool show_shapes = false, bool show_layer_names = true, string rankdir = "TB", bool expand_nested = false, int dpi = 96)
Parameters
Type Name Description
BaseModel model

A Keras model instance

System.String to_file

File name of the plot image.

System.Boolean show_shapes

whether to display shape information.

System.Boolean show_layer_names

whether to display layer names.

System.String rankdir
System.Boolean expand_nested

whether to expand nested models into clusters.

System.Int32 dpi

dot DPI.

| Improve this Doc View Source

ToCategorical(NDarray, Nullable<Int32>, String)

Converts a class vector (integers) to binary class matrix. E.g. for use with categorical_crossentropy.

Declaration
public static NDarray ToCategorical(NDarray y, int? num_classes = default(int? ), string dtype = "float32")
Parameters
Type Name Description
Numpy.NDarray y

class vector to be converted into a matrix (integers from 0 to num_classes).

System.Nullable<System.Int32> num_classes

total number of classes.

System.String dtype

The data type expected by the input, as a string (float32, float64, int32...)

Returns
Type Description
Numpy.NDarray

A binary matrix representation of the input. The classes axis is placed last.

Implements

System.IDisposable
  • Improve this Doc
  • View Source
Back to top Generated by DocFX