MCPcopy Create free account
hub / github.com/NVIDIA/semantic-segmentation / ImageDumper

Class ImageDumper

utils/misc.py:204–417  ·  view source on GitHub ↗

Image dumping class You pass images/tensors from training pipeline into this object and it first converts them to images (doing transformations where necessary) and then writes the images out to disk.

Source from the content-addressed store, hash-verified

202
203
204class ImageDumper():
205 """
206 Image dumping class
207
208 You pass images/tensors from training pipeline into this object and it first
209 converts them to images (doing transformations where necessary) and then
210 writes the images out to disk.
211 """
212 def __init__(self, val_len, tensorboard=True, write_webpage=True,
213 webpage_fn='index.html', dump_all_images=False, dump_assets=False,
214 dump_err_prob=False, dump_num=10, dump_for_auto_labelling=False,
215 dump_for_submission=False):
216 """
217 :val_len: num validation images
218 :tensorboard: push summary to tensorboard
219 :webpage: generate a summary html page
220 :webpage_fn: name of webpage file
221 :dump_all_images: dump all (validation) images, e.g. for video
222 :dump_num: number of images to dump if not dumping all
223 :dump_assets: dump attention maps
224 """
225 self.val_len = val_len
226 self.tensorboard = tensorboard
227 self.write_webpage = write_webpage
228 self.webpage_fn = os.path.join(cfg.RESULT_DIR,
229 'best_images', webpage_fn)
230 self.dump_assets = dump_assets
231 self.dump_for_auto_labelling = dump_for_auto_labelling
232 self.dump_for_submission = dump_for_submission
233
234 self.viz_frequency = max(1, val_len // dump_num)
235 if dump_all_images:
236 self.dump_frequency = 1
237 else:
238 self.dump_frequency = self.viz_frequency
239
240 inv_mean = [-mean / std for mean, std in zip(cfg.DATASET.MEAN,
241 cfg.DATASET.STD)]
242 inv_std = [1 / std for std in cfg.DATASET.STD]
243 self.inv_normalize = standard_transforms.Normalize(
244 mean=inv_mean, std=inv_std
245 )
246
247 if self.dump_for_submission:
248 self.save_dir = os.path.join(cfg.RESULT_DIR, 'submit')
249 elif self.dump_for_auto_labelling:
250 self.save_dir = os.path.join(cfg.RESULT_DIR)
251 else:
252 self.save_dir = os.path.join(cfg.RESULT_DIR, 'best_images')
253
254 os.makedirs(self.save_dir, exist_ok=True)
255
256 self.imgs_to_tensorboard = []
257 self.imgs_to_webpage = []
258
259 if cfg.DATASET.NAME == 'cityscapes':
260 # If all images of a dataset are identical, as in cityscapes,
261 # there's no need to crop the images before tiling them into a

Callers 1

validateFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected