本文整理汇总了Python中keras.metrics.binary_accuracy方法的典型用法代码示例。如果您正苦于以下问题:Python metrics.binary_accuracy方法的具体用法?Python metrics.binary_accuracy怎么用?Python metrics.binary_accuracy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras.metrics
的用法示例。
在下文中一共展示了metrics.binary_accuracy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_model
# 需要导入模块: from keras import metrics [as 别名]
# 或者: from keras.metrics import binary_accuracy [as 别名]
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
示例2: optimizer
# 需要导入模块: from keras import metrics [as 别名]
# 或者: from keras.metrics import binary_accuracy [as 别名]
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
示例3: get_net
# 需要导入模块: from keras import metrics [as 别名]
# 或者: from keras.metrics import binary_accuracy [as 别名]
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