示例#1
0
    network = dropout(network, 0.8)

    softmax = fully_connected(network, nClass, activation='softmax')

    sgd = tflearn.SGD(learning_rate=0.1, lr_decay=0.96, decay_step=1000)
    top_k = tflearn.metrics.Top_k(3)
    network = tflearn.regression(softmax, optimizer=sgd, metric=top_k,
                                 loss='categorical_crossentropy', name='target')

    # Training
    model = tflearn.DNN(network, tensorboard_verbose=0)
    model.fit({'input': X}, {'target': Y}, validation_set=0.1, n_epoch=n_epoch1,
              snapshot_step=100, run_id='convnet_buflo'+str(iter))
    # Save model
    model.save(os.path.join(model_path, 'Conv_buflo_'+str(iter)+'.tflearn'))
    prob_vector = model.predict(testX)

    k_list = []
    # confidence thresholds
    confs = [0.1,0.3,0.5,0.7, 0.9]
    # top k accuracy
    k_list = [1, 2, 3]

    for topK in k_list:
        for conf in confs:
            file = os.path.join(HOME, 'results',
                                'Conv_Buflo' + '_top_' + str(topK) + '_' + gb + str(
                                    dim) + '_' + str(nClass) + '_' + str(dim) + '_conf_' + str(conf) + '.txt')

            nn_metrics.getMetricsTopK(exp, prob_vector, testY, nClass, file, topK, conf, iter, 0, mon_instance * nClass)
示例#2
0
文件: pfp_m.py 项目: seeunoh2/pFP
    model = tflearn.DNN(net, tensorboard_verbose=0)
    model.fit(X, Y, batch_size=47, n_epoch=n_epoch1, validation_set=0.1)
    # Save model
    model.save(os.path.join(model_path, 'PFP_M_' + str(iter) + '.tflearn'))

    prob_vector = model.predict(testX)
    # print(prob_vector)
    k_list = []
    confs = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
    if b_label:  ## Binary classification
        k_list = [1]
    else:
        k_list = [1, 2, 3, 4, 5]
    for topK in k_list:
        if not b_label:
            file = os.path.join(
                HOME, 'results', 'PFP_M_' + str(topK) + '_' + exp + '_' + gb +
                str(dim) + '_' + str(mon_instance * (nClass - 1)) + '_' +
                str(unClass) + '_' + str(n_epoch1) + '.txt')
            for conf in confs:
                nn_metrics.getMetricsTopK(exp, prob_vector, testY, nClass,
                                          file, topK, conf, iter, 0, 0)
        else:
            file = os.path.join(
                HOME, 'results', 'PFP_M_' + exp + '_' + gb + str(dim) + '_' +
                str(mon_instance * (nClass - 1)) + '_' + str(unClass) + '_' +
                str(n_epoch1) + '.txt')
    for conf in confs:
        nn_metrics.getMetricsTopK(exp, prob_vector, testY, nClass, file, topK,
                                  conf, iter, 0, 0)