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

Python tensor_format.format_tensor函数代码示例

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

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



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

示例1: testFormatTensorWithEllipses

  def testFormatTensorWithEllipses(self):
    a = (np.arange(11 * 11 * 11) + 1000).reshape([11, 11, 11]).astype(np.int32)

    out = tensor_format.format_tensor(
        a, "a", False, np_printoptions={"threshold": 100, "edgeitems": 2})

    cli_test_utils.assert_lines_equal_ignoring_whitespace(
        self, ["Tensor \"a\":", ""], out.lines[:2])
    self.assertEqual(repr(a).split("\n"), out.lines[2:])

    self._checkTensorMetadata(a, out.annotations)

    # Check annotations for beginning indices of the lines.
    actual_row_0_0_0, _ = self._findFirst(out.lines, "1000")
    self.assertEqual({tensor_format.BEGIN_INDICES_KEY: [0, 0, 0]},
                     out.annotations[actual_row_0_0_0])
    actual_row_0_1_0, _ = self._findFirst(out.lines, "1011")
    self.assertEqual({tensor_format.BEGIN_INDICES_KEY: [0, 1, 0]},
                     out.annotations[actual_row_0_1_0])
    # Find the first line that is completely omitted.
    omitted_line = 2
    while not out.lines[omitted_line].strip().startswith("..."):
      omitted_line += 1
    self.assertEqual({tensor_format.OMITTED_INDICES_KEY: [0, 2, 0]},
                     out.annotations[omitted_line])

    actual_row_10_10_0, _ = self._findFirst(out.lines, "2320")
    self.assertEqual({tensor_format.BEGIN_INDICES_KEY: [10, 10, 0]},
                     out.annotations[actual_row_10_10_0])
    # Find the last line that is completely omitted.
    omitted_line = len(out.lines) - 1
    while not out.lines[omitted_line].strip().startswith("..."):
      omitted_line -= 1
    self.assertEqual({tensor_format.OMITTED_INDICES_KEY: [10, 2, 0]},
                     out.annotations[omitted_line])
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:35,代码来源:tensor_format_test.py


示例2: testFormatTensor2DNoEllipsisWithRowBreak

  def testFormatTensor2DNoEllipsisWithRowBreak(self):
    a = np.linspace(0.0, 1.0 - 1.0 / 40.0, 40).reshape([2, 20])

    out = tensor_format.format_tensor(
        a, "a", np_printoptions={"linewidth": 50})

    self.assertEqual(
        {"dtype": a.dtype, "shape": a.shape},
        out.annotations["tensor_metadata"])

    self.assertEqual([
        "Tensor \"a\":",
        "",
        "array([[ 0.   ,  0.025,  0.05 ,  0.075,  0.1  ,",
        "         0.125,  0.15 ,  0.175,  0.2  ,  0.225,",
        "         0.25 ,  0.275,  0.3  ,  0.325,  0.35 ,",
        "         0.375,  0.4  ,  0.425,  0.45 ,  0.475],",
        "       [ 0.5  ,  0.525,  0.55 ,  0.575,  0.6  ,",
        "         0.625,  0.65 ,  0.675,  0.7  ,  0.725,",
        "         0.75 ,  0.775,  0.8  ,  0.825,  0.85 ,",
        "         0.875,  0.9  ,  0.925,  0.95 ,  0.975]])",
    ], out.lines)

    self._checkTensorMetadata(a, out.annotations)

    # Check annotations for the beginning indices of the lines.
    self._checkBeginIndices([0, 0], out.annotations[2])
    self._checkBeginIndices([0, 5], out.annotations[3])
    self._checkBeginIndices([0, 10], out.annotations[4])
    self._checkBeginIndices([0, 15], out.annotations[5])
    self._checkBeginIndices([1, 0], out.annotations[6])
    self._checkBeginIndices([1, 5], out.annotations[7])
    self._checkBeginIndices([1, 10], out.annotations[8])
    self._checkBeginIndices([1, 15], out.annotations[9])
开发者ID:ComeOnGetMe,项目名称:tensorflow,代码行数:34,代码来源:tensor_format_test.py


示例3: testBatchModeWithErrors

  def testBatchModeWithErrors(self):
    a = np.zeros(20)

    out = tensor_format.format_tensor(
        a, "a", np_printoptions={"linewidth": 40})

    self.assertEqual([
        "Tensor \"a\":",
        "",
        "array([ 0.,  0.,  0.,  0.,  0.,  0.,",
        "        0.,  0.,  0.,  0.,  0.,  0.,",
        "        0.,  0.,  0.,  0.,  0.,  0.,",
        "        0.,  0.])",
    ], out.lines)

    with self.assertRaisesRegexp(ValueError, "Dimensions mismatch"):
      tensor_format.locate_tensor_element(out, [[0, 0], [0]])

    with self.assertRaisesRegexp(ValueError,
                                 "Indices exceed tensor dimensions"):
      tensor_format.locate_tensor_element(out, [[0], [20]])

    with self.assertRaisesRegexp(ValueError,
                                 r"Indices contain negative value\(s\)"):
      tensor_format.locate_tensor_element(out, [[0], [-1]])

    with self.assertRaisesRegexp(
        ValueError, "Input indices sets are not in ascending order"):
      tensor_format.locate_tensor_element(out, [[5], [0]])
开发者ID:ComeOnGetMe,项目名称:tensorflow,代码行数:29,代码来源:tensor_format_test.py


示例4: testFormatTensor3DNoEllipsis

  def testFormatTensor3DNoEllipsis(self):  # TODO(cais): Test name.
    a = np.linspace(0.0, 1.0 - 1.0 / 24.0, 24).reshape([2, 3, 4])

    out = tensor_format.format_tensor(a, "a")

    self.assertEqual([
        "Tensor \"a\":",
        "",
        "array([[[ 0.        ,  0.04166667,  0.08333333,  0.125     ],",
        "        [ 0.16666667,  0.20833333,  0.25      ,  0.29166667],",
        "        [ 0.33333333,  0.375     ,  0.41666667,  0.45833333]],",
        "",
        "       [[ 0.5       ,  0.54166667,  0.58333333,  0.625     ],",
        "        [ 0.66666667,  0.70833333,  0.75      ,  0.79166667],",
        "        [ 0.83333333,  0.875     ,  0.91666667,  0.95833333]]])",
    ], out.lines)

    self._checkTensorMetadata(a, out.annotations)

    # Check annotations for beginning indices of the lines.
    self._checkBeginIndices([0, 0, 0], out.annotations[2])
    self._checkBeginIndices([0, 1, 0], out.annotations[3])
    self._checkBeginIndices([0, 2, 0], out.annotations[4])
    self.assertNotIn(5, out.annotations)
    self._checkBeginIndices([1, 0, 0], out.annotations[6])
    self._checkBeginIndices([1, 1, 0], out.annotations[7])
    self._checkBeginIndices([1, 2, 0], out.annotations[8])
开发者ID:ComeOnGetMe,项目名称:tensorflow,代码行数:27,代码来源:tensor_format_test.py


示例5: testLocateTensorElement2DNoEllipsis

  def testLocateTensorElement2DNoEllipsis(self):
    a = np.linspace(0.0, 1.0 - 1.0 / 16.0, 16).reshape([4, 4])

    out = tensor_format.format_tensor(a, "a")

    self.assertEqual([
        "Tensor \"a\":",
        "",
        "array([[ 0.    ,  0.0625,  0.125 ,  0.1875],",
        "       [ 0.25  ,  0.3125,  0.375 ,  0.4375],",
        "       [ 0.5   ,  0.5625,  0.625 ,  0.6875],",
        "       [ 0.75  ,  0.8125,  0.875 ,  0.9375]])",
    ], out.lines)

    is_omitted, row, start_col, end_col = tensor_format.locate_tensor_element(
        out, [0, 0])
    self.assertFalse(is_omitted)
    self.assertEqual(2, row)
    self.assertEqual(9, start_col)
    self.assertEqual(11, end_col)

    is_omitted, row, start_col, end_col = tensor_format.locate_tensor_element(
        out, [0, 3])
    self.assertFalse(is_omitted)
    self.assertEqual(2, row)
    self.assertEqual(36, start_col)
    self.assertEqual(42, end_col)

    is_omitted, row, start_col, end_col = tensor_format.locate_tensor_element(
        out, [1, 0])
    self.assertFalse(is_omitted)
    self.assertEqual(3, row)
    self.assertEqual(9, start_col)
    self.assertEqual(13, end_col)

    is_omitted, row, start_col, end_col = tensor_format.locate_tensor_element(
        out, [1, 3])
    self.assertFalse(is_omitted)
    self.assertEqual(3, row)
    self.assertEqual(36, start_col)
    self.assertEqual(42, end_col)

    is_omitted, row, start_col, end_col = tensor_format.locate_tensor_element(
        out, [3, 3])
    self.assertFalse(is_omitted)
    self.assertEqual(5, row)
    self.assertEqual(36, start_col)
    self.assertEqual(42, end_col)

    with self.assertRaisesRegexp(
        ValueError, "Indices exceed tensor dimensions"):
      tensor_format.locate_tensor_element(out, [1, 4])

    with self.assertRaisesRegexp(
        ValueError, "Indices contain negative"):
      tensor_format.locate_tensor_element(out, [-1, 2])

    with self.assertRaisesRegexp(
        ValueError, "Dimensions mismatch"):
      tensor_format.locate_tensor_element(out, [0])
开发者ID:ComeOnGetMe,项目名称:tensorflow,代码行数:60,代码来源:tensor_format_test.py


示例6: testFormatTensor3DNoEllipsisWithArgwhereHighlightWithMatches

  def testFormatTensor3DNoEllipsisWithArgwhereHighlightWithMatches(self):
    a = np.linspace(0.0, 1.0 - 1.0 / 24.0, 24).reshape([2, 3, 4])

    lower_bound = 0.26
    upper_bound = 0.5

    def highlight_filter(x):
      return np.logical_and(x > lower_bound, x < upper_bound)

    highlight_options = tensor_format.HighlightOptions(
        highlight_filter, description="between 0.26 and 0.5")
    out = tensor_format.format_tensor(
        a, "a", highlight_options=highlight_options)

    cli_test_utils.assert_lines_equal_ignoring_whitespace(
        self,
        ["Tensor \"a\": "
         "Highlighted(between 0.26 and 0.5): 5 of 24 element(s) (20.83%)",
         ""],
        out.lines[:2])
    self.assertEqual(repr(a).split("\n"), out.lines[2:])

    self._checkTensorMetadata(a, out.annotations)

    # Check annotations for beginning indices of the lines.
    self._checkBeginIndicesAnnotations(out, a)

    self.assertAllClose(
        [0.29166667, 0.33333333, 0.375, 0.41666667, 0.45833333],
        self._extractBoldNumbers(out, 2))
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:30,代码来源:tensor_format_test.py


示例7: testLocateTensorElement2DNoEllipsisWithNumericSummary

  def testLocateTensorElement2DNoEllipsisWithNumericSummary(self):
    a = np.linspace(0.0, 1.0 - 1.0 / 16.0, 16).reshape([4, 4])

    out = tensor_format.format_tensor(a, "a", include_numeric_summary=True)

    cli_test_utils.assert_lines_equal_ignoring_whitespace(
        self,
        ["Tensor \"a\":",
         "",
         "Numeric summary:",
         "|  0  + | total |",
         "|  1 15 |    16 |",
         "|           min           max          mean           std |"],
        out.lines[:6])
    cli_test_utils.assert_array_lines_close(
        self, [0.0, 0.9375, 0.46875, 0.28811076429], out.lines[6:7])
    cli_test_utils.assert_array_lines_close(self, a, out.lines[8:])

    self._checkTensorElementLocations(out, a)

    with self.assertRaisesRegexp(
        ValueError, "Indices exceed tensor dimensions"):
      tensor_format.locate_tensor_element(out, [1, 4])

    with self.assertRaisesRegexp(
        ValueError, "Indices contain negative"):
      tensor_format.locate_tensor_element(out, [-1, 2])

    with self.assertRaisesRegexp(
        ValueError, "Dimensions mismatch"):
      tensor_format.locate_tensor_element(out, [0])
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:31,代码来源:tensor_format_test.py


示例8: print_tensor

  def print_tensor(self, args, screen_info=None):
    """Command handler for print_tensor.

    Print value of a given dumped tensor.

    Args:
      args: Command-line arguments, excluding the command prefix, as a list of
        str.
      screen_info: Optional dict input containing screen information such as
        cols.

    Returns:
      Output text lines as a RichTextLines object.
    """

    if screen_info and "cols" in screen_info:
      np_printoptions = {"linewidth": screen_info["cols"]}
    else:
      np_printoptions = {}

    parsed = self._arg_parsers["print_tensor"].parse_args(args)

    node_name, output_slot = debug_data.parse_node_or_tensor_name(
        parsed.tensor_name)
    if output_slot is None:
      return self._error("\"%s\" is not a valid tensor name" %
                         parsed.tensor_name)

    if not self._debug_dump.node_exists(node_name):
      return self._error(
          "Node \"%s\" does not exist in partition graphs" % node_name)

    watch_keys = self._debug_dump.debug_watch_keys(node_name)

    # Find debug dump data that match the tensor name (node name + output
    # slot).
    matching_data = []
    for watch_key in watch_keys:
      debug_tensor_data = self._debug_dump.watch_key_to_data(watch_key)
      for datum in debug_tensor_data:
        if datum.output_slot == output_slot:
          matching_data.append(datum)

    if not matching_data:
      return self._error(
          "Tensor \"%s\" did not generate any dumps." % parsed.tensor_name)

    # TODO(cais): In the case of multiple dumps from the same tensor, require
    #   explicit specification of the DebugOp and the temporal order.
    if len(matching_data) > 1:
      return self._error(
          "print_tensor logic for multiple dumped records has not been "
          "implemented.")

    return tensor_format.format_tensor(
        matching_data[0].get_tensor(),
        matching_data[0].watch_key,
        include_metadata=True,
        np_printoptions=np_printoptions)
开发者ID:KalraA,项目名称:tensorflow,代码行数:59,代码来源:analyzer_cli.py


示例9: testFormatTensorSuppressingTensorName

  def testFormatTensorSuppressingTensorName(self):
    a = np.linspace(0.0, 1.0 - 1.0 / 16.0, 16).reshape([4, 4])

    out = tensor_format.format_tensor(a, None)
    self.assertEqual(repr(a).split("\n"), out.lines)

    self._checkTensorMetadata(a, out.annotations)
    self._checkBeginIndicesAnnotations(out, a)
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:8,代码来源:tensor_format_test.py


示例10: testLocateTensorElementAnnotationsUnavailable

  def testLocateTensorElementAnnotationsUnavailable(self):
    out = tensor_format.format_tensor(None, "a")

    self.assertEqual(["Tensor \"a\":", "", "Uninitialized tensor"], out.lines)

    with self.assertRaisesRegexp(
        AttributeError, "tensor_metadata is not available in annotations"):
      tensor_format.locate_tensor_element(out, [0])
开发者ID:ComeOnGetMe,项目名称:tensorflow,代码行数:8,代码来源:tensor_format_test.py


示例11: testFormatZeroDimensionTensor

  def testFormatZeroDimensionTensor(self):
    a = np.array(42.0, dtype=np.float32)

    out = tensor_format.format_tensor(a, "a")

    self.assertEqual(["Tensor \"a\":", "", "array(42.0, dtype=float32)"],
                     out.lines)
    self._checkTensorMetadata(a, out.annotations)
开发者ID:ComeOnGetMe,项目名称:tensorflow,代码行数:8,代码来源:tensor_format_test.py


示例12: testFormatTensorWithEllipses

  def testFormatTensorWithEllipses(self):
    a = np.zeros([11, 11, 11])

    out = tensor_format.format_tensor(
        a, "a", False, np_printoptions={"threshold": 100, "edgeitems": 2})

    self.assertEqual([
        "Tensor \"a\":",
        "",
        "array([[[ 0.,  0., ...,  0.,  0.],",
        "        [ 0.,  0., ...,  0.,  0.],",
        "        ..., ",
        "        [ 0.,  0., ...,  0.,  0.],",
        "        [ 0.,  0., ...,  0.,  0.]],",
        "",
        "       [[ 0.,  0., ...,  0.,  0.],",
        "        [ 0.,  0., ...,  0.,  0.],",
        "        ..., ",
        "        [ 0.,  0., ...,  0.,  0.],",
        "        [ 0.,  0., ...,  0.,  0.]],",
        "",
        "       ..., ",
        "       [[ 0.,  0., ...,  0.,  0.],",
        "        [ 0.,  0., ...,  0.,  0.],",
        "        ..., ",
        "        [ 0.,  0., ...,  0.,  0.],",
        "        [ 0.,  0., ...,  0.,  0.]],",
        "",
        "       [[ 0.,  0., ...,  0.,  0.],",
        "        [ 0.,  0., ...,  0.,  0.],",
        "        ..., ",
        "        [ 0.,  0., ...,  0.,  0.],",
        "        [ 0.,  0., ...,  0.,  0.]]])",
    ], out.lines)

    self._checkTensorMetadata(a, out.annotations)

    # Check annotations for beginning indices of the lines.
    for i in xrange(2):
      self._checkBeginIndices([i, 0, 0], out.annotations[i * 6 + 2])
      self._checkBeginIndices([i, 1, 0], out.annotations[i * 6 + 3])
      self._checkOmittedIndices([i, 2, 0], out.annotations[i * 6 + 4])
      self._checkBeginIndices([i, 9, 0], out.annotations[i * 6 + 5])
      self._checkBeginIndices([i, 10, 0], out.annotations[i * 6 + 6])
      self.assertNotIn(i * 6 + 7, out.annotations)

    p = 15
    for i in xrange(2):
      self._checkBeginIndices([9 + i, 0, 0], out.annotations[p + i * 6])
      self._checkBeginIndices([9 + i, 1, 0], out.annotations[p + i * 6 + 1])
      self._checkOmittedIndices(
          [9 + i, 2, 0], out.annotations[p + i * 6 + 2])
      self._checkBeginIndices([9 + i, 9, 0], out.annotations[p + i * 6 + 3])
      self._checkBeginIndices([9 + i, 10, 0], out.annotations[p + i * 6 + 4])

      if i < 1:
        self.assertNotIn(p + i * 6 + 5, out.annotations)
开发者ID:ComeOnGetMe,项目名称:tensorflow,代码行数:57,代码来源:tensor_format_test.py


示例13: testLocateTensorElement1DTinyAndNanValues

  def testLocateTensorElement1DTinyAndNanValues(self):
    a = np.ones([3, 3]) * 1e-8
    a[1, 0] = np.nan
    a[1, 2] = np.inf

    out = tensor_format.format_tensor(
        a, "a", np_printoptions={"linewidth": 100})

    self.assertEqual([
        "Tensor \"a\":",
        "",
        "array([[  1.00000000e-08,   1.00000000e-08,   1.00000000e-08],",
        "       [             nan,   1.00000000e-08,              inf],",
        "       [  1.00000000e-08,   1.00000000e-08,   1.00000000e-08]])",
    ], out.lines)

    is_omitted, row, start_col, end_col = tensor_format.locate_tensor_element(
        out, [0, 0])
    self.assertFalse(is_omitted)
    self.assertEqual(2, row)
    self.assertEqual(10, start_col)
    self.assertEqual(24, end_col)

    is_omitted, row, start_col, end_col = tensor_format.locate_tensor_element(
        out, [0, 2])
    self.assertFalse(is_omitted)
    self.assertEqual(2, row)
    self.assertEqual(46, start_col)
    self.assertEqual(60, end_col)

    is_omitted, row, start_col, end_col = tensor_format.locate_tensor_element(
        out, [1, 0])
    self.assertFalse(is_omitted)
    self.assertEqual(3, row)
    self.assertEqual(21, start_col)
    self.assertEqual(24, end_col)

    is_omitted, row, start_col, end_col = tensor_format.locate_tensor_element(
        out, [1, 1])
    self.assertFalse(is_omitted)
    self.assertEqual(3, row)
    self.assertEqual(28, start_col)
    self.assertEqual(42, end_col)

    is_omitted, row, start_col, end_col = tensor_format.locate_tensor_element(
        out, [1, 2])
    self.assertFalse(is_omitted)
    self.assertEqual(3, row)
    self.assertEqual(57, start_col)
    self.assertEqual(60, end_col)

    is_omitted, row, start_col, end_col = tensor_format.locate_tensor_element(
        out, [2, 2])
    self.assertFalse(is_omitted)
    self.assertEqual(4, row)
    self.assertEqual(46, start_col)
    self.assertEqual(60, end_col)
开发者ID:ComeOnGetMe,项目名称:tensorflow,代码行数:57,代码来源:tensor_format_test.py


示例14: testFormatZeroDimensionTensor

  def testFormatZeroDimensionTensor(self):
    a = np.array(42, dtype=np.int32)

    out = tensor_format.format_tensor(a, "a")

    cli_test_utils.assert_lines_equal_ignoring_whitespace(
        self, ["Tensor \"a\":", ""], out.lines[:2])
    self.assertTrue(out.lines[2].startswith("array(42"))
    self._checkTensorMetadata(a, out.annotations)
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:9,代码来源:tensor_format_test.py


示例15: testFormatTensorHighlightsTensorNameWithDebugOp

 def testFormatTensorHighlightsTensorNameWithDebugOp(self):
   tensor_name = "a_tensor:0"
   debug_op = "DebugIdentity"
   a = np.zeros(2)
   out = tensor_format.format_tensor(
       a, "%s:%s" % (tensor_name, debug_op), np_printoptions={"linewidth": 40})
   self.assertEqual([(8, 8 + len(tensor_name), "bold"),
                     (8 + len(tensor_name) + 1,
                      8 + len(tensor_name) + 1 + len(debug_op), "yellow")],
                    out.font_attr_segs[0])
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:10,代码来源:tensor_format_test.py


示例16: testFormatResourceTypeTensor

  def testFormatResourceTypeTensor(self):
    tensor_proto = tensor_pb2.TensorProto(
        dtype=types_pb2.DataType.Value("DT_RESOURCE"),
        tensor_shape=tensor_shape_pb2.TensorShapeProto(
            dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)]))
    out = tensor_format.format_tensor(
        debug_data.InconvertibleTensorProto(tensor_proto), "a")

    self.assertEqual(["Tensor \"a\":", ""], out.lines[:2])
    self.assertEqual(str(tensor_proto).split("\n"), out.lines[2:])
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:10,代码来源:tensor_format_test.py


示例17: _format_tensor

    def _format_tensor(self,
                       tensor,
                       watch_key,
                       np_printoptions,
                       print_all=False,
                       tensor_slicing=None,
                       highlight_options=None):
        """Generate formatted str to represent a tensor or its slices.

    Args:
      tensor: (numpy ndarray) The tensor value.
      watch_key: (str) Tensor debug watch key.
      np_printoptions: (dict) Numpy tensor formatting options.
      print_all: (bool) Whether the tensor is to be displayed in its entirety,
        instead of printing ellipses, even if its number of elements exceeds
        the default numpy display threshold.
        (Note: Even if this is set to true, the screen output can still be cut
         off by the UI frontend if it consist of more lines than the frontend
         can handle.)
      tensor_slicing: (str or None) Slicing of the tensor, e.g., "[:, 1]". If
        None, no slicing will be performed on the tensor.
      highlight_options: (tensor_format.HighlightOptions) options to highlight
        elements of the tensor. See the doc of tensor_format.format_tensor()
        for more details.

    Returns:
      (str) Formatted str representing the (potentially sliced) tensor.

    Raises:
      ValueError: If tehsor_slicing is not a valid numpy ndarray slicing str.
    """

        if tensor_slicing:
            # Validate the indexing.
            if not command_parser.validate_slicing_string(tensor_slicing):
                raise ValueError("Invalid tensor-slicing string.")

            value = eval("tensor" + tensor_slicing)  # pylint: disable=eval-used
            sliced_name = watch_key + tensor_slicing
        else:
            value = tensor
            sliced_name = watch_key

        if print_all:
            np_printoptions["threshold"] = value.size
        else:
            np_printoptions[
                "threshold"] = self.default_ndarray_display_threshold

        return tensor_format.format_tensor(
            value,
            sliced_name,
            include_metadata=True,
            np_printoptions=np_printoptions,
            highlight_options=highlight_options)
开发者ID:ppwwyyxx,项目名称:tensorflow,代码行数:55,代码来源:analyzer_cli.py


示例18: testFormatUninitializedTensor

  def testFormatUninitializedTensor(self):
    tensor_proto = tensor_pb2.TensorProto(
        dtype=types_pb2.DataType.Value("DT_FLOAT"),
        tensor_shape=tensor_shape_pb2.TensorShapeProto(
            dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)]))
    out = tensor_format.format_tensor(
        debug_data.InconvertibleTensorProto(tensor_proto, False), "a")

    self.assertEqual(["Tensor \"a\":", "", "Uninitialized tensor:"],
                     out.lines[:3])
    self.assertEqual(str(tensor_proto).split("\n"), out.lines[3:])
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:11,代码来源:tensor_format_test.py


示例19: testLocateTensorElement1DNoEllipsisBatchMode

  def testLocateTensorElement1DNoEllipsisBatchMode(self):
    a = np.zeros(20)

    out = tensor_format.format_tensor(
        a, "a", np_printoptions={"linewidth": 40})

    cli_test_utils.assert_lines_equal_ignoring_whitespace(
        self, ["Tensor \"a\":", ""], out.lines[:2])
    self.assertEqual(repr(a).split("\n"), out.lines[2:])

    self._checkTensorElementLocations(out, a)
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:11,代码来源:tensor_format_test.py


示例20: testFormatTensor3DNoEllipsis

  def testFormatTensor3DNoEllipsis(self):
    a = np.linspace(0.0, 1.0 - 1.0 / 24.0, 24).reshape([2, 3, 4])

    out = tensor_format.format_tensor(a, "a")

    cli_test_utils.assert_lines_equal_ignoring_whitespace(
        self, ["Tensor \"a\":", ""], out.lines[:2])
    self.assertEqual(repr(a).split("\n"), out.lines[2:])

    self._checkTensorMetadata(a, out.annotations)
    self._checkBeginIndicesAnnotations(out, a)
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:11,代码来源:tensor_format_test.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python debug_utils.watch_graph函数代码示例发布时间:2022-05-27
下一篇:
Python debugger_cli_common.wrap_rich_text_lines函数代码示例发布时间: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