Beispiel #1
0
  def build_inference(self, handle, use_moving_average=False,
                      clear_existing_annotations=False):
    """Builds an inference pipeline.

    This always uses the whole pipeline.

    Args:
      handle: Handle tensor for the ComputeSession.
      use_moving_average: Whether or not to read from the moving
        average variables instead of the true parameters. Note: it is not
        possible to make gradient updates when this is True.
      clear_existing_annotations: Whether or not existing annotations
        should be cleared when processing a new batch.

    Returns:
      handle: Handle after annotation.
    """
    self.read_from_avg = use_moving_average
    network_states = {}

    for comp in self.components:
      network_states[comp.name] = component.NetworkState()
      handle = dragnn_ops.init_component_data(
          handle, component=comp.name,
          clear_existing_annotations=clear_existing_annotations)
      master_state = component.MasterState(handle,
                                           dragnn_ops.batch_size(
                                               handle, component=comp.name))
      with tf.control_dependencies([handle]):
        handle = comp.build_inference(master_state, network_states)
      handle = dragnn_ops.write_annotations(handle, component=comp.name)

    self.read_from_avg = False
    return handle
    def build_inference(self, handle, use_moving_average=False):
        """Builds an inference pipeline.

    This always uses the whole pipeline.

    Args:
      handle: Handle tensor for the ComputeSession.
      use_moving_average: Whether or not to read from the moving
        average variables instead of the true parameters. Note: it is not
        possible to make gradient updates when this is True.

    Returns:
      handle: Handle after annotation.
    """
        self.read_from_avg = use_moving_average
        network_states = {}

        for comp in self.components:
            network_states[comp.name] = component.NetworkState()
            handle = dragnn_ops.init_component_data(
                handle,
                beam_size=comp.inference_beam_size,
                component=comp.name)
            master_state = component.MasterState(
                handle, dragnn_ops.batch_size(handle, component=comp.name))
            with tf.control_dependencies([handle]):
                handle = comp.build_greedy_inference(master_state,
                                                     network_states)
            handle = dragnn_ops.write_annotations(handle, component=comp.name)

        self.read_from_avg = False
        return handle
Beispiel #3
0
  def build_inference(self,
                      handle,
                      use_moving_average=False,
                      build_runtime_graph=False):
    """Builds an inference pipeline.

    This always uses the whole pipeline.

    Args:
      handle: Handle tensor for the ComputeSession.
      use_moving_average: Whether or not to read from the moving
        average variables instead of the true parameters. Note: it is not
        possible to make gradient updates when this is True.
      build_runtime_graph: Whether to build a graph for use by the runtime.

    Returns:
      handle: Handle after annotation.
    """
    self.read_from_avg = use_moving_average
    self.build_runtime_graph = build_runtime_graph
    network_states = {}

    for comp in self.components:
      network_states[comp.name] = component.NetworkState()
      handle = dragnn_ops.init_component_data(
          handle, beam_size=comp.inference_beam_size, component=comp.name)
      if build_runtime_graph:
        batch_size = 1  # runtime uses singleton batches
      else:
        batch_size = dragnn_ops.batch_size(handle, component=comp.name)
      master_state = component.MasterState(handle, batch_size)
      with tf.control_dependencies([handle]):
        handle = comp.build_greedy_inference(master_state, network_states)
      handle = dragnn_ops.write_annotations(handle, component=comp.name)

    self.read_from_avg = False
    self.build_runtime_graph = False
    return handle