• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python errors.raise_exception_on_not_ok_status函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tensorflow.python.framework.errors.raise_exception_on_not_ok_status函数的典型用法代码示例。如果您正苦于以下问题:Python raise_exception_on_not_ok_status函数的具体用法?Python raise_exception_on_not_ok_status怎么用?Python raise_exception_on_not_ok_status使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了raise_exception_on_not_ok_status函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: tf_record_iterator

def tf_record_iterator(path, options=None):
  """An iterator that read the records from a TFRecords file.

  Args:
    path: The path to the TFRecords file.
    options: (optional) A TFRecordOptions object.

  Yields:
    Strings.

  Raises:
    IOError: If `path` cannot be opened for reading.
  """
  compression_type = TFRecordOptions.get_compression_type_string(options)
  with errors.raise_exception_on_not_ok_status() as status:
    reader = pywrap_tensorflow.PyRecordReader_New(
        compat.as_bytes(path), 0, compat.as_bytes(compression_type), status)

  if reader is None:
    raise IOError("Could not open %s." % path)
  while True:
    try:
      with errors.raise_exception_on_not_ok_status() as status:
        reader.GetNext(status)
    except errors.OutOfRangeError:
      break
    yield reader.record()
  reader.Close()
开发者ID:ChengYuXiang,项目名称:tensorflow,代码行数:28,代码来源:tf_record.py


示例2: _initialize_handle_and_devices

  def _initialize_handle_and_devices(self):
    """Initialize handle and devices."""
    with self._initialize_lock:
      if self._context_handle is not None:
        return
      assert self._context_devices is None
      opts = pywrap_tensorflow.TF_NewSessionOptions(
          target=compat.as_bytes(""), config=self._config)
      with errors.raise_exception_on_not_ok_status() as status:
        self._context_handle = pywrap_tensorflow.TFE_NewContext(opts, status)
        pywrap_tensorflow.TF_DeleteSessionOptions(opts)
      # Store list of devices
      self._context_devices = []
      with errors.raise_exception_on_not_ok_status() as status:
        device_list = pywrap_tensorflow.TFE_ContextListDevices(
            self._context_handle, status)
      try:
        self._num_gpus = 0
        for i in range(pywrap_tensorflow.TF_DeviceListCount(device_list)):
          with errors.raise_exception_on_not_ok_status() as status:
            dev_name = pywrap_tensorflow.TF_DeviceListName(
                device_list, i, status)
          self._context_devices.append(pydev.canonical_name(dev_name))
          with errors.raise_exception_on_not_ok_status() as status:
            dev_type = pywrap_tensorflow.TF_DeviceListType(
                device_list, i, status)
          if dev_type == "GPU":
            self._num_gpus += 1

      finally:
        pywrap_tensorflow.TF_DeleteDeviceList(device_list)
开发者ID:alexsax,项目名称:tensorflow,代码行数:31,代码来源:context.py


示例3: get_matching_files_v2

def get_matching_files_v2(pattern):
  """Returns a list of files that match the given pattern(s).

  Args:
    pattern: string or iterable of strings. The glob pattern(s).

  Returns:
    A list of strings containing filenames that match the given pattern(s).

  Raises:
    errors.OpError: If there are filesystem / directory listing errors.
  """
  with errors.raise_exception_on_not_ok_status() as status:
    if isinstance(pattern, six.string_types):
      return [
          # Convert the filenames to string from bytes.
          compat.as_str_any(matching_filename)
          for matching_filename in pywrap_tensorflow.GetMatchingFiles(
              compat.as_bytes(pattern), status)
      ]
    else:
      return [
          # Convert the filenames to string from bytes.
          compat.as_str_any(matching_filename)
          for single_filename in pattern
          for matching_filename in pywrap_tensorflow.GetMatchingFiles(
              compat.as_bytes(single_filename), status)
      ]
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:28,代码来源:file_io.py


示例4: list_directory

def list_directory(dirname):
  """Returns a list of entries contained within a directory.

  The list is in arbitrary order. It does not contain the special entries "."
  and "..".

  Args:
    dirname: string, path to a directory

  Returns:
    [filename1, filename2, ... filenameN] as strings

  Raises:
    errors.NotFoundError if directory doesn't exist
  """
  if not is_directory(dirname):
    raise errors.NotFoundError(None, None, "Could not find directory")
  with errors.raise_exception_on_not_ok_status() as status:
    # Convert each element to string, since the return values of the
    # vector of string should be interpreted as strings, not bytes.
    return [
        compat.as_str_any(filename)
        for filename in pywrap_tensorflow.GetChildren(
            compat.as_bytes(dirname), status)
    ]
开发者ID:LUTAN,项目名称:tensorflow,代码行数:25,代码来源:file_io.py


示例5: recursive_create_dir

def recursive_create_dir(dirname):
  with errors.raise_exception_on_not_ok_status() as status:
    dirs = dirname.split('/')
    for i in range(len(dirs)):
      partial_dir = '/'.join(dirs[0:i+1])
      if partial_dir and not file_exists(partial_dir):
        pywrap_tensorflow.CreateDir(compat.as_bytes(partial_dir), status)
开发者ID:AI-MR-Related,项目名称:tensorflow,代码行数:7,代码来源:file_io.py


示例6: call_cpp_shape_fn

def call_cpp_shape_fn(op):
  """A shape function that delegates to the registered C++ shape function.

  Args:
    op: the node in the graph for which to compute output shapes.

  Returns:
    A TensorShape list of the output shapes of the op, as computed using the
    C++ shape inference function registered for the op.

  Raises:
    ValueError: If the C++ shape function returned an error (e.g. because the
    shapes of the inputs are of the wrong rank or otherwise incompatible
    according to the shape function).
  """
  node_def_str = op.node_def.SerializeToString()
  input_shapes = [i.get_shape().as_proto().SerializeToString() for i in
                  op.inputs]

  try:
    with errors.raise_exception_on_not_ok_status() as status:
      output_shapes = pywrap_tensorflow.RunCppShapeInference(
          node_def_str, input_shapes, status)
  except errors.InvalidArgumentError as err:
    raise ValueError(err.message)

  # Convert TensorShapeProto values in output_shapes.
  return [
      tensor_shape.TensorShape(tensor_shape_pb2.TensorShapeProto.FromString(s))
      for s in output_shapes
  ]
开发者ID:JamesFysh,项目名称:tensorflow,代码行数:31,代码来源:common_shapes.py


示例7: smart_constant_value

def smart_constant_value(pred):
  """Return the bool value for `pred`, or None if `pred` had a dynamic value.

  Arguments:
    pred: A scalar, either a Python bool or tensor.

  Returns:
    True or False if `pred` has a constant boolean value, None otherwise.

  Raises:
    TypeError: If `pred` is not a Tensor or bool.
  """
  if pred in {0, 1}:  # Accept 1/0 as valid boolean values
    pred_value = bool(pred)
  elif isinstance(pred, bool):
    pred_value = pred
  elif isinstance(pred, ops.Tensor):
    pred_value = tensor_util.constant_value(pred)
    # TODO(skyewm): consider folding this into tensor_util.constant_value when
    # _USE_C_API is removed (there may be performance and correctness bugs, so I
    # wanted to limit the change hidden behind _USE_C_API).
    # pylint: disable=protected-access
    if pred_value is None and ops._USE_C_API:
      with errors.raise_exception_on_not_ok_status() as status:
        pred_value = c_api.TF_TryEvaluateConstant_wrapper(
            pred.graph._c_graph, pred._as_tf_output(), status)
    # pylint: enable=protected-access

  else:
    raise TypeError("`pred` must be a Tensor, or a Python bool, or 1 or 0. "
                    "Found instead: %s" % pred)
  return pred_value
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:32,代码来源:smart_cond.py


示例8: capture_value

def capture_value(tensor_map, value, dtype, name):
  """Capture a value from outside the function, to pass in as an extra arg."""
  captured_value = tensor_map.get(ops.tensor_id(value), None)
  if captured_value is None:
    captured_value = graph_placeholder(
        dtype=dtype or value.dtype, shape=value.shape, name=name)
    if captured_value.dtype == dtypes_module.resource:
      handle_data = value._handle_data  # pylint: disable=protected-access
      captured_value._handle_data = handle_data  # pylint: disable=protected-access
      if handle_data is not None and handle_data.is_set:
        # Ensure that shapes and dtypes are propagated.
        shapes, types = zip(*[(pair.shape, pair.dtype)
                              for pair in handle_data.shape_and_type])
        ranks = [len(s.dim) if not s.unknown_rank else -1 for s in shapes]
        shapes = [[d.size for d in s.dim]
                  if not s.unknown_rank else None for s in shapes]
        with errors.raise_exception_on_not_ok_status() as status:
          pywrap_tensorflow.TF_GraphSetOutputHandleShapesAndTypes_wrapper(
              captured_value._op._graph._c_graph,  # pylint: disable=protected-access
              captured_value._as_tf_output(),  # pylint: disable=protected-access
              shapes,
              ranks,
              types,
              status)

    tensor_map[ops.tensor_id(value)] = (value, captured_value)
  else:
    captured_value = captured_value[1]
  tape.record_operation("captured_value", [captured_value], [value],
                        lambda x: [x])
  return captured_value
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:31,代码来源:function.py


示例9: __init__

  def __init__(self,
               allow_soft_placement=True,
               disable_detailed_stats=True,
               disable_timeline=True,
               devices=None):
    """Creates a Cluster.

    Args:
      allow_soft_placement: If True, TF will automatically fix illegal
        placements instead of erroring out if the placement isn't legal.
      disable_detailed_stats: If True, detailed statistics will not be
        available.
      disable_timeline: If True, the timeline information will not be reported.
      devices: A list of devices of type device_properties_pb2.NamedDevice.
        If None, a device list will be created based on the spec of
        the local machine.
    """
    self._tf_cluster = None
    self._generate_timeline = not disable_timeline
    with errors.raise_exception_on_not_ok_status() as status:
      if devices is None:
        self._tf_cluster = tf_cluster.TF_NewCluster(
            allow_soft_placement, disable_detailed_stats, status)
      else:
        devices_serialized = [device.SerializeToString() for device in devices]
        self._tf_cluster = tf_cluster.TF_NewVirtualCluster(
            devices_serialized, status)
开发者ID:Kongsea,项目名称:tensorflow,代码行数:27,代码来源:cluster.py


示例10: TransformGraph

def TransformGraph(input_graph_def, inputs, outputs, transforms):
  """Python wrapper for the Graph Transform Tool.

  Gives access to all graph transforms available through the command line tool.
  See documentation at https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/graph_transforms/README.md
  for full details of the options available.

  Args:
    input_graph_def: GraphDef object containing a model to be transformed.
    inputs: List of node names for the model inputs.
    outputs: List of node names for the model outputs.
    transforms: List of strings containing transform names and parameters.

  Returns:
    New GraphDef with transforms applied.
  """

  input_graph_def_string = input_graph_def.SerializeToString()
  inputs_string = compat.as_bytes(",".join(inputs))
  outputs_string = compat.as_bytes(",".join(outputs))
  transforms_string = compat.as_bytes(" ".join(transforms))
  with errors.raise_exception_on_not_ok_status() as status:
    output_graph_def_string = TransformGraphWithStringInputs(
        input_graph_def_string, inputs_string, outputs_string,
        transforms_string, status)
  output_graph_def = graph_pb2.GraphDef()
  output_graph_def.ParseFromString(output_graph_def_string)
  return output_graph_def
开发者ID:1000sprites,项目名称:tensorflow,代码行数:28,代码来源:__init__.py


示例11: __init__

    def __init__(self, server_or_cluster_def, job_name=None, task_index=None, protocol=None, config=None, start=True):
        """Creates a new server with the given definition.

    The `job_name`, `task_index`, and `protocol` arguments are optional, and
    override any information provided in `server_or_cluster_def`.

    Args:
      server_or_cluster_def: A `tf.train.ServerDef` or
        `tf.train.ClusterDef` protocol buffer, or a
        `tf.train.ClusterSpec` object, describing the server to be
        created and/or the cluster of which it is a member.
      job_name: (Optional.) Specifies the name of the job of which the server
        is a member. Defaults to the value in `server_or_cluster_def`, if
        specified.
      task_index: (Optional.) Specifies the task index of the server in its
        job. Defaults to the value in `server_or_cluster_def`, if specified.
        Otherwise defaults to 0 if the server's job has only one task.
      protocol: (Optional.) Specifies the protocol to be used by the server.
        Acceptable values include `"grpc"`. Defaults to the value in
        `server_or_cluster_def`, if specified. Otherwise defaults to `"grpc"`.
      config: (Options.) A `tf.ConfigProto` that specifies default
        configuration options for all sessions that run on this server.
      start: (Optional.) Boolean, indicating whether to start the server
        after creating it. Defaults to `True`.

    Raises:
      tf.errors.OpError: Or one of its subclasses if an error occurs while
        creating the TensorFlow server.
    """
        self._server_def = _make_server_def(server_or_cluster_def, job_name, task_index, protocol, config)
        with errors.raise_exception_on_not_ok_status() as status:
            self._server = pywrap_tensorflow.PyServer_New(self._server_def.SerializeToString(), status)
        if start:
            self.start()
开发者ID:apollos,项目名称:tensorflow,代码行数:34,代码来源:server_lib.py


示例12: GenerateCostReport

def GenerateCostReport(metagraph,
                       per_node_report=False,
                       verbose=False,
                       cluster=None):
  """Analyze the cost of each TensorFlow op and node in the provided metagraph.

  Args:
    metagraph: A TensorFlow MetaGraphDef.
    per_node_report: by default the report contains stats aggregated on a per op
      type basis, setting per_node_report to True adds results for each
      individual node to the report.
    verbose: Prints out the entire operation proto instead of a summary table.
    cluster: Analyze the costs using the specified cluster, or the local machine
      if no cluster was specified.

  Returns:
    A string of cost report.
  """
  if cluster is None:
    cluster = gcluster.Cluster(disable_detailed_stats=False)

  with errors.raise_exception_on_not_ok_status():
    ret_from_swig = tf_wrap.GenerateCostReport(metagraph.SerializeToString(),
                                               per_node_report, verbose,
                                               cluster.tf_cluster)
  return ret_from_swig
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:26,代码来源:cost_analyzer.py


示例13: register_function_def

def register_function_def(fdef):
  fdef_string = fdef.SerializeToString()
  with errors.raise_exception_on_not_ok_status() as status:
    pywrap_tensorflow.TFE_ContextAddFunctionDef(
        context.get_default_context()._handle,  # pylint: disable=protected-access
        fdef_string,
        len(fdef_string),
        status)
开发者ID:chdinh,项目名称:tensorflow,代码行数:8,代码来源:function.py


示例14: write

  def write(self, record):
    """Write a string record to the file.

    Args:
      record: str
    """
    with errors.raise_exception_on_not_ok_status() as status:
      self._writer.WriteRecord(record, status)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:8,代码来源:tf_record.py


示例15: write

 def write(self, file_content):
   """Writes file_content to the file."""
   if not self._write_check_passed:
     raise errors.PermissionDeniedError(None, None,
                                        "File isn't open for writing")
   with errors.raise_exception_on_not_ok_status() as status:
     pywrap_tensorflow.WriteStringToFile(
         compat.as_bytes(self.__name), compat.as_bytes(file_content), status)
开发者ID:JamesFysh,项目名称:tensorflow,代码行数:8,代码来源:file_io.py


示例16: read

 def read(self):
   """Returns the contents of a file as a string."""
   if not self._read_check_passed:
     raise errors.PermissionDeniedError(None, None,
                                        "File isn't open for reading")
   with errors.raise_exception_on_not_ok_status() as status:
     return pywrap_tensorflow.ReadFileToString(
         compat.as_bytes(self.__name), status)
开发者ID:anilshanbhag,项目名称:tensorflow,代码行数:8,代码来源:file_io.py


示例17: TF_Reset

def TF_Reset(target, containers=None, config=None):
  from tensorflow.python.framework import errors
  opts = TF_NewSessionOptions(target=target, config=config)
  try:
    with errors.raise_exception_on_not_ok_status() as status:
      TF_Reset_wrapper(opts, containers, status)
  finally:
    TF_DeleteSessionOptions(opts)
开发者ID:devil15,项目名称:running_projects,代码行数:8,代码来源:pywrap_tensorflow.py


示例18: _prereadline_check

 def _prereadline_check(self):
   if not self._read_buf:
     if not self._read_check_passed:
       raise errors.PermissionDeniedError(None, None,
                                          "File isn't open for reading")
     with errors.raise_exception_on_not_ok_status() as status:
       self._read_buf = pywrap_tensorflow.CreateBufferedInputStream(
           compat.as_bytes(self.__name), 1024 * 512, status)
开发者ID:anilshanbhag,项目名称:tensorflow,代码行数:8,代码来源:file_io.py


示例19: _prewrite_check

 def _prewrite_check(self):
   if not self._writable_file:
     if not self._write_check_passed:
       raise errors.PermissionDeniedError(None, None,
                                          "File isn't open for writing")
     with errors.raise_exception_on_not_ok_status() as status:
       self._writable_file = pywrap_tensorflow.CreateWritableFile(
           compat.as_bytes(self.__name), status)
开发者ID:anilshanbhag,项目名称:tensorflow,代码行数:8,代码来源:file_io.py


示例20: _run_fn

 def _run_fn(session, feed_dict, fetch_list, target_list, options,
             run_metadata):
   # Ensure any changes to the graph are reflected in the runtime.
   self._extend_graph()
   with errors.raise_exception_on_not_ok_status() as status:
     return tf_session.TF_Run(session, options,
                              feed_dict, fetch_list, target_list,
                              status, run_metadata)
开发者ID:Jackhuang945,项目名称:tensorflow,代码行数:8,代码来源:session.py



注:本文中的tensorflow.python.framework.errors.raise_exception_on_not_ok_status函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python function._from_library函数代码示例发布时间:2022-05-27
下一篇:
Python error_interpolation.interpolate函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap