コード例 #1
0
        X, Y = generate_dataset(output_dim=nclass, num_examples=time_step)
        all_X.append(X.T)
        all_Y.append(Y)
    all_X, all_Y = np.array(all_X), np.array(all_Y)
    hist = model.fit([all_Y, all_X], all_Y, nb_epoch=200, batch_size=5)

    # calc EER: we cut MFoM head, up to sigmoid output
    input = model.get_layer(name='main_input').output
    out = model.get_layer(name='output').output
    cut_model = Model(input=input, output=out)
    y_pred_sig = cut_model.predict(all_X)
    eer_val = MT.eer(all_Y.flatten(), y_pred_sig.flatten())
    print('sigma_EER: %.4f' % eer_val)

    y_pred = model.predict([all_Y, all_X])
    eer_val = MT.eer(all_Y.flatten(), 1. - y_pred.flatten())
    print('l_EER: %.4f' % eer_val)
    print(model.evaluate([all_Y, all_X], all_Y))

    # TODO notice from the experiments:
    # when we minimize obj.mfom_microf1 with psi = y_pred or psi = -y_pred + 0.5 in
    # UvZMisclassification() layer, the smoothF1 is minimized !!! but EER is not at all.
    # When we minimize obj.mfom_microf1 with psi = -y_pred + y_neg * unit_avg + y_true * zeros_avg,
    # then both smoothF1 and EER are minimized :)

    # history plot, alpha and beta params
    m = model.get_layer('smooth_error_counter')
    print('alpha: ', K.get_value(m.alpha))
    print('beta: ', K.get_value(m.beta))

    # print stats of psi misclassification measure
コード例 #2
0
    # misclassification layer, feed Y
    y_true = Input(shape=(nclass, ), name='y_true')
    psi = mfom.UvZMisclassification(name='uvz_misclass')([y_true, y_pred])

    # class Loss function layer
    out = mfom.SmoothErrorCounter(name='smooth_error_counter')(psi)

    # compile model
    model = Model(input=[y_true, feat_input], output=out)
    model.compile(loss=obj.mfom_eer_normalized, optimizer='Adam')
    model.summary()

    # train
    X, Y = generate_dataset(output_dim=nclass)
    hist = model.fit([Y, X], Y, nb_epoch=100, batch_size=16)

    # calc accuracy: we cut MFoM head, up to sigmoid output
    input = model.get_layer(name='main_input').output
    out = model.get_layer(name='output').output
    cut_model = Model(input=input, output=out)
    y_pred = cut_model.predict(X)
    eer_val = MT.eer(y_true=Y.flatten(), y_pred=y_pred.flatten())
    print('EER: %.4f' % eer_val)

    # history plot, alpha and beta params
    m = model.get_layer('smooth_error_counter')
    print('alpha: ', K.get_value(m.alpha))
    print('beta: ', K.get_value(m.beta))
    plt.plot(hist.history['loss'])
    plt.show()