kgcnn.utils package¶
Submodules¶
kgcnn.utils.devices module¶
-
kgcnn.utils.devices.
check_device
()[source]¶ Simple function to check for available devices for computing models. Mostly GPUs.
-
kgcnn.utils.devices.
set_cuda_device
(device_id: Union[int, list])[source]¶ Set the cuda device by ID.
Better use cuda environment variable to do this instead of this function:
import os os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID" os.environ["CUDA_VISIBLE_DEVICES"]="1" # specify which GPU(s) to be used
- Parameters
device_id (int) – ID of the GPU to set.
kgcnn.utils.plots module¶
-
kgcnn.utils.plots.
plot_predict_true
(y_predict, y_true, data_unit: Optional[list] = None, model_name: str = '', filepath: Optional[str] = None, file_name: str = '', dataset_name: str = '', target_names: Optional[list] = None, figsize: Optional[list] = None, dpi: Optional[float] = None, show_fig: bool = False, scaled_predictions: bool = False)[source]¶ Make a scatter plot of predicted versus actual targets. Not for k-splits.
- Parameters
y_predict (np.ndarray) – Numpy array of shape (N_samples, n_targets) or (N_samples, ).
y_true (np.ndarray) – Numpy array of shape (N_samples, n_targets) or (N_samples, ).
data_unit (list) – String or list of string that matches n_targets. Name of the data’s unit.
model_name (str) – Name of the model. Default is “”.
filepath (str) – Full path where to save plot to, without the name of the file. Default is “”.
file_name (str) – File name base. Model name and dataset will be added to the name. Default is “”.
dataset_name (str) – Name of the dataset which was fitted to. Default is “”.
target_names (list) – String or list of string that matches n_targets. Name of the targets.
figsize (list) – Size of the figure. Default is None.
dpi (float) – The resolution of the figure in dots-per-inch. Default is None.
show_fig (bool) – Whether to show figure. Default is True.
scaled_predictions (bool) – Whether predictions had been standardized. Default is False.
- Returns
Figure of the scatter plot.
- Return type
matplotlib.pyplot.figure
-
kgcnn.utils.plots.
plot_train_test_loss
(histories: list, loss_name: Optional[str] = None, val_loss_name: Optional[str] = None, data_unit: str = '', model_name: str = '', filepath: Optional[str] = None, file_name: str = '', dataset_name: str = '', figsize: Optional[list] = None, dpi: Optional[float] = None, show_fig: bool = True)[source]¶ Plot training curves for a list of fit results in form of keras history objects. This means, training- and test-loss is plotted vs. epochs for all splits.
- Parameters
histories (list) – List of
tf.keras.callbacks.History()
objects.loss_name (str) – Which loss or metric to pick from history for plotting. Default is “loss”.
val_loss_name (str) – Which validation loss or metric to pick from history for plotting. Default is “val_loss”.
data_unit (str) – Unit of the loss. Default is “”.
model_name (str) – Name of the model. Default is “”.
filepath (str) – Full path where to save plot to, without the name of the file. Default is “”.
file_name (str) – File name base. Model name and dataset will be added to the name. Default is “”.
dataset_name (str) – Name of the dataset which was fitted to. Default is “”.
figsize (list) – Size of the figure. Default is None.
dpi (float) – The resolution of the figure in dots-per-inch. Default is None.
show_fig (bool) – Whether to show figure. Default is True.
- Returns
Figure of the training curves.
- Return type
matplotlib.pyplot.figure
kgcnn.utils.serial module¶
-
kgcnn.utils.serial.
deserialize
(obj_dict: dict) → Any[source]¶ General deserialization scheme for objects. Requires module information. For each submodule there might be a separate deserialization scheme, that works e.g. with name only.
- Parameters
obj_dict – Serialized object.
- Returns
Class or object from
obj_dict
.- Return type
Any