當前位置: 首頁>>代碼示例>>Python>>正文


Python layers.LocallyConnected1D方法代碼示例

本文整理匯總了Python中keras.layers.LocallyConnected1D方法的典型用法代碼示例。如果您正苦於以下問題:Python layers.LocallyConnected1D方法的具體用法?Python layers.LocallyConnected1D怎麽用?Python layers.LocallyConnected1D使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在keras.layers的用法示例。


在下文中一共展示了layers.LocallyConnected1D方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_keras_import

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import LocallyConnected1D [as 別名]
def test_keras_import(self):
        # Conv 1D
        model = Sequential()
        model.add(LocallyConnected1D(32, 3, kernel_regularizer=regularizers.l2(0.01),
                                     bias_regularizer=regularizers.l2(0.01),
                                     activity_regularizer=regularizers.l2(0.01), kernel_constraint='max_norm',
                                     bias_constraint='max_norm', activation='relu', input_shape=(16, 10)))
        model.build()
        self.keras_param_test(model, 1, 12)
        # Conv 2D
        model = Sequential()
        model.add(LocallyConnected2D(32, (3, 3), kernel_regularizer=regularizers.l2(0.01),
                                     bias_regularizer=regularizers.l2(0.01),
                                     activity_regularizer=regularizers.l2(0.01), kernel_constraint='max_norm',
                                     bias_constraint='max_norm', activation='relu', input_shape=(16, 16, 10)))
        model.build()
        self.keras_param_test(model, 1, 14)


# ********** Recurrent Layers ********** 
開發者ID:Cloud-CV,項目名稱:Fabrik,代碼行數:22,代碼來源:test_views.py

示例2: localconv1d

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import LocallyConnected1D [as 別名]
def localconv1d(x, filters, kernel_size, strides=1, use_bias=True, name=None):
    """LocallyConnected1D possibly wrapped by a TimeDistributed layer."""
    f = LocallyConnected1D(filters, kernel_size, strides=strides,
            use_bias=use_bias, name=name)

    return TimeDistributed(f, name=name)(x) if K.ndim(x) == 4 else f(x) 
開發者ID:dluvizon,項目名稱:deephar,代碼行數:8,代碼來源:layers.py

示例3: add_conv_layer

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import LocallyConnected1D [as 別名]
def add_conv_layer(model, layer_params, input_dim=None, locally_connected=False):
    if len(layer_params) == 3: # 1D convolution
        filters = layer_params[0]
        filter_len = layer_params[1]
        stride = layer_params[2]
        if locally_connected:
            if input_dim:
                model.add(LocallyConnected1D(filters, filter_len, strides=stride, input_shape=(input_dim, 1)))
            else:
                model.add(LocallyConnected1D(filters, filter_len, strides=stride))
        else:
            if input_dim:
                model.add(Conv1D(filters, filter_len, strides=stride, input_shape=(input_dim, 1)))
            else:
                model.add(Conv1D(filters, filter_len, strides=stride))
    elif len(layer_params) == 5: # 2D convolution
        filters = layer_params[0]
        filter_len = (layer_params[1], layer_params[2])
        stride = (layer_params[3], layer_params[4])
        if locally_connected:
            if input_dim:
                model.add(LocallyConnected2D(filters, filter_len, strides=stride, input_shape=(input_dim, 1)))
            else:
                model.add(LocallyConnected2D(filters, filter_len, strides=stride))
        else:
            if input_dim:
                model.add(Conv2D(filters, filter_len, strides=stride, input_shape=(input_dim, 1)))
            else:
                model.add(Conv2D(filters, filter_len, strides=stride))
    return model 
開發者ID:ECP-CANDLE,項目名稱:Benchmarks,代碼行數:32,代碼來源:p1b3_baseline_keras2.py

示例4: locally_connected

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import LocallyConnected1D [as 別名]
def locally_connected(layer, layer_in, layerId, tensor=True):
    localMap = {
        '1D': LocallyConnected1D,
        '2D': LocallyConnected2D,
    }
    out = {}
    kernel_initializer = layer['params']['kernel_initializer']
    bias_initializer = layer['params']['bias_initializer']
    filters = layer['params']['filters']
    kernel_regularizer = regularizerMap[layer['params']['kernel_regularizer']]
    bias_regularizer = regularizerMap[layer['params']['bias_regularizer']]
    activity_regularizer = regularizerMap[layer['params']
                                          ['activity_regularizer']]
    kernel_constraint = constraintMap[layer['params']['kernel_constraint']]
    bias_constraint = constraintMap[layer['params']['bias_constraint']]
    use_bias = layer['params']['use_bias']
    layer_type = layer['params']['layer_type']
    if (layer_type == '1D'):
        strides = layer['params']['stride_w']
        kernel = layer['params']['kernel_w']
    else:
        strides = (layer['params']['stride_h'], layer['params']['stride_w'])
        kernel = (layer['params']['kernel_h'], layer['params']['kernel_w'])
    out[layerId] = localMap[layer_type](filters, kernel, strides=strides, padding='valid',
                                        kernel_initializer=kernel_initializer,
                                        bias_initializer=bias_initializer,
                                        kernel_regularizer=kernel_regularizer,
                                        bias_regularizer=bias_regularizer,
                                        activity_regularizer=activity_regularizer, use_bias=use_bias,
                                        bias_constraint=bias_constraint,
                                        kernel_constraint=kernel_constraint)
    if tensor:
        out[layerId] = out[layerId](*layer_in)
    return out


# ********** Recurrent Layers ********** 
開發者ID:Cloud-CV,項目名稱:Fabrik,代碼行數:39,代碼來源:layers_export.py

示例5: test_keras_export

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import LocallyConnected1D [as 別名]
def test_keras_export(self):
        tests = open(os.path.join(settings.BASE_DIR, 'tests', 'unit', 'keras_app',
                                  'keras_export_test.json'), 'r')
        response = json.load(tests)
        tests.close()
        net = yaml.safe_load(json.dumps(response['net']))
        net = {'l0': net['Input'], 'l1': net['Input2'], 'l3': net['LocallyConnected']}
        # LocallyConnected 1D
        net['l1']['connection']['output'].append('l3')
        net['l3']['connection']['input'] = ['l1']
        net['l3']['params']['layer_type'] = '1D'
        inp = data(net['l1'], '', 'l1')['l1']
        temp = locally_connected(net['l3'], [inp], 'l3')
        model = Model(inp, temp['l3'])
        self.assertEqual(model.layers[1].__class__.__name__, 'LocallyConnected1D')
        # LocallyConnected 2D
        net['l0']['connection']['output'].append('l0')
        net['l0']['shape']['output'] = [3, 10, 10]
        net['l3']['connection']['input'] = ['l0']
        net['l3']['params']['layer_type'] = '2D'
        inp = data(net['l0'], '', 'l0')['l0']
        temp = locally_connected(net['l3'], [inp], 'l3')
        model = Model(inp, temp['l3'])
        self.assertEqual(model.layers[1].__class__.__name__, 'LocallyConnected2D')


# ********** Recurrent Layers Test ********** 
開發者ID:Cloud-CV,項目名稱:Fabrik,代碼行數:29,代碼來源:test_views.py


注:本文中的keras.layers.LocallyConnected1D方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。