Class Util
Implements
Inherited Members
Namespace: Keras.Utils
Assembly: Keras.dll
Syntax
public class Util : Base, IDisposable
Methods
| Improve this Doc View SourceMultiGPUModel(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. |
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 |
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. |
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. |