Example #1
0
folder_output = "/home/prassanna/Development/workspace/CamVid_scripts/FrameworkDump3/crf/"
fh, filenames_ext = listFiles(folder_energy, ext_energy)
filenames = [f.replace(ext_energy, "") for f in filenames_ext]

for i in range(0, len(filenames)):
    print i, "->", filenames[i]
    print "Loading all files..."
    energies = ocv.read_xml_file(folder_energy + filenames[i] + ext_energy,
                                 "prob")
    segments = ocv.read_xml_file(
        folder_superpixels + filenames[i] + ext_superpixels, "Segments")
    nbrs = ocv.read_xml_file(folder_superpixels + filenames[i] + ext_nbr,
                             "Neighbours")
    ann = ocv.read_xml_file(folder_superpixels + filenames[i] + ext_ann, "Ann")
    gt_labels = annImagetoLabels(ann, segments)

    print "Necessary Transformations..."
    edge_list, edge_features = SuperpixelAdjacency.convertToAdjacencyListPotts(
        nbrs, segments, gt_labels)
    #edge_features.shape=len(edge_features),1
    x = (energies, edge_list, edge_features)

    print "Inference...."
    predlabelList = crf.inference(x, ssvm.w, relaxed=True)

    print "Final Operations..."
    predAnn = predLabelsToAnnIndex(segments, predlabelList)
    predImage = labelsToImage(label_list, predAnn, True)
    ocv.write_xml_file(folder_output + filenames[i] + ext_out_ann, "Ann",
                       predAnn)
    cv2.imwrite(folder_output + filenames[i] + ext_out_image, predImage)
Example #2
0
#gt_global = list();
#desc_global = list();
#cv2.namedWindow("Original");
#cv2.namedWindow("Predicted");

for i in range(0, len(filenames_sup)):
    print i, "->", filenames_sup[i]
    segments = ocv.read_xml_file(folder_location + filenames_sup[i],
                                 "Segments")
    desc = ocv.read_xml_file(folder_location + filenames_desc[i],
                             "Descriptors")
    #ann = ocv.read_xml_file(folder_location+filenames_ann[i], "Ann")
    print "Transforming.."
    desc = imp.transform(desc)
    print "Predicting.."
    for k in range(0, len(clfs)):
        clf = clfs[k]
        folder_out = folder_outs[k]
        pred_labels = clf.predict(desc)
        predAnn = predLabelsToAnnIndex(segments, pred_labels)
        #annImage = labelsToImage(dataset_colours, ann);
        predImage = labelsToImage(dataset_colours, predAnn)
        #cv2.imshow("Original", annImage);
        #cv2.imshow("Predicted", predImage);
        ocv.write_xml_file(folder_out + filenames_out[i] + ".xml", "Ann",
                           predAnn)
        cv2.imwrite(folder_out + filenames_out[i], predImage)
    #cv2.waitKey(0)

#cv2.destroyAllWindows();
Example #3
0

folder_location = "/home/prassanna/Development/workspace/CamVid_scripts/FrameworkDump4/Train/"

#Getting filenames for Random Forests
filenames, filenames_desc = listFiles(folder_location, ext_desc)
filenames_sup = [
    filename.replace(ext_desc, ext_sup) for filename in filenames_desc
]
filenames_ann = [
    filename.replace(ext_desc, ext_ann) for filename in filenames_desc
]
filename_extless = [
    filename.replace(ext_desc, "") for filename in filenames_desc
]
gt_global = list()
desc_global = list()

for i in range(0, 1):  #len(filenames_sup)):
    print i, "->", filenames_sup[i]
    for j in range(0, len(clfs)):
        print "On classifier : ", j

        desc = ocv.read_xml_file(folder_location + filenames_desc[i],
                                 "Descriptors")
        desc = imp.transform(desc)
        pred = clfs[j].predict_log_proba(desc)
        #predEnergy = clf.predict_log_proba(desc);
        ocv.write_xml_file(folder_out[j] + filename_extless[i] + "_prob.xml",
                           "prob", pred)
    #ocv.write_xml_file(folder_out+filenames_extless[i]+"_energy.xml", "energy", predEnergy)