Beispiel #1
0
    dest_onlyveg = os.path.join(outpaths['only_veg'],img_name+'.png')

    dest_ndvi = os.path.join(outpaths['ndvi'],img_name+'.png')
    dest_overlay = os.path.join(outpaths['overlay'],img_name+'.png')

    try:
        if not os.path.isfile(dest_pred):
            vd.single_img_forward_pass(epoch_path,img_path)

            # vd.single_img_forward_pass(epoch_path,img_path,dataset='cityscapes',model='DeepLabV3_plus')

            copyfile(out_orig,dest_orig)
            copyfile(out_pred,dest_pred)
        
        if gen_extras:
            cs.gen_only_veg_img(dest_pred,dest_orig,dest_onlyveg)
            cs.gen_uint8_NDVI(dest_onlyveg,dest_ndvi)

            cs.gen_overlay_img(dest_orig,dest_pred,dest_overlay)


    except:
        msc.telegram_bot_sendtext("failed on "+img_name)
        # msc.telegram_bot_sendtext(e)

    msc.print_rem_time_info(len(img_list),i,t1)


msc.telegram_bot_sendtext("img_gen done!!")

# cityscapes dict: /home/kaue/Semantic-Segmentation-Suite/cityscapes/class_dict.csv
Beispiel #2
0
classifiedList = misc.orderedFileList(classifiedPath,'*.png')

for path in classifiedList:
    # print(path)
    filename = misc.filenameFromPath(path)
    originalImgPath = os.path.join(originalsPath,misc.modFilenameExt(filename,'.jpg'))
    outPath  = os.path.join(toClassifyFolder,filename)

    print(originalImgPath)

    classifiedImg = cv2.imread(path)
    originalImg   = cv2.imread(originalImgPath)

    for i,column in enumerate(classifiedImg):
        for j,pixel in enumerate(column):
            # as there are only black or white pixels, we can test only a channel
            # print(originalImg[i,j,0])
            if pixel[0] == 255:
                try:
                    pixel.itemset(0,originalImg[i,j,0])
                    pixel.itemset(1,originalImg[i,j,1])
                    pixel.itemset(2,originalImg[i,j,2])
                except:
                    print(classifiedImg.shape)

    cv2.imwrite(outPath,classifiedImg)


misc.telegram_bot_sendtext("processing ended")
pathlist = msc.getSubdirs(basedir)

# sizes = np.empty(len(pathlist), dtype=int)

# print(sizes)

# for i,path in enumerate(pathlist):
#     sizes[i] = path.count('/')

# print(sizes)

# max_lvl = np.max(sizes)

# print(max_lvl)

for path in pathlist:
    if msc.checkForImages(path,'*.png'):
        parent = msc.get_parent_dir(path)S
        imgList = msc.orderedFileList(path,'*.png')
        for imgPath in imgList:
            if strToContain in imgPath:
                filename = msc.filenameFromPath(imgPath)
                newfilename = filename.replace(strToReplace,strToAdd)
                print(newfilename)
                move(imgPath,os.path.join(parent,newfilename))
        # os.removedirs(path)


msc.telegram_bot_sendtext("copying terminated")
Beispiel #4
0
from processing_functions import color_stuff as cs
from processing_functions import general_funcs as gf
import glob
import cv2

basedir = "/home/kauevestena/Dropbox/data/backup/temp/"
baseOutDir = "/home/kauevestena/Dropbox/data/gt/originals_complete_red/"

dirList = msc.getSubdirs(basedir)

subpaths = msc.subpathList(dirList,basedir)

msc.createDirStructure(baseOutDir,subpaths)


for folder in dirList:
    if msc.checkForImages(folder,'*.png'):
        print(folder)
        subpath = msc.removeBasedir(folder,basedir)
        outFolderPath = os.path.join(baseOutDir,subpath)
    
        for filepath in glob.glob(folder+"/*.png"):
            fileName = msc.filenameFromPath(filepath)
            outPath = os.path.join(outFolderPath,fileName)

            cs.save_one_band(filepath,outPath)


msc.telegram_bot_sendtext("band extraction terminated")

    # # # #     # plotting stuff
    # # # #     plt.close('all')
    # # # #     plt.figure()

    # # # #     picklepath = os.path.join(vd.PICKLES_PATH,key+"_"+db_name+'.pickle')

    # # # #     errorMetricsDfs[key].to_pickle(picklepath,compression=None)

    # # # #     errorMetricsDfs[key].plot.line()

    # # # #     plt.savefig(os.path.join(outpath,key+'.png'))

    # # # #     plt.close('all')
    # # # #     plt.figure()

    # # # #     errorMetricsDfs[key].T.plot.line()

    # # # #     plt.savefig(os.path.join(outpath,'T_'+key+'.png'))

print("tooked  {} s".format(time.time() - beg))

for key in revCkptDict:
    print("{} is {}".format(key, revCkptDict[key]))

revCkptDict_path = os.path.join(vd.PICKLES_PATH, 'ckpt_rev_dict.pickle')

with open(revCkptDict_path, 'wb') as pickling_dict:
    pickle.dump(revCkptDict, pickling_dict)

msc.telegram_bot_sendtext("pickled and ended!!!")
Beispiel #6
0
#script to classify vegetation and no vegatation in a manualy classified in white for vegetation and anything to non-vegetation
from processing_functions import misc as msc
from processing_functions import color_stuff as cs
import datetime
import os
# import cv2

# inputpath = "/home/kaue/data/extracted_images/samples/2019-07-11-16-21-46/regular"
inputpath = "/home/kaue/data/extracted_images/samples/2019-07-11-16-21-46/reclassification"

# outpath = "/home/kaue/data/extracted_images/samples/2019-07-11-16-21-46/already_classified"
outpath = "/home/kaue/data/extracted_images/samples/2019-07-11-16-21-46/reclassification_blackwhite"

imagelist = msc.orderedFileList(inputpath, extension='*.png')

minDate = datetime.datetime(year=2019, day=17, month=7)

for imgpath in imagelist:
    filedate = msc.getModTime(imgpath)
    if filedate > minDate:
        savepath = os.path.join(outpath, msc.filenameFromPath(imgpath))
        # cs.remove_other_classes(imgpath,savepath,255,255,255)
        cs.remove_other_classes(imgpath, savepath, 0, 0, 0, 255, 255, 255)
        print(imgpath)

msc.telegram_bot_sendtext("GT classification ended")
Beispiel #7
0
        ckptList.append(vd.checkpoint(validckptpath, "python3.7"))
    else:
        print(validckptpath)
        ckptList.append(vd.checkpoint(validckptpath))

# for ckpt in ckptList:
#     print(ckpt.model,ckpt.dataset)

# print(listOfListsOnDirs[0][0])

# ckptList[0].process_image(gtImagesList[0])
# ckptList[0].process_and_validate(imgs_and_gts[0])
# ckptList[0].process_and_validate(imgs_and_gts[1])

# print(ckptList[0].error_metrics_store)

# ckptList[0].dump_to_tinyDB()

print(len(ckptList), len(imgs_and_gts))

total_its = len(ckptList) * len(imgs_and_gts)

for i, ckpt in enumerate(ckptList):
    for j, img in enumerate(imgs_and_gts):
        beg = time.time()
        ckpt.process_and_validate(img, True, False)
        msc.print_rem_time_info(total_its, i * len(imgs_and_gts) + j, beg)
    ckpt.dump_to_tinyDB()

msc.telegram_bot_sendtext("evaluation done")