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


Python layers.ActivityRegularization方法代碼示例

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


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

示例1: test_activity_regularization

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import ActivityRegularization [as 別名]
def test_activity_regularization():
    layer = layers.ActivityRegularization(l1=0.01, l2=0.01)

    # test in functional API
    x = layers.Input(shape=(3,))
    z = layers.Dense(2)(x)
    y = layer(z)
    model = Model(x, y)
    model.compile('rmsprop', 'mse')

    model.predict(np.random.random((2, 3)))

    # test serialization
    model_config = model.get_config()
    model = Model.from_config(model_config)
    model.compile('rmsprop', 'mse') 
開發者ID:hello-sea,項目名稱:DeepLearning_Wavelet-LSTM,代碼行數:18,代碼來源:core_test.py

示例2: create_simnet_network

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import ActivityRegularization [as 別名]
def create_simnet_network(input_shape, weights):
    L2_REGULARIZATION = 0.001

    input = Input(shape=input_shape)

    # CNN 1
    vgg16 = create_vgg16_network(input_shape, weights)
    cnn_1 = vgg16(input)

    # CNN 2
    # Downsample by 4:1
    cnn_2 = MaxPooling2D(pool_size=(4, 4))(input)
    cnn_2 = Conv2D(128, (3, 3), padding='same', activation='relu')(cnn_2)
    cnn_2 = Conv2D(128, (3, 3), padding='same', activation='relu')(cnn_2)
    cnn_2 = Conv2D(256, (3, 3), padding='same', activation='relu')(cnn_2)
    cnn_2 = Dropout(0.5)(cnn_2)
    cnn_2 = Flatten()(cnn_2)
    cnn_2 = Dense(1024, activation='relu')(cnn_2)

    # CNN 3
    # Downsample by 8:1
    cnn_3 = MaxPooling2D(pool_size=(8, 8))(input)
    cnn_3 = Conv2D(128, (3, 3), padding='same', activation='relu')(cnn_3)
    cnn_3 = Conv2D(128, (3, 3), padding='same', activation='relu')(cnn_3)
    cnn_3 = Dropout(0.5)(cnn_3)
    cnn_3 = Flatten()(cnn_3)
    cnn_3 = Dense(512, activation='relu')(cnn_3)

    concat_2_3 = concatenate([cnn_2, cnn_3])
    concat_2_3 = Dense(1024, activation='relu')(concat_2_3)
    l2_reg = ActivityRegularization(l2=L2_REGULARIZATION)(concat_2_3)

    concat_1_l2 = concatenate([cnn_1, l2_reg])
    output = Dense(4096, activation='relu')(concat_1_l2)

    return Model(input, output) 
開發者ID:marco-c,項目名稱:autowebcompat,代碼行數:38,代碼來源:network.py

示例3: create_simnetlike_network

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import ActivityRegularization [as 別名]
def create_simnetlike_network(input_shape, weights):
    L2_REGULARIZATION = 0.005

    input = Input(shape=input_shape)

    # CNN 1
    vgg16 = create_vgglike_network(input_shape, weights)
    cnn_1 = vgg16(input)

    # CNN 2
    # Downsample by 4:1
    cnn_2 = MaxPooling2D(pool_size=(4, 4))(input)
    cnn_2 = Conv2D(32, (3, 3), padding='same', activation='relu')(cnn_2)
    cnn_2 = Conv2D(32, (3, 3), padding='same', activation='relu')(cnn_2)
    cnn_2 = Conv2D(64, (3, 3), padding='same', activation='relu')(cnn_2)
    cnn_2 = Dropout(0.5)(cnn_2)
    cnn_2 = Flatten()(cnn_2)
    cnn_2 = Dense(64, activation='relu')(cnn_2)

    # CNN 3
    # Downsample by 8:1
    cnn_3 = MaxPooling2D(pool_size=(8, 8))(input)
    cnn_3 = Conv2D(16, (3, 3), padding='same', activation='relu')(cnn_3)
    cnn_3 = Conv2D(16, (3, 3), padding='same', activation='relu')(cnn_3)
    cnn_3 = Dropout(0.5)(cnn_3)
    cnn_3 = Flatten()(cnn_3)
    cnn_3 = Dense(32, activation='relu')(cnn_3)

    concat_2_3 = concatenate([cnn_2, cnn_3])
    concat_2_3 = Dense(128, activation='relu')(concat_2_3)
    l2_reg = ActivityRegularization(l2=L2_REGULARIZATION)(concat_2_3)

    concat_1_l2 = concatenate([cnn_1, l2_reg])
    output = Dense(256, activation='relu')(concat_1_l2)

    return Model(input, output) 
開發者ID:marco-c,項目名稱:autowebcompat,代碼行數:38,代碼來源:network.py

示例4: regularization

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import ActivityRegularization [as 別名]
def regularization(layer, layer_in, layerId, tensor=True):
    l1 = layer['params']['l1']
    l2 = layer['params']['l2']
    out = {layerId: ActivityRegularization(l1=l1, l2=l2)}
    if tensor:
        out[layerId] = out[layerId](*layer_in)
    return out 
開發者ID:Cloud-CV,項目名稱:Fabrik,代碼行數:9,代碼來源:layers_export.py

示例5: test_keras_import

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import ActivityRegularization [as 別名]
def test_keras_import(self):
        model = Sequential()
        model.add(ActivityRegularization(l1=2, input_shape=(10,)))
        model.build()
        self.keras_type_test(model, 0, 'Regularization') 
開發者ID:Cloud-CV,項目名稱:Fabrik,代碼行數:7,代碼來源:test_views.py

示例6: test_keras_export

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import ActivityRegularization [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['Input3'], 'l1': net['Regularization']}
        net['l0']['connection']['output'].append('l1')
        inp = data(net['l0'], '', 'l0')['l0']
        net = regularization(net['l1'], [inp], 'l1')
        model = Model(inp, net['l1'])
        self.assertEqual(model.layers[1].__class__.__name__, 'ActivityRegularization') 
開發者ID:Cloud-CV,項目名稱:Fabrik,代碼行數:14,代碼來源:test_views.py


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