A generic Visdom class that works with the majority of Visdom plot types.
| 943 | |
| 944 | |
| 945 | class VisdomFeatureMapsLogger(BaseVisdomLogger): |
| 946 | ''' |
| 947 | A generic Visdom class that works with the majority of Visdom plot types. |
| 948 | ''' |
| 949 | |
| 950 | def __init__(self, plot_type, pad_value=1, nrow=2, fields=None, win=None, env=None, opts={}, port=8097, server="localhost"): |
| 951 | ''' |
| 952 | Args: |
| 953 | fields: Currently unused |
| 954 | plot_type: The name of the plot type, in Visdom |
| 955 | |
| 956 | |
| 957 | ''' |
| 958 | super(VisdomFeatureMapsLogger, self).__init__(fields, win, env, opts, port, server) |
| 959 | self.plot_type = plot_type |
| 960 | self.pad_value = pad_value |
| 961 | self.nrow = nrow |
| 962 | self.chart = getattr(self.viz, plot_type) |
| 963 | self.viz_logger = self._viz_prototype(self.chart) |
| 964 | |
| 965 | def log(self, *args, **kwargs): |
| 966 | self.viz_logger(*args, **kwargs) |
| 967 | |
| 968 | def images(self, bchw_tensor): |
| 969 | self._viz.images(bchw_tensor, padding=self.pad_value, nrow=self.nrow, win=self.win, |
| 970 | env=self.env, |
| 971 | opts=self.opts) |
| 972 | |
| 973 | def img(self, name, img_): |
| 974 | """ |
| 975 | self.img('input_img',t.Tensor(64,64)) |
| 976 | """ |
| 977 | |
| 978 | if len(img_.size()) < 3: |
| 979 | img_ = img_.cpu().unsqueeze(0) |
| 980 | self._viz.image(img_.cpu(), |
| 981 | win=name, |
| 982 | opts=dict(title=name) |
| 983 | ) |
| 984 | def img_grid_many(self, d): |
| 985 | for k, v in d.items(): |
| 986 | self.img_grid(k, v) |
| 987 | |
| 988 | def img_grid(self, name, input_3d): |
| 989 | """ |
| 990 | Turning a batch of images to a grid |
| 991 | e.g. input shape: (36, 64, 64) |
| 992 | Will be a grid of 6x6, each grid is |
| 993 | an image size 64x64 |
| 994 | """ |
| 995 | self.img('key', tv.utils.make_grid( |
| 996 | input_3d.cpu().unsqueeze(1), pad_value=self.pad_value, nrow=self.nrow)) |
| 997 | |
| 998 | |
| 999 |
nothing calls this directly
no outgoing calls
no test coverage detected