Exemplo n.º 1
0
def process_folder(f):
    global args

    dst = f.replace("_polygons.json", f"_label{args.id_type}s.png")

    # do the conversion
    try:
        json2labelImg(f, dst, args.id_type)
    except:
        tqdm.write("Failed to convert: {}".format(f))
        raise

    if args.instance:
        dst = f.replace("_polygons.json", f"_instance{args.id_type}s.png")

        # do the conversion
        # try:
        json2instanceImg(f, dst, args.id_type)
        # except:
        #     tqdm.write("Failed to convert: {}".format(f))
        #     raise

    if args.color:
        # create the output filename
        dst = f.replace("_polygons.json", f"_labelColors.png")

        # do the conversion
        try:
            json2labelImg(f, dst, 'color')
        except:
            tqdm.write("Failed to convert: {}".format(f))
            raise
Exemplo n.º 2
0
def main():
    # Where to look for Cityscapes
    if 'CITYSCAPES_DATASET_INDIA' in os.environ:
        cityscapesPath = os.environ['CITYSCAPES_DATASET_INDIA']
    else:
        cityscapesPath = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), '..', '..')
    # how to search for all ground truth
    searchFine = os.path.join(cityscapesPath, "gtFine", "*", "*",
                              "*_gt*_polygons.json")
    searchCoarse = os.path.join(cityscapesPath, "gtCoarse", "*", "*",
                                "*_gt*_polygons.json")

    # search files
    filesFine = glob.glob(searchFine)
    filesFine.sort()
    filesCoarse = glob.glob(searchCoarse)
    filesCoarse.sort()

    # concatenate fine and coarse
    #files = filesFine + filesCoarse
    files = filesFine  # use this line if fine is enough for now.

    # quit if we did not find anything
    if not files:
        printError("Did not find any files. Please consult the README.")

    # a bit verbose
    print("Processing {} annotation files".format(len(files)))

    # iterate through files
    progress = 0
    print("Progress: {:>3} %".format(progress * 100 / len(files)), end=' ')
    for f in files:
        # create the output filename
        dst = f.replace("_polygons.json", "_labelTrainIds.png")

        # do the conversion
        # encoding can be set to
        #     - "ids"      : classes are encoded using the regular label IDs
        #     - "trainIds" : classes are encoded using the training IDs
        #     - "color"    : classes are encoded using the corresponding colors
        try:
            json2labelImg(f, dst, "trainIds")
        except:
            print("Failed to convert: {}".format(f))
            raise

        # status
        progress += 1
        print("\rProgress: {:>3} %".format(progress * 100 / len(files)),
              end=' ')
        sys.stdout.flush()
def main():
    # Where to look for Cityscapes
    if 'CITYSCAPES_DATASET' in os.environ:
        cityscapesPath = os.environ['CITYSCAPES_DATASET']
    else:
        cityscapesPath = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), '..', '..')
    # how to search for all ground truth
    #searchFine   = os.path.join( cityscapesPath , "gtFine"   , "*" , "*" , "*_gt*_polygons.json" )
    searchFine = os.path.join('/home/bctsai/gtFine/val', "*",
                              "*_gt*_polygons.json")  ###CVPR_eval
    searchCoarse = os.path.join(cityscapesPath, "gtCoarse", "*", "*",
                                "*_gt*_polygons.json")

    # search files
    #pdb.set_trace()
    filesFine = glob.glob(searchFine)
    filesFine.sort()
    filesCoarse = glob.glob(searchCoarse)
    filesCoarse.sort()

    # concatenate fine and coarse
    files = filesFine + filesCoarse
    # files = filesFine # use this line if fine is enough for now.

    # quit if we did not find anything
    if not files:
        printError("Did not find any files. Please consult the README.")

    # a bit verbose
    print("Processing {} annotation files".format(len(files)))

    # iterate through files
    progress = 0
    print("Progress: {:>3} %".format(progress * 100 / len(files)), end=' ')
    for f in files:
        # create the output filename
        dst = f.replace("_polygons.json", "_CVPR_eval.png")

        # do the conversion
        try:
            json2labelImg(f, dst, "trainIds")
        except:
            print("Failed to convert: {}".format(f))
            raise

        # status
        progress += 1
        print("\rProgress: {:>3} %".format(progress * 100 / len(files)),
              end=' ')
        sys.stdout.flush()
Exemplo n.º 4
0
def process_folder(f):
    global args

    dst = f.replace("_polygons.json", f"_label{args.id_type}s.png")

    # do the conversion
    try:
        json2labelImg(f, dst, args.id_type)
    except:
        tqdm.write("Failed to convert: {}".format(f))
        raise

    if args.instance:
        dst = f.replace("_polygons.json", f"_instance{args.id_type}s.png")

        # do the conversion
        # try:
        json2instanceImg(f, dst, args.id_type)
        # except:
        #     tqdm.write("Failed to convert: {}".format(f))
        #     raise

    if args.color:
        # create the output filename
        dst = f.replace("_polygons.json", f"_labelColors.png")

        # do the conversion
        try:
            json2labelImg(f, dst, 'color')
        except:
            tqdm.write("Failed to convert: {}".format(f))
            raise

    if args.panoptic and args.instance:
        dst = f.replace("_polygons.json", f"_panoptic{args.id_type}s.png")
        seg_anno = f.replace("_polygons.json", f"_label{args.id_type}s.png")
        inst_anno = f.replace("_polygons.json",
                              f"_instance{args.id_type}s.png")

        seg_tail = f"_gtFine_label{args.id_type}s.png"
        inst_tail = f"_gtFine_instance{args.id_type}s.png"
        pan_tail = f"_gtFine_panoptic{args.id_type}s.png"

        seg_img = imread(seg_anno)
        inst_img = imread(inst_anno)
        sh = (seg_img.shape[0], seg_img.shape[1], 2)
        twoch_img = np.zeros(sh, dtype=np.uint16)
        twoch_img[:, :, 0] = seg_img
        twoch_img[:, :, 1] = inst_img
        write_png(seg_anno.replace(seg_tail, pan_tail), twoch_img)
def main():
    # Where to look for Cityscapes
    # Where to look for Cityscapes
    # if 'CITYSCAPES_DATASET' in os.environ:
    #     cityscapesPath = os.environ['CITYSCAPES_DATASET']
    # else:
    #     cityscapesPath = os.path.join(os.path.dirname(os.path.realpath(__file__)),'..','..')
    cityscapesPath = os.path.expanduser('~/exp/datasets/cityscapes/gtFine_trainvaltest')
    # how to search for all ground truth
    searchFine   = os.path.join( cityscapesPath , "gtFine"   , "*" , "*" , "*_gt*_polygons.json" )
    searchCoarse = os.path.join( cityscapesPath , "gtCoarse" , "*" , "*" , "*_gt*_polygons.json" )

    # search files
    filesFine = glob.glob( searchFine )
    filesFine.sort()
    filesCoarse = glob.glob( searchCoarse )
    filesCoarse.sort()

    # concatenate fine and coarse
    files = filesFine + filesCoarse
    # files = filesFine # use this line if fine is enough for now.

    # quit if we did not find anything
    if not files:
        printError( "Did not find any files. Please consult the README." )

    # a bit verbose
    print "Processing {} annotation files".format(len(files))

    # iterate through files
    progress = 0
    print "Progress: {:>3} %".format( progress * 100 / len(files) ) ,
    for f in files:
        # create the output filename
        dst = f.replace( "_polygons.json" , "_labelTrainIds.png" )

        # do the conversion
        try:
            json2labelImg( f , dst , "trainIds" )
        except:
            print "Failed to convert: {}".format(f)
            raise

        # status
        progress += 1
        print "\rProgress: {:>3} %".format( progress * 100 / len(files) ) ,
        sys.stdout.flush()
Exemplo n.º 6
0
def main():
    # Where to look for Cityscapes
    if 'CITYSCAPES_DATASET' in os.environ:
        cityscapesPath = os.environ['CITYSCAPES_DATASET']
    else:
        cityscapesPath = 'data/cityscapes'
    # how to search for all ground truth
    searchFine = os.path.join(cityscapesPath, "gtFine", "*", "*",
                              "*_gt*_polygons.json")
    searchCoarse = os.path.join(cityscapesPath, "gtCoarse", "*", "*",
                                "*_gt*_polygons.json")

    # search files
    filesFine = glob.glob(searchFine)
    filesFine.sort()
    filesCoarse = glob.glob(searchCoarse)
    filesCoarse.sort()

    # concatenate fine and coarse
    files = filesFine + filesCoarse

    # quit if we did not find anything
    if not files:
        print("Did not find any files. Please consult the README.")

    # a bit verbose
    print("Processing {} annotation files".format(len(files)))

    # iterate through files
    progress = 0
    print("Progress: {:>3} %".format(progress * 100 / len(files)))
    for f in files:
        # create the output filename
        dst = f.replace("_polygons.json", "_labelTrainIds.png")

        # do the conversion
        try:
            json2labelImg(f, dst, "trainIds")
        except:
            print("Failed to convert: {}".format(f))
            raise

        # status
        progress += 1
        print("Progress: {:>3} %".format(progress * 100 / len(files)))
        sys.stdout.flush()
Exemplo n.º 7
0
def main():
    cityscapesPath = "/Users/ht/Documents/dataset/cityscapes/gtFine_trainvaltest"
    # how to search for all ground truth
    searchFine = os.path.join(cityscapesPath, "gtFine", "*", "*",
                              "*_gt*_polygons.json")
    searchCoarse = os.path.join(cityscapesPath, "gtCoarse", "*", "*",
                                "*_gt*_polygons.json")

    # search files
    filesFine = glob.glob(searchFine)
    filesFine.sort()
    filesCoarse = glob.glob(searchCoarse)
    filesCoarse.sort()

    # concatenate fine and coarse
    #files = filesFine + filesCoarse
    files = filesFine  # use this line if fine is enough for now.

    # quit if we did not find anything
    if not files:
        printError("Did not find any files. Please consult the README.")

    # a bit verbose
    print("Processing {} annotation files".format(len(files)))

    # iterate through files
    progress = 0
    print("Progress: {:>3} %".format(progress * 100 / len(files)), end=' ')
    for f in files:
        # create the output filename
        dst = f.replace("_polygons.json", "_labelTrainIds.png")

        # do the conversion
        try:
            json2labelImg(f, dst, "trainIds")
        except:
            print("Failed to convert: {}".format(f))
            raise

        # status
        progress += 1
        print("\rProgress: {:>3} %".format(progress * 100 / len(files)),
              end=' ')
        sys.stdout.flush()
Exemplo n.º 8
0
def process_folder(fn):
    global args

    dst = fn.replace("_polygons.json", "_label{}s.png".format(args.id_type))

    # do the conversion
    try:
        json2labelImg(fn, dst, args.id_type)
    except:
        tqdm.write("Failed to convert: {}".format(fn))
        raise

    if args.color:
        # create the output filename
        dst = fn.replace("_polygons.json", "_labelColors.png")

        # do the conversion
        try:
            json2labelImg(fn, dst, 'color')
        except:
            tqdm.write("Failed to convert: {}".format(f))
            raise
def main():
    # how to search for all ground truth
    searchFine   = os.path.join( '/media/psf/Home/code/dataset/03.labelled/' , "*.json" )

    # search files
    filesFine = glob.glob( searchFine )
    filesFine.sort()

    # concatenate fine and coarse
    files = filesFine

    # quit if we did not find anything
    if not files:
        printError( "Did not find any files. Please consult the README." )

    # a bit verbose
    print("Processing {} annotation files".format(len(files)))

    # iterate through files
    progress = 0
    print("Progress: {:>3} %".format( progress * 100 / len(files) ), end=' ')
    for f in files:
        # create the output filename
        labelIdFileName = f.replace( ".json" , "_labelIds.png" )
        colorFileName   = f.replace( ".json" , "_color.png" )

        # do the conversion
        try:
            json2labelImg(f, labelIdFileName)
            json2labelImg(f, colorFileName, encoding='color')
        except:
            print("Failed to convert: {}".format(f))
            raise

        # status
        progress += 1
        print("\rProgress: {:>3} %".format( progress * 100 / len(files) ), end=' ')
        sys.stdout.flush()