Module monk.gluon.models.params

Expand source code
from gluon.models.imports import *
from system.imports import *
from gluon.models.models import combined_list_lower



def set_model_name(name, system_dict):
    '''
    Set base model name for transfer learning.

    Args:
        name (str): Select from available models. Check via List_Models() function
        system_dict (dict): System Dictionary

    Returns:
        dict: Updated system dictionary.
    '''
    if(name not in combined_list_lower):
        msg = "Model name {} not in {}".format(name, combined_list_lower);
        raise ConstraintError(msg);
    system_dict["model"]["params"]["model_name"] = name;
    return system_dict;





def set_device(value, system_dict):
    '''
    Set whether to use gpu or not

    Args:
        value (bool): If set as True, uses GPU
        system_dict (dict): System Dictionary

    Returns:
        dict: Updated system dictionary.
    '''
    GPUs = GPUtil.getGPUs()
    if(value and len(GPUs)==0):
        msg = "GPU not accessible yet requested."
        ConstraintWarning(msg)
        system_dict["model"]["params"]["use_gpu"] = False;
    else:
        system_dict["model"]["params"]["use_gpu"] = value;
    return system_dict;




def set_pretrained(value, system_dict):
    '''
    Set whether to use pretrained models or randomly initialized weights

    Args:
        value (bool): If set as True, use weights trained on imagenet and coco like dataset
                                    Else, use randomly initialized weights
        system_dict (dict): System Dictionary

    Returns:
        dict: Updated system dictionary.
    '''
    system_dict["model"]["params"]["use_pretrained"] = value;
    return system_dict;




def set_freeze_base_network(value, system_dict):
    '''
    Set whether to freeze base network or not

    Args:
        value (bool): If set as True, then base network's weights are freezed (cannot be trained)
        system_dict (dict): System Dictionary

    Returns:
        dict: Updated system dictionary.
    '''
    system_dict["model"]["params"]["freeze_base_network"] = value;
    return system_dict;




def set_model_path(path, system_dict):
    '''
    Set path to custom weights for model

    Args:
        path (str): Path to custom model weights for initialization.
        system_dict (dict): System Dictionary
        
    Returns:
        dict: Updated system dictionary.
    '''
    system_dict["model"]["params"]["model_path"] = path;
    return system_dict;

Functions

def set_device(value, system_dict)

Set whether to use gpu or not

Args

value : bool
If set as True, uses GPU
system_dict : dict
System Dictionary

Returns

dict
Updated system dictionary.
Expand source code
def set_device(value, system_dict):
    '''
    Set whether to use gpu or not

    Args:
        value (bool): If set as True, uses GPU
        system_dict (dict): System Dictionary

    Returns:
        dict: Updated system dictionary.
    '''
    GPUs = GPUtil.getGPUs()
    if(value and len(GPUs)==0):
        msg = "GPU not accessible yet requested."
        ConstraintWarning(msg)
        system_dict["model"]["params"]["use_gpu"] = False;
    else:
        system_dict["model"]["params"]["use_gpu"] = value;
    return system_dict;
def set_freeze_base_network(value, system_dict)

Set whether to freeze base network or not

Args

value : bool
If set as True, then base network's weights are freezed (cannot be trained)
system_dict : dict
System Dictionary

Returns

dict
Updated system dictionary.
Expand source code
def set_freeze_base_network(value, system_dict):
    '''
    Set whether to freeze base network or not

    Args:
        value (bool): If set as True, then base network's weights are freezed (cannot be trained)
        system_dict (dict): System Dictionary

    Returns:
        dict: Updated system dictionary.
    '''
    system_dict["model"]["params"]["freeze_base_network"] = value;
    return system_dict;
def set_model_name(name, system_dict)

Set base model name for transfer learning.

Args

name : str
Select from available models. Check via List_Models() function
system_dict : dict
System Dictionary

Returns

dict
Updated system dictionary.
Expand source code
def set_model_name(name, system_dict):
    '''
    Set base model name for transfer learning.

    Args:
        name (str): Select from available models. Check via List_Models() function
        system_dict (dict): System Dictionary

    Returns:
        dict: Updated system dictionary.
    '''
    if(name not in combined_list_lower):
        msg = "Model name {} not in {}".format(name, combined_list_lower);
        raise ConstraintError(msg);
    system_dict["model"]["params"]["model_name"] = name;
    return system_dict;
def set_model_path(path, system_dict)

Set path to custom weights for model

Args

path : str
Path to custom model weights for initialization.
system_dict : dict
System Dictionary

Returns

dict
Updated system dictionary.
Expand source code
def set_model_path(path, system_dict):
    '''
    Set path to custom weights for model

    Args:
        path (str): Path to custom model weights for initialization.
        system_dict (dict): System Dictionary
        
    Returns:
        dict: Updated system dictionary.
    '''
    system_dict["model"]["params"]["model_path"] = path;
    return system_dict;
def set_pretrained(value, system_dict)

Set whether to use pretrained models or randomly initialized weights

Args

value : bool
If set as True, use weights trained on imagenet and coco like dataset Else, use randomly initialized weights
system_dict : dict
System Dictionary

Returns

dict
Updated system dictionary.
Expand source code
def set_pretrained(value, system_dict):
    '''
    Set whether to use pretrained models or randomly initialized weights

    Args:
        value (bool): If set as True, use weights trained on imagenet and coco like dataset
                                    Else, use randomly initialized weights
        system_dict (dict): System Dictionary

    Returns:
        dict: Updated system dictionary.
    '''
    system_dict["model"]["params"]["use_pretrained"] = value;
    return system_dict;