Beispiel #1
0
 def __init__(self, name='AverageReturn', buffer_size=10, batch_size=None):
   """Creates an AverageReturnMetric."""
   self._np_state = numpy_storage.NumpyState()
   # Set a dummy value on self._np_state.episode_return so it gets included in
   # the first checkpoint (before metric is first called).
   self._np_state.episode_return = np.float64(0)
   super(AverageReturnMetric, self).__init__(name, buffer_size=buffer_size,
                                             batch_size=batch_size)
    def testSaveRestore(self):
        arrays = numpy_storage.NumpyState()
        checkpoint = tf.train.Checkpoint(numpy_arrays=arrays)
        arrays.x = np.ones([3, 4])
        directory = self.get_temp_dir()
        prefix = os.path.join(directory, 'ckpt')
        save_path = checkpoint.save(prefix)
        arrays.x[:] = 0.
        self.assertAllEqual(arrays.x, np.zeros([3, 4]))
        checkpoint.restore(save_path).assert_consumed()
        self.assertAllEqual(arrays.x, np.ones([3, 4]))

        second_checkpoint = tf.train.Checkpoint(
            numpy_arrays=numpy_storage.NumpyState())
        # Attributes of NumpyState objects are created automatically by restore()
        second_checkpoint.restore(save_path).assert_consumed()
        self.assertAllEqual(np.ones([3, 4]), second_checkpoint.numpy_arrays.x)
Beispiel #3
0
  def __init__(self, data_spec, capacity):
    """Creates a PyUniformReplayBuffer.

    Args:
      data_spec: An ArraySpec or a list/tuple/nest of ArraySpecs describing a
        single item that can be stored in this buffer.
      capacity: The maximum number of items that can be stored in the buffer.
    """
    super(PyUniformReplayBuffer, self).__init__(data_spec, capacity)

    self._storage = numpy_storage.NumpyStorage(self._encoded_data_spec(),
                                               capacity)
    self._lock = threading.Lock()
    self._np_state = numpy_storage.NumpyState()

    # Adding elements to the replay buffer is done in a circular way.
    # Keeps track of the actual size of the replay buffer and the location
    # where to add new elements.
    self._np_state.size = np.int64(0)
    self._np_state.cur_id = np.int64(0)

    # Total number of items that went through the replay buffer.
    self._np_state.item_count = np.int64(0)
Beispiel #4
0
 def __init__(self, name='Counter'):
   super(CounterMetric, self).__init__(name)
   self._np_state = numpy_storage.NumpyState()
   self.reset()
Beispiel #5
0
 def __init__(self, name='NumberOfEpisodes'):
   super(NumberOfEpisodes, self).__init__(name)
   self._np_state = numpy_storage.NumpyState()
   self.reset()
Beispiel #6
0
 def __init__(self, name='EnvironmentSteps'):
   super(EnvironmentSteps, self).__init__(name)
   self._np_state = numpy_storage.NumpyState()
   self.reset()