Exemplo n.º 1
0
 def write(self, values: base.LoggingData):
     with self.summary.as_default():
         for key, value in values.items():
             tf.summary.scalar(f'{self.label}/{_format_key(key)}',
                               value,
                               step=self._iter)
     self._iter += 1
Exemplo n.º 2
0
 def write(self, data: base.LoggingData):
   for k, v in data.items():
     image = Image.fromarray(v, mode=self._mode)
     path = self._path / f'{k}_{self._indices[k]:06}.png'
     self._indices[k] += 1
     with path.open(mode='wb') as f:
       logging.info('Writing image to %s.', str(path))
       image.save(f)
Exemplo n.º 3
0
    def write(self, data: base.LoggingData, step: Optional[int] = None):
        """Writes a set of scalar values in the log at a specific time step
        
        Args:
            data: a dictionary with name of quantity: quantity pairs
            step: optionally the number of the step to register the data, if None, the internal is used
        """
        if step is not None:
            iteration = step
        else:
            iteration = self._iter
            self._iter += 1

        for key, value in data.items():
            self._writer.add_scalar(key, value, iteration)
Exemplo n.º 4
0
    def write(self, values: base.LoggingData) -> None:
        # If this is in init, launchpad fails,
        # Error: tensorflow.python.framework.errors_impl.InvalidArgumentError:
        #   Cannot convert a Tensor of dtype resource to a NumPy array.
        # Line: CloudPickler(file, protocol=protocol, buffer_callback
        #   =buffer_callback).dump(obj)
        if self._summary is None:
            self._summary = tf.summary.create_file_writer(self._logdir)

        with self._summary.as_default():
            for key, value in values.items():
                if hasattr(value, "shape") and len(value.shape) > 0:
                    self.histogram_summary(key, value)
                elif hasattr(value, "shape") or not isinstance(value, dict):
                    self.scalar_summary(key, value)
                else:
                    self.dict_summary(key, value)
            self._iter += 1
Exemplo n.º 5
0
def serialize(values: base.LoggingData) -> str:
    """Converts `values` to a pretty-printed string.

  This takes a dictionary `values` whose keys are strings and returns
  a formatted string such that each [key, value] pair is separated by ' = ' and
  each entry is separated by ' | '. The keys are sorted alphabetically to ensure
  a consistent order, and snake case is split into words.

  For example:

      values = {'a': 1, 'b' = 2.33333333, 'c': 'hello', 'big_value': 10}
      # Returns 'A = 1 | B = 2.333 | Big Value = 10 | C = hello'
      values_string = serialize(values)

  Args:
    values: A dictionary with string keys.

  Returns:
    A formatted string.
  """
    return ' | '.join(f'{_format_key(k)} = {_format_value(v)}'
                      for k, v in sorted(values.items()))
Exemplo n.º 6
0
 def write(self, values: base.LoggingData):
     values = {k: v for k, v in values.items() if v is not None}
     self._to.write(values)
Exemplo n.º 7
0
 def write(self, data: base.LoggingData):
     if self._keep:
         data = {k: data[k] for k in self._keep}
     if self._drop:
         data = {k: v for k, v in data.items() if k not in self._drop}
     self._to.write(data)
Exemplo n.º 8
0
 def write(self, values: base.LoggingData):
   self._wandb.log({self.label + k: v for k, v in values.items()})
   self._iter += 1