Python keras.metrics.binary_accuracy() Examples

The following are 3 code examples of keras.metrics.binary_accuracy(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module keras.metrics , or try the search function .
Example #1
Source Project: Learning-aftershock-location-patterns   Author: phoebemrdevries   File: modelfunctions.py    License: MIT License 6 votes vote down vote up
def create_model():
    model = Sequential()
    model.add(Dense(50, input_dim=12, kernel_initializer='lecun_uniform', activation = 'tanh'))
    model.add(Dropout(0.50))
    model.add(Dense(50, kernel_initializer='lecun_uniform', activation= 'tanh'))
    model.add(Dropout(0.50))
    model.add(Dense(50, kernel_initializer='lecun_uniform', activation= 'tanh'))
    model.add(Dropout(0.50))
    model.add(Dense(50, kernel_initializer='lecun_uniform', activation= 'tanh'))
    model.add(Dropout(0.50))
    model.add(Dense(50, kernel_initializer='lecun_uniform', activation= 'tanh'))
    model.add(Dropout(0.50))
    model.add(Dense(50, kernel_initializer='lecun_uniform', activation= 'tanh'))
    model.add(Dropout(0.50))
    model.add(Dense(1, kernel_initializer='lecun_uniform', activation='sigmoid'))
    model.compile(optimizer='adadelta', loss='binary_crossentropy', metrics=[metrics.binary_accuracy])
    return model 
Example #2
Source Project: cs-ranking   Author: kiudee   File: test_tuning.py    License: Apache License 2.0 5 votes vote down vote up
def optimizer():
    from ..tunable import Tunable

    class RankerStub(Tunable):
        def fit(self, X, Y, **kwargs):
            self.seed = int(np.sum(list(self.__dict__.values())))

        def predict(self, X, **kwargs):
            random_state = np.random.RandomState(self.seed)
            weight = random_state.rand(n_features, 2)
            scores = np.dot(X, weight) / np.dot(X, weight).sum(axis=1)[:, None]
            return scores.argmax(axis=1)

        def set_tunable_parameters(self, **point):
            self.__dict__.update(point)

        def __call__(self, X, *args, **kwargs):
            return self.predict(X, **kwargs)

    ranker = RankerStub()

    rankers = [RankerStub() for _ in range(2)]
    test_params = {
        rankers[0]: dict(a=(1.0, 4.0)),
        ranker: dict(b=(4.0, 7.0), c=(7.0, 10.0)),
        rankers[1]: dict(d=(10.0, 13.0)),
    }

    opt = ParameterOptimizer(
        learner=ranker,
        optimizer_path=OPTIMIZER_PATH,
        tunable_parameter_ranges=test_params,
        ranker_params=dict(),
        validation_loss=binary_accuracy,
    )
    return opt, rankers, test_params 
Example #3
Source Project: kaggle_ndsb2017   Author: juliandewit   File: step2_train_nodule_detector.py    License: MIT License 4 votes vote down vote up
def get_net(input_shape=(CUBE_SIZE, CUBE_SIZE, CUBE_SIZE, 1), load_weight_path=None, features=False, mal=False) -> Model:
    inputs = Input(shape=input_shape, name="input_1")
    x = inputs
    x = AveragePooling3D(pool_size=(2, 1, 1), strides=(2, 1, 1), border_mode="same")(x)
    x = Convolution3D(64, 3, 3, 3, activation='relu', border_mode='same', name='conv1', subsample=(1, 1, 1))(x)
    x = MaxPooling3D(pool_size=(1, 2, 2), strides=(1, 2, 2), border_mode='valid', name='pool1')(x)

    # 2nd layer group
    x = Convolution3D(128, 3, 3, 3, activation='relu', border_mode='same', name='conv2', subsample=(1, 1, 1))(x)
    x = MaxPooling3D(pool_size=(2, 2, 2), strides=(2, 2, 2), border_mode='valid', name='pool2')(x)
    if USE_DROPOUT:
        x = Dropout(p=0.3)(x)

    # 3rd layer group
    x = Convolution3D(256, 3, 3, 3, activation='relu', border_mode='same', name='conv3a', subsample=(1, 1, 1))(x)
    x = Convolution3D(256, 3, 3, 3, activation='relu', border_mode='same', name='conv3b', subsample=(1, 1, 1))(x)
    x = MaxPooling3D(pool_size=(2, 2, 2), strides=(2, 2, 2), border_mode='valid', name='pool3')(x)
    if USE_DROPOUT:
        x = Dropout(p=0.4)(x)

    # 4th layer group
    x = Convolution3D(512, 3, 3, 3, activation='relu', border_mode='same', name='conv4a', subsample=(1, 1, 1))(x)
    x = Convolution3D(512, 3, 3, 3, activation='relu', border_mode='same', name='conv4b', subsample=(1, 1, 1),)(x)
    x = MaxPooling3D(pool_size=(2, 2, 2), strides=(2, 2, 2), border_mode='valid', name='pool4')(x)
    if USE_DROPOUT:
        x = Dropout(p=0.5)(x)

    last64 = Convolution3D(64, 2, 2, 2, activation="relu", name="last_64")(x)
    out_class = Convolution3D(1, 1, 1, 1, activation="sigmoid", name="out_class_last")(last64)
    out_class = Flatten(name="out_class")(out_class)

    out_malignancy = Convolution3D(1, 1, 1, 1, activation=None, name="out_malignancy_last")(last64)
    out_malignancy = Flatten(name="out_malignancy")(out_malignancy)

    model = Model(input=inputs, output=[out_class, out_malignancy])
    if load_weight_path is not None:
        model.load_weights(load_weight_path, by_name=False)
    model.compile(optimizer=SGD(lr=LEARN_RATE, momentum=0.9, nesterov=True), loss={"out_class": "binary_crossentropy", "out_malignancy": mean_absolute_error}, metrics={"out_class": [binary_accuracy, binary_crossentropy], "out_malignancy": mean_absolute_error})

    if features:
        model = Model(input=inputs, output=[last64])
    model.summary(line_length=140)

    return model