def _get_values(self, data_blob, dtype_enum, shape_string):
     """Obtains values for histogram data given blob and dtype enum.
 Args:
   data_blob: The blob obtained from the database.
   dtype_enum: The enum representing the dtype.
   shape_string: A comma-separated string of numbers denoting shape.
 Returns:
   The histogram values as a list served to the frontend.
 """
     buf = np.frombuffer(data_blob,
                         dtype=tf.DType(dtype_enum).as_numpy_dtype)
     return buf.reshape([int(i) for i in shape_string.split(',')]).tolist()
  def _get_value(self, scalar_data_blob, dtype_enum):
    """Obtains value for scalar event given blob and dtype enum.

    Args:
      scalar_data_blob: The blob obtained from the database.
      dtype_enum: The enum representing the dtype.

    Returns:
      The scalar value.
    """
    tensorflow_dtype = tf.DType(dtype_enum)
    buf = np.frombuffer(scalar_data_blob, dtype=tensorflow_dtype.as_numpy_dtype)
    return np.asscalar(buf)
Exemple #3
0
    def pr_curves_impl(self, runs, tag):
        """Creates the JSON object for the PR curves response for a run-tag combo.

    Arguments:
      runs: A list of runs to fetch the curves for.
      tag: The tag to fetch the curves for.

    Raises:
      ValueError: If no PR curves could be fetched for a run and tag.

    Returns:
      The JSON object for the PR curves route response.
    """
        if self._db_connection_provider:
            # Serve data from the database.
            db = self._db_connection_provider()

            # We select for steps greater than -1 because the writer inserts
            # placeholder rows en masse. The check for step filters out those rows.
            cursor = db.execute(
                '''
        SELECT
          Runs.run_name,
          Tensors.step,
          Tensors.computed_time,
          Tensors.data,
          Tensors.dtype,
          Tensors.shape,
          Tags.plugin_data
        FROM Tensors
        JOIN Tags
          ON Tensors.series = Tags.tag_id
        JOIN Runs
          ON Tags.run_id = Runs.run_id
        WHERE
          Runs.run_name IN (%s)
          AND Tags.tag_name = ?
          AND Tags.plugin_name = ?
          AND Tensors.step > -1
        ORDER BY Tensors.step
      ''' % ','.join(['?'] * len(runs)), runs + [tag, metadata.PLUGIN_NAME])
            response_mapping = {}
            for (run, step, wall_time, data, dtype, shape,
                 plugin_data) in cursor:
                if run not in response_mapping:
                    response_mapping[run] = []
                buf = np.frombuffer(data, dtype=tf.DType(dtype).as_numpy_dtype)
                data_array = buf.reshape([int(i) for i in shape.split(',')])
                plugin_data_proto = plugin_data_pb2.PrCurvePluginData()
                string_buffer = np.frombuffer(plugin_data, dtype=np.dtype('b'))
                plugin_data_proto.ParseFromString(
                    tf.compat.as_bytes(string_buffer.tostring()))
                thresholds = self._compute_thresholds(
                    plugin_data_proto.num_thresholds)
                entry = self._make_pr_entry(step, wall_time, data_array,
                                            thresholds)
                response_mapping[run].append(entry)
        else:
            # Serve data from events files.
            response_mapping = {}
            for run in runs:
                try:
                    tensor_events = self._multiplexer.Tensors(run, tag)
                except KeyError:
                    raise ValueError(
                        'No PR curves could be found for run %r and tag %r' %
                        (run, tag))

                content = self._multiplexer.SummaryMetadata(
                    run, tag).plugin_data.content
                pr_curve_data = metadata.parse_plugin_metadata(content)
                thresholds = self._compute_thresholds(
                    pr_curve_data.num_thresholds)
                response_mapping[run] = [
                    self._process_tensor_event(e, thresholds)
                    for e in tensor_events
                ]
        return response_mapping