Пример #1
0
def main(trainset, window, nfeatures, image, savetodir):
    output = savetodir+"temp.xpl"
    #building the xpl file
    ensemble.build_xpl(trainset,window,output)
    #reading the "just" created xpl file
    result = xplutil.read_xpl(output)
    XPL_data = result.data
    w0 = result.freq0.copy()
    w1 = result.freq1.copy()
    #normalizing the table frequency values
    w0,w1 = cl.normalize_table(w0, w1)
    #calculating features and indexes
    indices, feature_list, _ = ft.cmim(XPL_data, w0, w1, nfeatures)
    #saving window file
    tw.to_window_file(indices, result.winshape, savetodir+"window.win")
    #applying the feature selection algorithm
    w0, w1, updated_decision, cls_error =  cl.apply_feature_selection(XPL_data, indices, w0, w1)
    #calculating the unique array and their indexes
    indices = np.sort(indices)
    unique_array, unique_index = cl._apply_projection(XPL_data, indices)
    #writing a mimterm file to disk
    xplutil.write_minterm_file(savetodir+"mintermfile.mtm",indices, result.winshape, unique_array,updated_decision[unique_index])
    #building the operator based on the mintermfile
    ensemble.build_operator(savetodir+"window.win", savetodir+"mintermfile.mtm", savetodir+"operator")
    #building a new XPL according to the learned window
    output = savetodir+"Learned.xpl"
    ensemble.build_xpl(trainset,savetodir+"window.win",output)
    result_img = savetodir+"Image_applied"
    #applying the operator on the image
    ensemble.apply_operator(savetodir+"operator", image, result_img)
Пример #2
0
def main(level1trainset,level2trainset, testset, window, nfeatures, niterations, savetodir):
    output = savetodir+"temp.xpl"
    #building a XPL to start processing
    ensemble.build_xpl(level1trainset,window,output)
    XPL_filepath = output
    #now let's read the XPL
    XPL_data = xplutil.read_xpl(XPL_filepath)
    #writing the minimal empirical error to file
    ensemble.write_min_empirical_error(savetodir+"min_emp_err.txt",ensemble.min_empirical_error(XPL_data))
    #training the ensemble
    ensemble.train(XPL_data, nfeatures, niterations, savetodir)
    #building first level operators
    print
    print "... Building first level operators ...\n"
    ensemble.build_operators(savetodir , niterations)

    #creating the operators combinations
    for i in range(1,niterations):
        print
        print "...Building operators combination : 0 to %s ... \n" %str(i)
        ensemble.build_operator_combination(level2trainset, np.array(range(i+1)), savetodir, savetodir+"twoLevel_0_to_"+str(i))

    #combining all the operators
    #ensemble.build_operator_combination(trainset, np.array(range(niterations)), savetodir, savetodir+"twoLevel")

    #Writing MAE from training set  to file.
    set = imageset.Imageset()
    trainimgset = set.read(level1trainset)
    mae_t = ensemble.mae(trainimgset)
    file = open(savetodir+"MAE_TrainingSet.txt", "w")
    file.write(str(mae_t))
    file.close()

    #Writing MAE  from test set to file.
    set = imageset.Imageset()
    testimgset = set.read(testset)
    mae_test = ensemble.mae(testimgset)
    file = open(savetodir+"MAE_TestSet.txt", "w")
    file.write(str(mae_test))
    file.close()

    img_list = _get_imgList(testimgset)

    #applying the first level operators on the test set images
    for i in range(niterations):
        for j in img_list:
            ensemble.apply_operator(savetodir+"mtm"+str(i)+"-op", j, savetodir+"mtm"+str(i)+"-op-files/"+j.split("/")[-1][:-3]+"proc.pnm")
        ensemble.trios_test(savetodir+"mtm"+str(i)+"-op", testset, savetodir+"mtm"+str(i)+"-op-files/MAE.txt")

    #applying the second level operators combinations on the test set images
    for i in range(1,niterations):
        for j in img_list:
            ensemble.apply_operator(savetodir+"twoLevel_0_to_"+str(i),j, savetodir+"twoLevel_0_to_"+str(i)+"-files/level1/operator0/"+j.split("/")[-1][:-3]+"proc.pnm")
        ensemble.trios_test(savetodir+"twoLevel_0_to_"+str(i), testset, savetodir+"twoLevel_0_to_"+str(i)+"-files/level1/operator0/MAE.txt")
Пример #3
0
def main(numwindows, npixels, winshape, level1trainset, level2trainset, testset, savetodir):
    winshape = winshape.split("x")
    height = int(winshape[0])
    width = int(winshape[1])
    make_windows(savetodir, (height, width), npixels, numwindows)

    # this is where i run the single level operators training
    for i in range(numwindows):
        print
        print "...Building operator %s ...\n" % str(i)
        build_operator(savetodir + "window_" + str(i) + ".win", level1trainset, savetodir + "window_" + str(i) + "_op")

    # this is where i combine the single level operators to create a second level one
    for i in range(1, numwindows):
        print
        print "...Building operators combination : 0 to %s ... \n" % str(i)
        build_operators_combination(
            level2trainset, np.array(range(i + 1)), savetodir, savetodir + "twoLevel_0_to_" + str(i)
        )

    triostestset = imageset.Imageset()
    testimgset = triostestset.read(testset)
    img_list = _get_imgList(testimgset)

    # applying the first level operators on the test set images
    for i in range(numwindows):
        for j in img_list:
            print
            print "...Applying operator %s on image : %s ...\n" % (str(i), j)
            ensemble.apply_operator(
                savetodir + "window_" + str(i) + "_op",
                j,
                savetodir + "window_" + str(i) + "_op-files/" + j.split("/")[-1][:-3] + "proc.pnm",
            )
        ensemble.trios_test(
            savetodir + "window_" + str(i) + "_op", testset, savetodir + "window_" + str(i) + "_op-files/MAE.txt"
        )

    # applying the second level operators combinations on the test set images
    for i in range(1, int(numwindows)):
        for j in img_list:
            ensemble.apply_operator(
                savetodir + "twoLevel_0_to_" + str(i),
                j,
                savetodir + "twoLevel_0_to_" + str(i) + "-files/level1/operator0/" + j.split("/")[-1][:-3] + "proc.pnm",
            )
        # running trios_test tool to calculate MAE for current operator combination
        ensemble.trios_test(
            savetodir + "twoLevel_0_to_" + str(i),
            testset,
            savetodir + "twoLevel_0_to_" + str(i) + "-files/level1/operator0/MAE.txt",
        )

    return 0
Пример #4
0
def main(trainset, window, image, savetodir):
    output = savetodir+"temp.xpl"
    fname = savetodir+"operator"
    #building the xpl file
    ensemble.build_xpl(trainset,window,output)
    #writing minterm file to disk
    ensemble.trios_build_mtm(window, trainset, savetodir+"mintermfile.mtm")
    #building an operator with trios_build tool
    ensemble.trios_build(window, trainset, fname)
    result_img = savetodir+"Image_applied"
    #applying the operator on the image
    ensemble.apply_operator(savetodir+"operator", image, result_img)