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/', '../../'))
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')
Beispiel #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;}',
    )
Beispiel #4
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
    )
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))
Beispiel #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;}"
    )
Beispiel #7
0
    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):
            eval_summary = pickle.load(open(eval_path, 'rb'))
            summary_row.append('%.3g' % eval_summary['stats'][0])
        else:
            summary_row.append('')
    else:
        summary_row.append('')

imagetable(
    cols,
    join(out_dir, out_name),
    title,
    summary_row=summary_row,
    # imscale=0.3 + imsize=1
    imsize=(288, 180),
    sortable=True,
    sticky_header=True,
    sort_style='materialize',
    style=
    'body {margin: 0}\n.html4vision td img {display: block; margin-left: auto; margin-right: auto;}',
    pathrep=srv_dir,
)

url = f'http://{host_name}:{srv_port}{out_dir.replace(srv_dir, "")}/{out_name}'
print(url)
Beispiel #8
0
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)

imagetable(baseline_tpfp_bed, 'baseline_tpfp_bed.html', imscale=0.7)

imagetable(baseline_tpfp_toilet, 'baseline_tpfp_toilet.html', imscale=0.7)

imagetable(baseline_tpfp_tv, 'baseline_tpfp_tv.html', imscale=0.7)

imagetable(baseline_tpfp_couch, 'baseline_tpfp_couch.html', imscale=0.7)

imagetable(baseline_tpfp_pottedplant,
           'baseline_tpfp_potted_plant.html',
           imscale=0.7)

###########################
###########################
Beispiel #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;}',
)
Beispiel #10
0
for i in range(len(train_class_name)):
    cols.append(Col('text', train_class_name[i], per_inst_per_class[:, i],
                    sel))

summaryrow = [
    'S', summary[0], *(7 * ['']), summary[1], summary[2], *summary_per_class
]

assert (len(summaryrow) == len(cols))

out_path = join(out_dir, out_name)

imagetable(
    cols,
    out_path,
    exp_name,
    imsize=(512, 256),
    overlaytoggle=True,
    pathrep=out_dir + '/',
    stickyheader=True,
    sortcol=1,
    sortable=True,
    sortstyle='metro-dark',
    zebra=True,
    summaryrow=summaryrow,
    style='.html4vision tr.static td {background-color: #ffc044 !important}')

print('Generated at ' + out_path)
print('External path: ' + external_path)
Beispiel #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
Beispiel #12
0
cols_toilet = [
    Col('img', 'TOILET', 'vis_top_detections/toilet/*'),
]

cols_tv = [
    Col('img', 'TV', 'vis_top_detections/tv/*'),
]

cols_couch = [
    Col('img', 'COUCH', 'vis_top_detections/couch/*'),
]

cols_pottedplant = [
    Col('img', 'POTTED PLANT', 'vis_top_detections/potted_plant/*'),
]

# html table generation
imagetable(cols_all, imscale=0.6)

imagetable(cols_chair, 'chair.html')

imagetable(cols_bed, 'bed.html')

imagetable(cols_toilet, 'toilet.html')

imagetable(cols_tv, 'tv.html')

imagetable(cols_couch, 'couch.html')

imagetable(cols_pottedplant, 'potted_plant.html')
        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])
        else:
            summary_A = ''
        if isfile(eval_B):
            eval_summary = pickle.load(open(eval_B, 'rb'))
            summary_B = '%.1f' % (100 * eval_summary['stats'][0])
        else:
            summary_B = ''
        summary_row.append(f'{summary_A} vs {summary_B}')
    else:
        summary_row.append('')

imagetable(
    cols,
    join(out_dir, out_name),
    title,
    summary_row=summary_row,
    imscale=0.3,
    # style='body {margin: 0}\n.html4vision td img {display: block; margin-left: auto; margin-right: auto;}',
    style=
    'img {border: 1px solid black;-webkit-box-shadow: 2px 2px 1px #ccc; box-shadow: 2px 2px 1px #ccc;}',
    pathrep=srv_dir,
    copyright=False,
)

url = f'http://{host_name}:{srv_port}{out_dir.replace(srv_dir, "")}/{out_name}'
print(url)
Beispiel #14
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)
Beispiel #15
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)

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]),
]

# # html table generation

imagetable(baseline_html, 'baseline.html', imscale=0.6)
imagetable(local_html, 'local2.html', imscale=0.6)

# imagetable(baseline_tpfp_bed, 'baseline_tpfp_bed.html', imscale=0.7)
Beispiel #17
0
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),
    Col('img', 'Building 1 Source', building1_source, sel),    
]

out_path = join(out_dir, exp_name + '.html')

imagetable(cols, out_path, exp_name, imsize=(512, 256), interactive=True, pathrep=(join(data_dir, 'Exp'), '../..'))


Beispiel #18
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,
           'another-dir/pathrep.html',
           'Path Replace Example',
           pathrep=('images', '../images'))
Beispiel #19
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)
Beispiel #20
0
    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)
        if isfile(eval_path):
            eval_summary = pickle.load(open(eval_path, 'rb'))
            summary_row.append('%.3g' % eval_summary['stats'][0])
        else:
            summary_row.append('')
    else:
        summary_row.append('')

imagetable(
    cols,
    join(out_dir, out_name),
    title,
    summary_row=summary_row,
    # imscale=0.3 + imsize=1
    imsize=(288, 180),
    sortable=True,
    sticky_header=True,
    sort_style='materialize',
    style='body {margin: 0}',
    pathrep=srv_dir,
)

url = f'http://{host_name}:{srv_port}{out_dir.replace(srv_dir, "")}/{out_name}'
print(url)
    sid = img['sid']
    seq = seqs[sid]
    img_paths.append(join(seq_dirs[sid], img['name']))
    vid_paths.append(join(video_dir, split, seq + '.mp4'))

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

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))

imagetable(
    cols,
    join(out_dir, out_name),
    title,
    imscale=0.5,
    sortable=True,
    sticky_header=True,
    sort_style='materialize',
    style='body {margin: 0}',
    pathrep=srv_dir,
)

if host_name is None:
    host_name = socket.gethostname()
url = f'http://{host_name}:{srv_port}{out_dir.replace(srv_dir, "")}/{out_name}'
print(url)
Beispiel #22
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)
Beispiel #23
0
            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
    sortcol=2,  # initially sort based on column 2 (class average performance)
    sortable=True,  # enable interactive sorting
    sticky_header=True,  # keep the header on the top
    sort_style=
    'materialize',  # use the theme "materialize" from jquery.tablesorter
    zebra=True,  # use zebra-striped table
)