Python keras.regularizers.activity_l1() Examples

The following are code examples for showing how to use keras.regularizers.activity_l1(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: CAPTCHA-breaking   Author: lllcho   File: test_regularizers.py    MIT License 5 votes vote down vote up
def test_A_reg(self):
        for reg in [regularizers.activity_l1(), regularizers.activity_l2()]:
            model = create_model(activity_reg=reg)
            model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
            model.fit(X_train, Y_train, batch_size=batch_size, nb_epoch=nb_epoch, verbose=0)
            model.evaluate(X_test[test_ids, :], Y_test[test_ids, :], verbose=0) 
Example 2
Project: workspace_2017   Author: nwiizo   File: test_regularizers.py    MIT License 5 votes vote down vote up
def test_A_reg():
    (X_train, Y_train), (X_test, Y_test), test_ids = get_data()
    for reg in [regularizers.activity_l1(), regularizers.activity_l2()]:
        model = create_model(activity_reg=reg)
        model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
        assert len(model.losses) == 1
        model.fit(X_train, Y_train, batch_size=batch_size,
                  nb_epoch=nb_epoch, verbose=0)
        model.evaluate(X_test[test_ids, :], Y_test[test_ids, :], verbose=0)