Exemplo n.º 1
0
while (True):
    x_test, y_test, test_num = read_labels_batch_out(
        labels_path, (224, 224), (224, 224),
        root_images_folder,
        batch_size=batch_size,
        iteration_num=i,
        random_horizontal_flip=False)
    if (test_num == 0):
        break

    predicts = model.predict(x_test, batch_size=batch_size)

    for j, value in enumerate(predicts):
        predict = np.argmax(value)
        truth_val = y_test[j]
        confusion_mat.AddValueToConfusionMat(val=predict, label_val=truth_val)
        file_writer.Write("[[" + str(j + (batch_size * i)) + "]] " +
                          str(truth_val) + " {" + str(predict) + "}")

    print(
        "====================================================================")
    file_writer.Write(
        "====================================================================")

    print("result of iteration number : " + str(i))
    file_writer.Write("result of iteration number : " + str(i))
    print(" ")
    file_writer.Write(" ")

    print("---Show Current Score---\n")
    file_writer.Write("---Show Current Score---\n")
        else:
            net.blobs['data'].reshape(batch_size, image_color_channel,
                                      image_size_h, image_size_w)

        net.blobs['data'].data[j_0, :, :, :] = transformer.preprocess(
            'data', caffe_img)

    #Run Model
    out = net.forward()

    for j_1, raw_predict_val in enumerate(out['score']):
        predict_val = raw_predict_val.argmax()

        #Storage Value
        prop_dict = sub_list[j_1]
        confusion_mat.AddValueToConfusionMat(
            val=predict_val, label_val=prop_dict['truth_label'])
        file_writer.Write("[[" + str(prop_dict['real_line_pos']) + "]] " +
                          " [" + str(prop_dict['iteration_id']) + "]" + " [" +
                          str(prop_dict['batch_id']) + "] " +
                          prop_dict['img_path'] + " " +
                          str(prop_dict['truth_label']) + " {" +
                          str(predict_val) + "}")

    #Show confusion matrix every X iteration
    if (i < iteration_count):
        print(
            "===================================================================="
        )
        file_writer.Write(
            "===================================================================="
        )