Beispiel #1
0
def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('--exp-name', type=str, default='C20_S1_0.1_CS')
    parser.add_argument('--split', type=str, default='val')
    parser.add_argument('--save-each-confmat', type=bool, default=True)
    # parser.add_argument('--dir-struct', type=str, default='deeplab')
    # parser.add_argument('--class-subset', type=int, nargs='+', default=None)

    parser.add_argument('--dir-struct', type=str, default='mtpt')
    parser.add_argument('--class-subset',
                        type=int,
                        nargs='+',
                        default=[0, 1, 2, 3, 4, 5, 7, 8, 11, 13, 19])
    # parser.add_argument('--predict-list', type=str,
    #                     help='list of predictions')
    # parser.add_argument('--target-list', type=str,
    #                     help='list of targets')
    # parser.add_argument('--output-dir', type=str,
    #                     help='directory stores the output')

    ##
    opts = parser.parse_args()

    opts.target_list = sorted(
        glob.glob(join(data_dir,
                       'CityScapes/ReOrg/SegColor20-1024/val/*.png')))
    if opts.dir_struct == 'deeplab':
        predict_dir = join(data_dir, 'Exp/DeepLabCityscapes', opts.exp_name,
                           'predict')
        opts.predict_list = sorted(
            glob.glob(join(predict_dir, opts.split, '*.png')))
        record_dir = mkdir2(join(data_dir, 'Exp/DeepLabCityscapes/record'))
    elif opts.dir_struct == 'mtpt':
        predict_dir = join(data_dir, 'Exp/Cityscapes/mtpt/output',
                           opts.exp_name)
        opts.predict_list = sorted(
            glob.glob(join(predict_dir, 'pred', '*.png')))
        record_dir = mkdir2(join(data_dir, 'Exp/Cityscapes/record'))
    else:
        raise ValueError('Undefined directory structure')
    opts.outfile_record_entry = join(record_dir, opts.exp_name + '.csv')
    opts.outfile_summary = join(predict_dir,
                                'eval-' + opts.split + '-summary.txt')
    opts.outfile_per_class = join(
        predict_dir, 'eval-' + opts.split + '-summary-per-class.txt')
    opts.outfile_per_inst = join(predict_dir,
                                 'eval-' + opts.split + '-per-inst.txt')
    opts.outfile_per_inst_per_class = join(
        predict_dir, 'eval-' + opts.split + '-per-inst-per-class.txt')
    if opts.save_each_confmat:
        opts.confmat_dir = mkdir2(join(predict_dir, 'confmat', opts.split))
        opts.confmat_total = join(predict_dir, 'confmat', opts.split + '.txt')

    return opts
Beispiel #2
0
    car_mask = (img == 10).astype(np.uint8)
    # This point is always the ego-vehicle thus not other car masks
    seed = (w // 2, h - 1)
    dummy_mask = np.zeros((h + 2, w + 2), np.uint8)
    cv2.floodFill(car_mask, dummy_mask, seed, 255)
    new_mask = car_mask != 255
    img[new_mask] = 10
    return img


single_mode = 0

if single_mode:
    ## single mode
    in_dir = join(data_dir, 'Exp/CARLA_gen20_town2/e000003/SegRaw')
    out_dir = mkdir2(join(data_dir, 'Exp/CARLA_gen20_town2/e000003/Seg'))
    mask_file = join(data_dir, 'Exp/CARLA_gen20_town2/ego-vehicle.png')

    mask = np.array(Image.open(mask_file), dtype=bool)

    files = glob.glob(join(in_dir, '*.png'))
    for f in files:
        img = np.array(Image.open(f))
        img = img[:, :, 0]
        img[mask] = 13
        img = proc_sky(img)
        img = proc_car(img)
        img = Image.fromarray(c2trainid(img).astype(np.uint8))
        img.putpalette(cm)
        img.save(join(out_dir, os.path.basename(f)))
else:
Beispiel #3
0
# parser.add_argument('--dir-struct', type=str, default='deeplab')
# parser.add_argument('--class-subset', type=int, nargs='+', default=None)

parser.add_argument('--dir-struct', type=str, default='mtpt')
parser.add_argument('--class-subset',
                    type=int,
                    nargs='+',
                    default=[0, 1, 2, 3, 4, 5, 7, 8, 11, 13, 19])

opts = parser.parse_args()

exp_name = opts.exp_name
if opts.dir_struct == 'deeplab':
    exp_dir = join(data_dir, 'Exp/DeepLabCityscapes', exp_name)
    predict_dir = join(exp_dir, 'predict')
    out_dir = mkdir2(join(exp_dir, 'vis'))
    out_name = 'index.html'
    reorg_dir = join(out_dir, '../../../../Cityscapes/ReOrg')
    inputs = join(reorg_dir, 'Image-512-JPG/val/*.jpg')
    outputs = join(out_dir, '../predict/val/*.png')
    targets = join(reorg_dir, 'SegColor20-1024/val/*.png')
    targets_org = join(reorg_dir, 'SegColor35-1024/val/*.png')
    external_path = 'http://mt1080.pc.cs.cmu.edu:21368/Exp/DeepLabCityscapes/' + exp_name + '/vis/' + out_name
elif opts.dir_struct == 'mtpt':
    predict_dir = join(data_dir, 'Exp/Cityscapes/mtpt', 'output', exp_name)
    out_dir = predict_dir
    out_name = 'advanced.html'
    reorg_dir = join(out_dir, '../../../../../Cityscapes/ReOrg')
    inputs = join(reorg_dir, 'Image-512-JPG/val/*.jpg')
    outputs = join(out_dir, 'pred/*.png')
    targets = join(reorg_dir, 'SegColor20-1024/val/*.png')
Beispiel #4
0
import sys

sys.path.insert(0, '../util')
from platform_config import data_dir, mkdir2

import os, glob, random, math
from os.path import join
from shutil import copy2
import numpy as np

# for converting to indexed images
from PIL import Image
from cityscapes import c2clabelfromrgb, cm_train

build_dir = mkdir2(join(data_dir,
                        'Exp/C20_S1'))  # gen 18, weather 2, subsampling step 1
train_source_dir = join(data_dir, 'Exp/CARLA_gen20')
test_source_dir = join(data_dir, 'Exp/CARLA_gen20_town2')
rgb_dir = mkdir2(join(build_dir, 'RGB-1024'))
seg_dir = mkdir2(join(build_dir, 'Seg-1024'))

n_frame = 10000

train_seqs = glob.glob(join(train_source_dir, 'e*'))
train_seqs = sorted(list(filter(lambda s: os.path.isdir(s), train_seqs)))

test_seqs = glob.glob(join(test_source_dir, 'e*'))
test_seqs = sorted(list(filter(lambda s: os.path.isdir(s), test_seqs)))

n_val = 2
n_train = len(train_seqs) - n_val
Beispiel #5
0
## Setting up platform dependent stuffs
import sys; sys.path.insert(0, '../../util')
from platform_config import data_dir, mkdir2


from os.path import join, basename
from html4vision import Col, imagetable

out_dir = mkdir2(join(data_dir, 'Exp/C2C/Visual'))
exp_name = 'test6'
# exp_name = basename(__file__)[:-3]


seq_dir = join(data_dir, 'Exp/CARLA_gen19/e000001')
exp_dir = join(data_dir, 'Exp/C2C', exp_name)

seg_colors = join(seq_dir, 'SegColor/*.png')
source_imgs = join(seq_dir, 'RGB/*.png')

matched = join(exp_dir, 'SegMatch-256-Vis/*.jpg')
canvas = join(exp_dir, 'Canvas-512-Vis/*.jpg')
refined = join(exp_dir, 'Refined-512/*.png')

road1_source = join(exp_dir, 'SegMatch-256-VisEx/*_road1.jpg')
car1_source = join(exp_dir, 'SegMatch-256-VisEx/*_car1.jpg')
car2_source = join(exp_dir, 'SegMatch-256-VisEx/*_car2.jpg')
car3_source = join(exp_dir, 'SegMatch-256-VisEx/*_car3.jpg')
building1_source = join(exp_dir, 'SegMatch-256-VisEx/*_building1.jpg')

sel = None # all
Beispiel #6
0
import sys

sys.path.insert(0, '../util')
from platform_config import data_dir, mkdir2

from glob import glob
from os.path import join
from shutil import copy2
from PIL import Image

split = 'train'
in_dir = join(r'D:\c2c2', split, 'images')
out_dir128 = mkdir2(join(data_dir, 'CarlaGen/C18_W2_S1/CycleGAN-128', split))
out_dir1024 = mkdir2(join(data_dir, 'CarlaGen/C18_W2_S1/CycleGAN-1024', split))

file_list = sorted(glob(join(in_dir, '*_fake_B.png')))
n = len(file_list)

for i, f in enumerate(file_list):
    print('Processing %d/%d - %s' % (i, n, f))
    copy2(f, join(out_dir128, '%08d.png' % (i + 1)))
    img = Image.open(f)
    img = img.resize((2048, 1024), Image.BICUBIC)
    img.save(join(out_dir1024, '%08d.png' % (i + 1)))