Exemplo n.º 1
0
 def generate_visualization(self, subset=False, num_output_imgs=10):
     # grab all dirs to grab all images
     mode = self.mode.name
     for i in range(8):
         cols = []
         imgs = self.visualize_set[i]
         if subset:
             step = len(imgs) // num_output_imgs
             indices = np.arange(0, step * num_output_imgs + 1, step)
             imgs = [imgs[i] for i in range(len(imgs)) if i in indices]
         gt_dir = [
             os.path.join(self.root_img_dir, im_ext) for im_ext in imgs
         ]
         cols += [Col('img', "GT", gt_dir)]
         for k, v in self.dirs.items():
             viz_set_list = [
                 os.path.join(v, f'viz/{i+1}/generated/{im_ext[15:]}')
                 for im_ext in imgs
             ]
             cols += [Col('img', k, viz_set_list)]
         # output html
         outfile = self.exp_root_dir + f"testset_viz_{i}.html"
         imagetable(cols,
                    out_file=outfile,
                    title=f"Results for Video {i+1}",
                    pathrep=('/home/jl5/data/data-meta/', '../../'))
Exemplo n.º 2
0
def to_html(imfiles_keep, imfiles_go):
    scores_keep = [str(sc) for _, sc in imfiles_keep]
    scores_go = [str(sc) for _, sc in imfiles_go]

    finfo = imfiles_keep[0][0] if len(imfiles_keep) else imfiles_go[0][0]
    dout = finfo.replace("/".join(finfo.split("/")[-2:]), "")

    cols = [
        Col("id1", "ID"),  # 1-based indexing
        Col(
            "img",
            "keep",
            [f.replace(dout, "") for f, _ in imfiles_keep],
            None,
            "background: #28aade",
            href=[f.replace(dout, "") for f, _ in imfiles_keep],
        ),
        Col("text", "keep (score)", scores_keep),
        Col(
            "img",
            "dump",
            [f.replace(dout, "") for f, _ in imfiles_go],
            None,
            "background: #db8a0f",
            href=[f.replace(dout, "") for f, _ in imfiles_go],
        ),
        Col("text", "dump (score)", scores_go, style="text {width: 2in;}"),
    ]
    summary_row = [
        "ID",
        len(imfiles_keep),
        np.mean([float(sc) for _, sc in imfiles_keep]),
        len(imfiles_go),
        np.mean([float(sc) for _, sc in imfiles_go]),
    ]

    imagetable(
        cols,
        dout + "face-cleanup.html",
        "Sample Decision and Score",
        summary_row=
        summary_row,  # add a summary row showing overall statistics of the dataset
        summary_color="#fff9b7",  # highlight the summary row
        sortable=True,  # enable interactive sorting
        sticky_header=True,  # keep the header on the top
        style="img {border: 1px solid black;};",
        sort_style=
        "materialize",  # use the theme "materialize" from jquery.tablesorter
        zebra=True,  # use zebra-striped table
    )
Exemplo n.º 3
0
def create_html_page_face_montage(p1, p2, labels):

    neg_ids = np.where(labels == 0)[0][-100:]
    pos_ids = np.where(labels == 1)[0][:100]

    p1_pos = p1[pos_ids]
    p1_neg = p1[neg_ids]
    p2_pos = p2[pos_ids]
    p2_neg = p2[neg_ids]

    hard_pos_pairs = np.array(list(zip(p1_pos, p2_pos)))
    hard_neg_pairs = np.array(list(zip(p1_neg, p2_neg)))

    cols = [
        Col('text', 'FID1', t1[pos_ids]),
        Col('img', 'P1', [
            CONFIGS.path.dfid + f + '.jpg' for f in list(hard_pos_pairs[:, 0])
        ]),
        Col('img', 'P2', [
            CONFIGS.path.dfid + f + '.jpg' for f in list(hard_pos_pairs[:, 1])
        ]),
        Col('text', 'Scores',
            ["{0:0.5}".format(sc * 100) for sc in scores[pos_ids]])
    ]
    # cols2 = []
    imagetable(
        cols,
        imscale=0.75,  # scale all images to 50%
        sticky_header=True,  # keep the header on the top
        out_file=dir_fold + 'hard_positives.html',
        style=
        'img {border: 1px solid black;-webkit-box-shadow: 2px 2px 1px #ccc; box-shadow: 2px 2px 1px #ccc;}',
    )
    cols = [
        Col('text', 'FID1', [
            "{}\n{}".format(tt1, tt2)
            for (tt1, tt2) in zip(t1[neg_ids], t2[neg_ids])
        ]),
        Col('img', 'P1', [
            CONFIGS.path.dfid + f + '.jpg' for f in list(hard_neg_pairs[:, 0])
        ]),
        Col('img', 'P2', [
            CONFIGS.path.dfid + f + '.jpg' for f in list(hard_neg_pairs[:, 1])
        ]),
        # Col('text', 'FID2', t2[neg_ids]),
        Col('text', 'Scores',
            ["{0:0.5}".format(sc * 100) for sc in scores[neg_ids]])
    ]

    imagetable(
        cols,
        imscale=0.75,  # scale all images to 50%
        sticky_header=True,  # keep the header on the top
        out_file=dir_fold + 'hard_negatives.html',
        style=
        'img {border: 1px solid black;-webkit-box-shadow: 2px 2px 1px #ccc; box-shadow: 2px 2px 1px #ccc;}',
    )
Exemplo n.º 4
0
def generate_html(G_net,
                  D_net,
                  device,
                  data_loaders,
                  html_save_path,
                  max_rows=64,
                  outpaint=True):
    '''
    Visualizes one batch from both the training and validation sets.
    Images are stored in the specified HTML file path.
    '''
    G_net.eval()
    D_net.eval()
    torch.set_grad_enabled(False)
    if os.path.exists(html_save_path):
        shutil.rmtree(html_save_path)
    os.makedirs(html_save_path + '/images')

    # Evaluate examples
    for phase in ['train', 'val']:
        imgs, masked_imgs, masked_parts = next(iter(data_loaders[phase]))
        masked_imgs = masked_imgs.to(device)
        outputs = G_net(masked_imgs)
        masked_imgs = masked_imgs.cpu()
        if not (outpaint):
            results = finish_inpaint(imgs, outputs.cpu())
        else:
            results = outputs.cpu()
        # Store images
        for i in range(min(imgs.shape[0], max_rows)):
            save_image(
                masked_imgs[i], html_save_path + '/images/' + phase + '_' +
                str(i) + '_masked.jpg')
            save_image(
                results[i], html_save_path + '/images/' + phase + '_' +
                str(i) + '_result.jpg')
            save_image(
                imgs[i], html_save_path + '/images/' + phase + '_' + str(i) +
                '_truth.jpg')

    # Generate table
    cols = [
        Col('id1', 'ID'),
        Col('img', 'Training set masked',
            html_save_path + '/images/train_*_masked.jpg'),
        Col('img', 'Training set result',
            html_save_path + '/images/train_*_result.jpg'),
        Col('img', 'Training set truth',
            html_save_path + '/images/train_*_truth.jpg'),
        Col('img', 'Validation set masked',
            html_save_path + '/images/val_*_masked.jpg'),
        Col('img', 'Validation set result',
            html_save_path + '/images/val_*_result.jpg'),
        Col('img', 'Validation set truth',
            html_save_path + '/images/val_*_truth.jpg'),
    ]
    imagetable(cols,
               out_file=html_save_path + '/index.html',
               pathrep=(html_save_path + '/images', 'images'))
    print('Generated image table at: ' + html_save_path + '/index.html')
Exemplo n.º 5
0
def generate_html(pairs):
    image1_list = []
    image2_list = []
    labels_list = []
    for index in pairs:
        info = pairs[index]
        image1_list.append(get_relative_image_path(info['image1']))
        image2_list.append(get_relative_image_path(info['image2']))
        labels_list.append(str(info['label']))

    cols = [
        Col('id1', 'ID'),
        Col('img', 'Image 1', image1_list),
        Col('img', 'Image 2', image2_list),
        Col('text', 'Label', labels_list)
    ]

    imagetable(cols, out_file='index.html', imsize=(320, 240))
Exemplo n.º 6
0
def generate_file(out_file_name, authors, links, titles, poster_id,
                  select_ids):
    ls = []
    # import pdb; pdb.set_trace()
    for i in range(len(authors)):
        if int(poster_id[i]) in select_ids:
            ls.append(i)
    print(ls)
    authors = [authors[x] for x in ls]
    titles = [titles[x] for x in ls]
    poster_id = [poster_id[x] for x in ls]
    links = [links[x] for x in ls]
    cols = [
        Col('text', 'ID', poster_id),
        Col('text', 'Title', titles, href=links),
        Col('text', 'Authors', authors)
    ]
    imagetable(
        cols,
        out_file_name,
        sortable=True,
        style=
        "td {text-align: left} table, th, td { border: 1px solid black;  border-collapse: collapse;   padding: 5px;}"
    )
Exemplo n.º 7
0
    consecs = np.arange(n_consec)
    sel = [n_consec * i + consecs for i in sel]
    sel = np.array(sel).flatten().tolist()

# sel = list(range(n_show))

img_paths = []
vid_paths = []

for idx in sel:
    img = imgs[idx]
    seq = seqs[img['sid']]
    img_paths.append(join(seq, img['name'][:-3] + 'jpg'))
    vid_paths.append(seq + '.mp4')

cols = [Col('id1', 'ID')]
summary_row = [metric]

for i, name in enumerate(names):
    paths = [join(dirs[i], p) for p in img_paths]
    if link_video:
        hrefs = [join(dirs[i], p) for p in vid_paths]
    else:
        hrefs = paths
    cols.append(Col('img', name, paths, href=hrefs))

    if 'Exp' in dirs[i]:
        eval_path = join(dirs[i].replace('/vis', '/output'),
                         'eval_summary.pkl')
        eval_path = eval_path.replace('-c3-eta0', '')
        if isfile(eval_path):
Exemplo n.º 8
0
from html4vision import Col, imagetable
import os

baseline_tpfp_chair = [
    Col('img', 'CHAIR', 'vis_top_detections_baseline/chair/*'),
]

baseline_tpfp_bed = [
    Col('img', 'BED', 'vis_top_detections_baseline/bed/*'),
]

baseline_tpfp_toilet = [
    Col('img', 'TOILET', 'vis_top_detections_baseline/toilet/*'),
]

baseline_tpfp_tv = [
    Col('img', 'TV', 'vis_top_detections_baseline/tv/*'),
]

baseline_tpfp_couch = [
    Col('img', 'COUCH', 'vis_top_detections_baseline/couch/*'),
]

baseline_tpfp_pottedplant = [
    Col('img', 'POTTED PLANT', 'vis_top_detections_baseline/potted_plant/*'),
]

# html table generation

imagetable(baseline_tpfp_chair, 'baseline_tpfp_chair.html', imscale=0.7)
Exemplo n.º 9
0
from html4vision import Col, imagetable

cols = [
    Col('img', 'Image', 'images/sketch_img_*'),
    Col('img', 'Sketch 1', 'images/sketch_*_1.svg'),
    Col('img', 'Sketch 2', 'images/sketch_*_2.svg'),
    Col('img', 'Sketch 3', 'images/sketch_*_3.svg',
        None, 'background: #e9f9fe'), # set background to light blue for this column
]

imagetable(
    cols,               
    'formatting.html',
    imsize=0,      # resize sketch svg to match corresponding image size (column 0)
    imscale=0.5,   # scale all images to 50%
    # adding image border and box shadows to the entire table
    style='img {border: 1px solid black;-webkit-box-shadow: 2px 2px 1px #ccc; box-shadow: 2px 2px 1px #ccc;}',
)
Exemplo n.º 10
0
summary_per_class = shorten(
    np.loadtxt(join(predict_dir, 'eval-val-summary-per-class.txt')))
per_inst = shorten(np.loadtxt(join(predict_dir, 'eval-val-per-inst.txt')))
per_inst_per_class = shorten(
    np.loadtxt(join(predict_dir, 'eval-val-per-inst-per-class.txt')))

train_class_name = [
    label.category + '.' + label.name for label in labels
    if label.trainId != 255 and label.trainId >= 0
]
if opts.class_subset is not None:
    train_class_name = [train_class_name[i] for i in opts.class_subset[:-1]]
sel = None  # all
# sel = 6

overlay_col = Col('overlay', '', inputs, sel, 'opacity: 0.15')
cols = [
    Col('id1', 'ID'),
    Col('text', 'mIoU', per_inst[:, 0], sel),
    Col('img', 'Input Image', inputs, sel),
    Col('img', 'Output Segmentation', outputs, sel),
    overlay_col,
    Col('img', 'Ground Truth (standard, 20)', targets, sel),
    overlay_col,
    Col('img', 'Ground Truth (original, 35)', targets_org, sel),
    overlay_col,
    Col('text', 'mAccu', per_inst[:, 1], sel),
    Col('text', 'Accu', per_inst[:, 2], sel),
]

for i in range(len(train_class_name)):
Exemplo n.º 11
0
from html4vision import Col, imagetable

cols = [
    # href can even be used on id columns, and uses the same glob pattern as for the content in img column
    Col('id1', 'ID', subset=1, href='images/road_*_image.jpg'),
    Col('img', 'Image + Label', 'images/road_*_image.jpg', 1, href='images/road_*_image.jpg'),
    # for overlay columns, href should be attached to the preceding img column
    Col('overlay', '', 'images/road_*_label.png', 1, 'opacity: 0.4'),
    # href supports a list of URLs, each one for each row
    Col('img', 'Amodel Road Mask', 'images/road_*_amodelroad.png', 1, href=['https://github.com/mtli/HTML4Vision']),
]

imagetable(cols, 'href.html', 'Hyperlink Example')
# Note for image overaly, href conflicts with overlay_toggle=True, since they are both triggered by the mouse click
Exemplo n.º 12
0
# 	detection_image_path = os.path.join('full/vis_detect', detection_image)
# 	detection_images.append(detection_image_path)

# print(tp_fp_images[0])
# print(detection_images[0])
# cols = [
#   # Col('id1', 'ID'),                                               # make a column of 1-based indice
#   # Col('img', 'Images with TP/FP', 'full/vis_gt/*.png'),             # specify image content for column 2
#   Col('img', 'Images with TP/FP', tp_fp_images),
#   Col('img', 'Images with Detections', detection_images),     # specify image content for column 3
# ]

cols_all = [
    # Col('id1', 'ID'),                                               # make a column of 1-based indice
    # Col('img', 'Images with TP/FP', 'full/vis_gt/*.png'),             # specify image content for column 2
    Col('img', 'CHAIR', 'vis_top_detections/chair/*'),
    Col('img', 'BED', 'vis_top_detections/bed/*'),
    #  Col('img', 'BED ONLY FALSE POSITIVES', 'vis_top_detections_bed_fp_only/bed/*'),
    Col('img', 'TOILET', 'vis_top_detections/toilet/*'),
    Col('img', 'TV', 'vis_top_detections/tv/*'),
    Col('img', 'COUCH', 'vis_top_detections/couch/*'),
    Col('img', 'POTTED PLANT', 'vis_top_detections/potted_plant/*'),
    #Col('img', 'Images with Detections', detection_images),     # specify image content for column 3
]

cols_chair = [
    Col('img', 'CHAIR', 'vis_top_detections/chair/*'),
]

cols_bed = [
    Col('img', 'BED', 'vis_top_detections/bed/*'),
Exemplo n.º 13
0
title = 'Debug'
metric = 'AP'
link_video = True

sel = 100

img_dir = '/data2/mengtial/Exp/ArgoVerse1.1-debug/pps_mrcnn50_nm_ds_s0.75_fba_iou_lin_pkt/5ab2697b-6e3e-3454-a36a-aba2c6f27818'

srv_dir = data_dir
srv_port = 40001
# host_name = socket.gethostname()
host_name = 'trinity.vision.cs.cmu.edu'

##
# print(f'python vis/make_videos.py "{img_dir}" --fps 30')

cols = [
    Col('id1', 'ID'),
    Col('img', 'Image', img_dir + '/*.jpg', sel),
]

imagetable(
    cols,
    join(out_dir, out_name),
    title,
    imscale=0.5,
    pathrep=srv_dir,
)

url = f'http://{host_name}:{srv_port}{out_dir.replace(srv_dir, "")}/{out_name}'
print(url)
Exemplo n.º 14
0
mport os.path as osp
from html4vision import Col, imagetable


# table description
cols = [
    Col('id1', 'ID'), # make a column of 1-based indices
    Col('img', 'vgg16', 'det_vgg16_Flickr_vis-0.70/*.jpg'), # specify image content for column 2

]

imagetable(cols, outfile='det_vgg16_Flickr_vis-0.70.html', title='Flickr conf pert-adapt', 
            style=None)

Exemplo n.º 15
0
print(len(col_dict[0]))
print(len(col_dict[1]))
print(len(col_dict[2]))
print(len(col_dict[3]))
print(len(col_dict[4]))
print(len(col_dict[5]))

print(len(col_dict_local[0]))
print(len(col_dict_local[1]))
print(len(col_dict_local[2]))
print(len(col_dict_local[3]))
print(len(col_dict_local[4]))
print(len(col_dict_local[5]))

baseline_html = [
    Col('img', '1', col_dict[0]),
    Col('img', '2', col_dict[1]),
    Col('img', '3', col_dict[2]),
    Col('img', '4', col_dict[3]),
    Col('img', '5', col_dict[4]),
    Col('img', '6', col_dict[5]),
]

local_html = [
    Col('img', '1', col_dict_local[0]),
    Col('img', '2', col_dict_local[1]),
    Col('img', '3', col_dict_local[2]),
    Col('img', '4', col_dict_local[3]),
    Col('img', '5', col_dict_local[4]),
    Col('img', '6', col_dict_local[5]),
]
Exemplo n.º 16
0
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

overlay_col = Col('overlay', '', seg_colors, sel, 'opacity: 0.15')
cols = [
    Col('id1', 'ID'), # 1-based indexing
    Col('img', 'CARLA RGB', source_imgs, sel),
    overlay_col,
    Col('img', 'Input Label', seg_colors, sel),
    Col('img', 'Output Image', refined, sel),
    overlay_col,
    Col('img', 'Segment Matching', matched, sel),
    overlay_col,
    Col('img', 'Canvas', canvas, sel),
    overlay_col,
    Col('img', 'Road 1 Source', road1_source, sel),
    Col('img', 'Car 1 Source', car1_source, sel),
    Col('img', 'Car 2 Source', car2_source, sel),
    Col('img', 'Car 3 Source', car3_source, sel),
Exemplo n.º 17
0
from html4vision import Col, imagetable

cols = [
    Col('img', 'Image', 'images/road_*_image.jpg'),
    Col('img', 'Label', 'images/road_*_label.png',
        1),  # 1 is used to select only the first item
    Col('img', 'Image + Label', 'images/road_*_image.jpg'),
    Col('overlay', '', 'images/road_*_label.png', 1, 'opacity: 0.4'),
]

imagetable(cols,
           'overlay.html',
           'Image Overlay',
           imscale=1.5,
           overlay_toggle=True)
Exemplo n.º 18
0
    consecs = np.arange(n_consec)
    sel = [n_consec*i + consecs for i in sel]
    sel = np.array(sel).flatten().tolist()

# sel = list(range(n_show))



img_paths = []
vid_paths = []

for idx in sel:
    img_paths.append(join(seq, img_names[idx] + '.jpg'))
    vid_paths.append(seq + '.mp4')

cols = [Col('id1', 'ID')]
summary_row = [metric]

for i, name in enumerate(names):
    paths = [join(dirs[i], p) for p in img_paths]
    if link_video:
        hrefs = [join(dirs[i], p) for p in vid_paths]
    else:
        hrefs = paths
    cols.append(
        Col('img', name, paths, href=hrefs)
    )

    if 'Exp' in dirs[i]:
        eval_path = join(dirs[i].replace('/visf-th0.5/', '/output/'), 'eval_summary_mask.pkl')
        print(eval_path)
        # sel_idx = np.random.choice(len(frames))
        # print(sel_idx)
        frame = frames[sel_idx]
        img_paths[i].append(join(seq, frame))
        vid_paths[i].append(seq + '.mp4')

cols = []
summary_row = []

for i, name in enumerate(names):
    paths = [join(dirs[i], p) for p in img_paths[i]]
    if link_video:
        hrefs = [join(dirs[i], p) for p in vid_paths[i]]
    else:
        hrefs = paths
    cols.append(Col('img', name, paths, href=hrefs))

    method_names = basename(dirname(dirs[i]))
    idx = method_names.find('-vs-')
    assert idx >= 0
    method_A = method_names[:idx]
    method_B = method_names[idx + 4:]

    if 'Exp' in dirs[i]:
        eval_A = join(data_dir, 'Exp', data_cfg, 'output', method_A, split,
                      'eval_summary.pkl')
        eval_B = join(data_dir, 'Exp', data_cfg, 'output', method_B, split,
                      'eval_summary.pkl')
        if isfile(eval_A):
            eval_summary = pickle.load(open(eval_A, 'rb'))
            summary_A = '%.1f' % (100 * eval_summary['stats'][0])
Exemplo n.º 20
0
from html4vision import Col, imagetable

cols = [
    Col('id1', 'ID'),  # 1-based indexing
    Col('img', 'Label Map', 'images/road_*_label.png'),
    Col('img', 'Road Object Map', 'images/road_*_roadobj.png'),
    Col('img', 'Amodel Road Mask', 'images/road_*_amodelroad.png'),
]

imagetable(cols)
Exemplo n.º 21
0
ave_perf = n * [None]
class_perf = [n * [None] for i in range(n_class)]
summary_info = (n_class + 1) * [None]

for i, s in enumerate(pref):
    items = s.split(' ')
    if i == 0:  # the header contains dataset summary
        for j in range(n_class + 1):
            summary_info[j] = float(items[j])
    else:  # each row contains result for each data point
        ave_perf[i - 1] = float(items[0])
        for j in range(n_class):
            class_perf[j][i - 1] = float(items[j + 1])

cols = [
    Col('id1', 'ID'),  # 1-based indexing
    Col('img', 'Detection', 'images/det_*.jpg'),
    Col('text', 'Class Average', ave_perf),
]
for i in range(n_class):
    cols.append(Col('text', class_names[i], class_perf[i]))

summary_row = ['S', '', *summary_info]
imagetable(
    cols,
    'sort.html',
    'Sorting Example',
    summary_row=
    summary_row,  # add a summary row showing overall statistics of the dataset
    summary_color='#fff9b7',  # highlight the summary row
    imscale=0.4,  # scale images to 0.4 of the original size