def __call__(self, trainer): if _available: # Dynamically import pyplot so that the backend of matplotlib # can be configured after importing chainercv. import matplotlib.pyplot as plt else: return if hasattr(self.iterator, 'reset'): self.iterator.reset() it = self.iterator else: it = copy.copy(self.iterator) idx = 0 while True: try: batch = next(it) except StopIteration: break imgs = [img for img, _, _ in batch] pred_bboxes, pred_labels, pred_scores = self.target.predict(imgs) for (img, gt_bbox, gt_label), pred_bbox, pred_label, pred_score \ in zip(batch, pred_bboxes, pred_labels, pred_scores): pred_bbox = chainer.backends.cuda.to_cpu(pred_bbox) pred_label = chainer.backends.cuda.to_cpu(pred_label) pred_score = chainer.backends.cuda.to_cpu(pred_score) out_file = self.filename.format( index=idx, iteration=trainer.updater.iteration) out_file = os.path.join(trainer.out, out_file) fig = plt.figure() ax_gt = fig.add_subplot(2, 1, 1) ax_gt.set_title('ground truth') vis_bbox(img, gt_bbox, gt_label, label_names=self.label_names, ax=ax_gt) ax_pred = fig.add_subplot(2, 1, 2) ax_pred.set_title('prediction') vis_bbox(img, pred_bbox, pred_label, pred_score, label_names=self.label_names, ax=ax_pred) plt.savefig(out_file) plt.close() idx += 1
def __call__(self, trainer): if _available: # Dynamically import pyplot so that the backend of matplotlib # can be configured after importing chainercv. import matplotlib.pyplot as plot else: return if hasattr(self.iterator, 'reset'): self.iterator.reset() it = self.iterator else: it = copy.copy(self.iterator) idx = 0 while True: try: batch = next(it) except StopIteration: break imgs = [img for img, _, _ in batch] pred_bboxes, pred_labels, pred_scores = self.target.predict(imgs) for (img, gt_bbox, gt_label), pred_bbox, pred_label, pred_score \ in zip(batch, pred_bboxes, pred_labels, pred_scores): pred_bbox = chainer.cuda.to_cpu(pred_bbox) pred_label = chainer.cuda.to_cpu(pred_label) pred_score = chainer.cuda.to_cpu(pred_score) out_file = self.filename.format( index=idx, iteration=trainer.updater.iteration) out_file = os.path.join(trainer.out, out_file) fig = plot.figure() ax_gt = fig.add_subplot(2, 1, 1) ax_gt.set_title('ground truth') vis_bbox( img, gt_bbox, gt_label, label_names=self.label_names, ax=ax_gt) ax_pred = fig.add_subplot(2, 1, 2) ax_pred.set_title('prediction') vis_bbox( img, pred_bbox, pred_label, pred_score, label_names=self.label_names, ax=ax_pred) plot.savefig(out_file) plot.close() idx += 1