Esempio n. 1
0
 def _save_images(self):
     for i, (image, box_coord, true_box) in enumerate(
             predict_on_batch_multi_output(self.model,
                                           self.validation_datagen)):
         image_with_box = overlay_box(image, box_coord, true_box,
                                      self.bins_nr)
         filepath = os.path.join(
             self.img_dir,
             'epoch{}_batch{}_idx{}.png'.format(self.epoch_id,
                                                self.batch_id, i))
         plt.imsave(filepath, image_with_box)
Esempio n. 2
0
    def on_epoch_end(self, *args, **kwargs):
        epoch_avg_loss = self.epoch_loss_averager.value
        epoch_avg_acc = self.epoch_acc_averager.value
        self.epoch_loss_averager.reset()
        self.epoch_acc_averager.reset()

        self.model.eval()
        val_loss, val_acc = score_model_multi_output(self.model,
                                                     self.loss_function,
                                                     self.validation_datagen)
        self.model.train()

        logs = {
            'epoch_id': self.epoch_id,
            'batch_id': self.batch_id,
            'epoch_loss': epoch_avg_loss,
            'epoch_acc': epoch_avg_acc,
            'epoch_val_loss': val_loss,
            'epoch_val_acc': val_acc
        }

        self._send_numeric_channels(logs)

        for i, (image, y_pred, y_true) in enumerate(
                predict_on_batch_multi_output(self.model,
                                              self.validation_datagen)):
            image_with_box = overlay_box(image, y_pred, y_true, self.bins_nr)
            pill_image = Image.fromarray(
                (image_with_box * 255.).astype(np.uint8))
            self.ctx.channel_send(
                "plotted bbox",
                neptune.Image(name='epoch{}_batch{}_idx{}'.format(
                    self.epoch_id, self.batch_id, i),
                              description="true and prediction bbox",
                              data=pill_image))

            if i == self.img_nr:
                break
        self.epoch_id += 1