visdom 简单使用

官方网址: https://github.com/facebookresearch/visdom
入门教程: http://www.ainoobtech.com/pytorch/pytorch-visdom.html

安装: pip install visdom
使用: visdom

可视化某个文件夹下所有图片, 代码如下

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2019-09-07 16:20
# @Author  : wangbin
# @FileName: visdom.py

import argparse
import cv2
import glob
import imgaug.augmenters as iaa
import os
from tqdm import tqdm
import visdom
import numpy as np

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('path', type=str, help='path to image')
    args = parser.parse_args()
    path = args.path
    pattern = os.path.join(path, '**', '*.jpg')
    img_paths = glob.glob(pattern, recursive=True)

    imgs = []
    cnt = 0
    for img_path in tqdm(img_paths):
        img = cv2.imread(img_path)
        imgs.append(img[:, :, ::-1])
        cnt += 1
        if cnt > 100:
            break
    resize_aug = iaa.Resize({"height": 224, "width": 448})
    resize_imgs = resize_aug.augment_images(imgs)
    resize_imgs = np.transpose(resize_imgs, (0, 3, 1, 2))
    print(resize_imgs.shape)
    vis = visdom.Visdom(env='heatmaps')
    vis.images(resize_imgs, nrow=5, win='heatmaps', opts={'title': 'headmaps'})
原文地址:https://www.cnblogs.com/nowgood/p/visdom-base.html