Module monk.gluon.models.initializers

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



def initialize_network(net, initializer):
    '''
    Get the right initializer for custom network weight initialization

    Args:
        initializer (str): The type of initializer

    Returns:
        gluon mxnet initializer: The type of initializer
    '''
    if(initializer == "xavier_normal"):
        net.initialize(initializer_xavier_normal(), ctx = ctx);
    elif(initializer == "xavier_uniform"):
        net.initialize(initializer_xavier_uniform(), ctx = ctx);
    elif(initializer == "msra"):
        net.initialize(initializer_msra(), ctx = ctx);
    elif(initializer == "normal"):
        net.initialize(initializer_normal(), ctx = ctx);
    elif(initializer == "orthogonal_normal"):
        net.initialize(initializer_orthogonal_normal(), ctx = ctx);
    elif(initializer == "orthogonal_uniform"):
        net.initialize(initializer_orthogonal_uniform(), ctx = ctx);
    elif(initializer == "uniform"):
        net.initialize(initializer_uniform(), ctx = ctx);

    return net;
    




def initializer_xavier_normal():
    '''
    Get Xavier normal initialization

    Args:
        None

    Returns:
        gluon mxnet initializer: Xavier Normal intializer
    '''
    return initializer.Xavier(rnd_type='gaussian');





def initializer_xavier_uniform():
    '''
    Get Xavier uniform initialization

    Args:
        None

    Returns:
        gluon mxnet initializer: Xavier uniform intializer
    '''
    return initializer.Xavier(rnd_type='uniform');




def initializer_msra():
    '''
    Get MSRA initialization

    Args:
        None

    Returns:
        gluon mxnet initializer: MSRA intializer
    '''
    return initializer.MSRAPrelu();




def initializer_normal():
    '''
    Get normal initialization

    Args:
        None

    Returns:
        gluon mxnet initializer: normal intializer
    '''
    return initializer.Normal();




def initializer_orthogonal_normal():
    '''
    Get orthogonal normal initialization

    Args:
        None

    Returns:
        gluon mxnet initializer: Orthogonal normal intializer
    '''
    return initializer.Orthogonal(rand_type='normal');





def initializer_orthogonal_uniform():
    '''
    Get orthogonal uniform initialization

    Args:
        None

    Returns:
        gluon mxnet initializer: Orthogonal uniform intializer
    '''
    return initializer.Orthogonal(rand_type='uniform');





def initializer_uniform():
    '''
    Get uniform initialization

    Args:
        None

    Returns:
        gluon mxnet initializer: Uniform intializer
    '''
    return initializer.Uniform();

Functions

def initialize_network(net, initializer)

Get the right initializer for custom network weight initialization

Args

initializer : str
The type of initializer

Returns

gluon mxnet initializer: The type of initializer
 
Expand source code
def initialize_network(net, initializer):
    '''
    Get the right initializer for custom network weight initialization

    Args:
        initializer (str): The type of initializer

    Returns:
        gluon mxnet initializer: The type of initializer
    '''
    if(initializer == "xavier_normal"):
        net.initialize(initializer_xavier_normal(), ctx = ctx);
    elif(initializer == "xavier_uniform"):
        net.initialize(initializer_xavier_uniform(), ctx = ctx);
    elif(initializer == "msra"):
        net.initialize(initializer_msra(), ctx = ctx);
    elif(initializer == "normal"):
        net.initialize(initializer_normal(), ctx = ctx);
    elif(initializer == "orthogonal_normal"):
        net.initialize(initializer_orthogonal_normal(), ctx = ctx);
    elif(initializer == "orthogonal_uniform"):
        net.initialize(initializer_orthogonal_uniform(), ctx = ctx);
    elif(initializer == "uniform"):
        net.initialize(initializer_uniform(), ctx = ctx);

    return net;
def initializer_msra()

Get MSRA initialization

Args

None
 

Returns

gluon mxnet initializer: MSRA intializer
 
Expand source code
def initializer_msra():
    '''
    Get MSRA initialization

    Args:
        None

    Returns:
        gluon mxnet initializer: MSRA intializer
    '''
    return initializer.MSRAPrelu();
def initializer_normal()

Get normal initialization

Args

None
 

Returns

gluon mxnet initializer: normal intializer
 
Expand source code
def initializer_normal():
    '''
    Get normal initialization

    Args:
        None

    Returns:
        gluon mxnet initializer: normal intializer
    '''
    return initializer.Normal();
def initializer_orthogonal_normal()

Get orthogonal normal initialization

Args

None
 

Returns

gluon mxnet initializer: Orthogonal normal intializer
 
Expand source code
def initializer_orthogonal_normal():
    '''
    Get orthogonal normal initialization

    Args:
        None

    Returns:
        gluon mxnet initializer: Orthogonal normal intializer
    '''
    return initializer.Orthogonal(rand_type='normal');
def initializer_orthogonal_uniform()

Get orthogonal uniform initialization

Args

None
 

Returns

gluon mxnet initializer: Orthogonal uniform intializer
 
Expand source code
def initializer_orthogonal_uniform():
    '''
    Get orthogonal uniform initialization

    Args:
        None

    Returns:
        gluon mxnet initializer: Orthogonal uniform intializer
    '''
    return initializer.Orthogonal(rand_type='uniform');
def initializer_uniform()

Get uniform initialization

Args

None
 

Returns

gluon mxnet initializer: Uniform intializer
 
Expand source code
def initializer_uniform():
    '''
    Get uniform initialization

    Args:
        None

    Returns:
        gluon mxnet initializer: Uniform intializer
    '''
    return initializer.Uniform();
def initializer_xavier_normal()

Get Xavier normal initialization

Args

None
 

Returns

gluon mxnet initializer: Xavier Normal intializer
 
Expand source code
def initializer_xavier_normal():
    '''
    Get Xavier normal initialization

    Args:
        None

    Returns:
        gluon mxnet initializer: Xavier Normal intializer
    '''
    return initializer.Xavier(rnd_type='gaussian');
def initializer_xavier_uniform()

Get Xavier uniform initialization

Args

None
 

Returns

gluon mxnet initializer: Xavier uniform intializer
 
Expand source code
def initializer_xavier_uniform():
    '''
    Get Xavier uniform initialization

    Args:
        None

    Returns:
        gluon mxnet initializer: Xavier uniform intializer
    '''
    return initializer.Xavier(rnd_type='uniform');