コード例 #1
0
    def new_log_interval_event(self, run_states):
        """
        PaddleHub default handler for log_interval_event, it will complete visualization.
        Args:
            run_states (object): the results in train phase
        """
        scores, avg_loss, run_speed = self._calculate_metrics(run_states)
        self.tb_writer.add_scalar(tag="Loss_{}".format(self.phase),
                                  scalar_value=avg_loss,
                                  global_step=self._envs['train'].current_step)
        log_scores = ""

        s = [self.current_step]
        for metric in scores:
            self.tb_writer.add_scalar(
                tag="{}_{}".format(metric, self.phase),
                scalar_value=scores[metric],
                global_step=self._envs['train'].current_step)
            log_scores += "%s=%.5f " % (metric, scores[metric])
            s.append(scores[metric])
            # train[metric].add_record(self.current_step, scores[metric])
        logger.train("step %d / %d: loss=%.5f %s[step/sec: %.2f]" %
                     (self.current_step, self.max_train_steps, avg_loss,
                      log_scores, run_speed))
        s.append(avg_loss)
        # train_loss.add_record(self.current_step, avg_loss)
        s = [str(x) for x in s]
        with open('./work/log/%s_train%s.txt' % (args.do_model, id),
                  'a',
                  encoding='utf-8') as f:
            f.write(','.join(s) + '\n')
コード例 #2
0
 def _default_log_interval_event(self, run_states):
     scores, avg_loss, run_speed = self._calculate_metrics(run_states)
     self.tb_writer.add_scalar(tag="Loss_{}".format(self.phase),
                               scalar_value=avg_loss,
                               global_step=self._envs['train'].current_step)
     log_scores = ""
     for metric in scores:
         self.tb_writer.add_scalar(
             tag="{}_{}".format(metric, self.phase),
             scalar_value=scores[metric],
             global_step=self._envs['train'].current_step)
         log_scores += "%s=%.5f " % (metric, scores[metric])
     logger.train("step %d / %d: loss=%.5f %s[step/sec: %.2f]" %
                  (self.current_step, self.max_train_steps, avg_loss,
                   log_scores, run_speed))
コード例 #3
0
    def _default_log_interval_event(self, run_states):
        """
        PaddleHub default handler for log_interval_event, it will complete visualization.

        Args:
            run_states (object): the results in train phase
        """
        scores, avg_loss, run_speed = self._calculate_metrics(run_states)
        self.vdl_writer.add_scalar(tag="Loss_{}".format(self.phase),
                                   value=avg_loss,
                                   step=self._envs['train'].current_step)
        log_scores = ""
        for metric in scores:
            self.vdl_writer.add_scalar(tag="{}_{}".format(metric, self.phase),
                                       value=scores[metric],
                                       step=self._envs['train'].current_step)
            log_scores += "%s=%.5f " % (metric, scores[metric])
        logger.train("step %d / %d: loss=%.5f %s[step/sec: %.2f]" %
                     (self.current_step, self.max_train_steps, avg_loss,
                      log_scores, run_speed))
コード例 #4
0
 def new_log_interval_event(self, run_states):
     scores, avg_loss, run_speed = self._calculate_metrics(run_states)
     self.tb_writer.add_scalar(tag="Loss_{}".format(self.phase),
                               scalar_value=avg_loss,
                               global_step=self._envs['train'].current_step)
     log_scores = ""
     log = [self._envs['train'].current_step, avg_loss]
     for metric in scores:
         self.tb_writer.add_scalar(
             tag="{}_{}".format(metric, self.phase),
             scalar_value=scores[metric],
             global_step=self._envs['train'].current_step)
         log_scores += "%s=%.5f " % (metric, scores[metric])
         log.append(scores[metric])
     logger.train("step %d / %d: loss=%.5f %s[step/sec: %.2f]" %
                  (self.current_step, self.max_train_steps, avg_loss,
                   log_scores, run_speed))
     log = [str(x) for x in log]
     with open('./work/log/cls_log_{}train.txt'.format(train_i),
               'a',
               encoding='utf-8') as f:
         f.write(','.join(log) + '\n')