Пример #1
0
def dense(params):
    imap = initializer_map(params)

    return kl.Dense(get_units(params),
                    dtype=tf.float32,
                    activation=activation_function(params),
                    use_bias=True,
                    kernel_initializer=imap['weights'],
                    bias_initializer=imap['offset'])
Пример #2
0
    def __init__(self, params, path_names, block_type):
        super(BlockLayer, self).__init__()

        self._block_name = block_type
        self._path_names = path_names
        self._paths = []

        for name in path_names:
            self._paths.append(make_sequence(params[name], SIMPLE_LAYERS))

        self._activator = kl.Activation(activation_function(params))
Пример #3
0
def depthwise_conv_2d(params):
    imap = initializer_map(params)
    nfilters, kernel_dimensions = get_shape_params(params)

    return kl.DepthwiseConv2D(kernel_size=kernel_dimensions,
                              strides=params['strides'],
                              dtype=tf.float32,
                              padding=params['padding'],
                              use_bias=params.get('bias', None) is not None,
                              depth_multiplier=params['depth_multiplier'],
                              activation=activation_function(params),
                              depthwise_initializer=imap['kernel'],
                              bias_initializer=imap['bias'])
Пример #4
0
def conv_2d(params):
    imap = initializer_map(params)
    nfilters, kernel_dimensions = get_shape_params(params)

    return kl.Conv2D(filters=nfilters,
                     kernel_size=kernel_dimensions,
                     dtype=tf.float32,
                     strides=params['strides'],
                     padding=params['padding'],
                     use_bias=params.get('bias', None) is not None,
                     activation=activation_function(params),
                     kernel_initializer=imap['kernel'],
                     kernel_regularizer=tf.keras.regularizers.l2(0.0005),
                     bias_initializer=imap['bias'])
Пример #5
0
def separable_conv_2d(params):
    imap = initializer_map(params)
    nfilters, kernel_dimensions = get_shape_params(params)

    return kl.SeparableConv2D(
        filters=nfilters,
        kernel_size=kernel_dimensions,
        dtype=tf.float32,
        strides=params["strides"],
        padding=params["padding"],
        use_bias=params.get("bias", None) is not None,
        depth_multiplier=params["depth_multiplier"],
        activation=activation_function(params),
        depthwise_initializer=imap["depth_kernel"],
        pointwise_initializer=imap["point_kernel"],
        bias_initializer=imap["bias"],
    )
Пример #6
0
def dense_with_weights(params):
    imap = {}

    for key in ["weights", "offset"]:
        if isinstance(params[key], str):
            imap[key] = params[key]
        else:
            imap[key] = tf.constant_initializer(np.array(params[key]))

    return kl.Dense(
        get_units(params),
        dtype=tf.float32,
        activation=activation_function(params),
        use_bias=True,
        kernel_initializer=imap["weights"],
        bias_initializer=imap["offset"],
    )
Пример #7
0
def with_popped_activation(params):
    afn = activation_function(params)
    params_copy = dict(params)
    params_copy.pop('activation_function', None)

    return params_copy, afn
Пример #8
0
 def __init__(self, params, path_names, block_type):
     self._paths = [params[name] for name in path_names]
     self._activator = kl.Activation(activation_function(params))
Пример #9
0
def activation(params):
    return kl.Activation(activation_function(params))