neuralgym

class neuralgym.Config(filename=None)

Bases: dict

Config with yaml file.

This class is used to config model hyper-parameters, global constants, and other settings with yaml file. All settings in yaml file will be automatically logged into file.

Parameters:filename (str) – File name.

Examples

yaml file model.yml:

NAME: 'neuralgym'
ALPHA: 1.0
DATASET: '/mnt/data/imagenet'

Usage in .py:

>>> from neuralgym import Config
>>> config = Config('model.yml')
>>> print(config.NAME)
    neuralgym
>>> print(config.ALPHA)
    1.0
>>> print(config.DATASET)
    /mnt/data/imagenet
neuralgym.get_gpus(num_gpus=1, dedicated=True, verbose=True)

Auto-select gpus for running by setting CUDA_VISIBLE_DEVICES.

Parameters:
  • num_gpus (int) – Number of GPU(s) to get.
  • dedicated (bool) – Dedicated GPU or not, i.e. one process for one GPU.
  • verbose (bool) – Display nvidia-smi info if verbose is true.
Returns:

A list of selected GPU(s).

Return type:

list

neuralgym.set_gpus(gpus)

Set environment variable CUDA_VISIBLE_DEVICES to a list of gpus.

Parameters:gpus (int or list) – GPU id or a list of GPU ids.
neuralgym.date_uid()

Generate a unique id based on date.

Returns:Return uid string, e.g. ‘20171122171307111552’.
Return type:str
neuralgym.unset_logger()

Unset logger of neuralgym.