本文整理汇总了Python中tensorflow.python.ops.logging_ops.print_v2函数的典型用法代码示例。如果您正苦于以下问题:Python print_v2函数的具体用法?Python print_v2怎么用?Python print_v2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_v2函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testPrintOneTensorEagerOnOpCreate
def testPrintOneTensorEagerOnOpCreate(self):
with self.cached_session():
with context.eager_mode():
tensor = math_ops.range(10)
expected = "[0 1 2 ... 7 8 9]"
with self.captureWritesToStream(sys.stderr) as printed:
logging_ops.print_v2(tensor)
self.assertTrue((expected + "\n") in printed.contents())
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:8,代码来源:logging_ops_test.py
示例2: testInvalidOutputStreamRaisesError
def testInvalidOutputStreamRaisesError(self):
with self.cached_session():
tensor = math_ops.range(10)
with self.assertRaises(ValueError):
print_op = logging_ops.print_v2(
tensor, output_stream="unknown")
self.evaluate(print_op)
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:7,代码来源:logging_ops_test.py
示例3: testPrintNoTensors
def testPrintNoTensors(self):
with self.cached_session():
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(23, [23, 5], {"6": 12})
self.evaluate(print_op)
expected = "23 [23, 5] {'6': 12}"
self.assertTrue((expected + "\n") in printed.contents())
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:7,代码来源:logging_ops_test.py
示例4: testPrintStringScalar
def testPrintStringScalar(self):
with self.cached_session():
tensor = ops.convert_to_tensor("scalar")
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor)
self.evaluate(print_op)
expected = "scalar"
self.assertTrue((expected + "\n") in printed.contents())
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:8,代码来源:logging_ops_test.py
示例5: testPrintTwoTensors
def testPrintTwoTensors(self):
with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor, tensor * 10)
self.evaluate(print_op)
expected = "[0 1 2 ... 7 8 9] [0 10 20 ... 70 80 90]"
self.assertTrue((expected + "\n") in printed.contents())
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:8,代码来源:logging_ops_test.py
示例6: testPrintPlaceholderGeneration
def testPrintPlaceholderGeneration(self):
with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2("{}6", {"{}": tensor * 10})
self.evaluate(print_op)
expected = "{}6 {'{}': [0 10 20 ... 70 80 90]}"
self.assertTrue((expected + "\n") in printed.contents())
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:8,代码来源:logging_ops_test.py
示例7: testPrintStringScalarDifferentEnd
def testPrintStringScalarDifferentEnd(self):
with self.cached_session():
tensor = ops.convert_to_tensor("scalar")
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor, end="<customend>")
self.evaluate(print_op)
expected = "scalar<customend>"
self.assertIn(expected, printed.contents())
开发者ID:aritratony,项目名称:tensorflow,代码行数:8,代码来源:logging_ops_test.py
示例8: testPrintTwoTensorsDifferentSep
def testPrintTwoTensorsDifferentSep(self):
with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor, tensor * 10, sep="<separator>")
self.evaluate(print_op)
expected = "[0 1 2 ... 7 8 9]<separator>[0 10 20 ... 70 80 90]"
self.assertIn(expected + "\n", printed.contents())
开发者ID:aritratony,项目名称:tensorflow,代码行数:8,代码来源:logging_ops_test.py
示例9: testPrintOneTensorStdout
def testPrintOneTensorStdout(self):
with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stdout) as printed:
print_op = logging_ops.print_v2(
tensor, output_stream=sys.stdout)
self.evaluate(print_op)
expected = "[0 1 2 ... 7 8 9]"
self.assertTrue((expected + "\n") in printed.contents())
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:9,代码来源:logging_ops_test.py
示例10: testPrintOneStringTensor
def testPrintOneStringTensor(self):
with self.cached_session():
tensor = ops.convert_to_tensor([char for char in string.ascii_lowercase])
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor)
self.evaluate(print_op)
expected = "[\"a\" \"b\" \"c\" ... \"x\" \"y\" \"z\"]"
self.assertIn((expected + "\n"), printed.contents())
开发者ID:aritratony,项目名称:tensorflow,代码行数:9,代码来源:logging_ops_test.py
示例11: testPrintOneVariable
def testPrintOneVariable(self):
with self.cached_session():
var = variables.Variable(math_ops.range(10))
if not context.executing_eagerly():
variables.global_variables_initializer().run()
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(var)
self.evaluate(print_op)
expected = "[0 1 2 ... 7 8 9]"
self.assertTrue((expected + "\n") in printed.contents())
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:10,代码来源:logging_ops_test.py
示例12: testNoDuplicateFormatOpGraphModeAfterExplicitFormat
def testNoDuplicateFormatOpGraphModeAfterExplicitFormat(self):
with self.cached_session():
tensor = math_ops.range(10)
formatted_string = string_ops.string_format("{}", tensor)
print_op = logging_ops.print_v2(formatted_string)
self.evaluate(print_op)
graph_ops = ops.get_default_graph().get_operations()
format_ops = [op for op in graph_ops if op.type == "StringFormat"]
# Should be only 1 format_op for graph mode.
self.assertEqual(len(format_ops), 1)
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:10,代码来源:logging_ops_test.py
示例13: testPrintOneTensorLogError
def testPrintOneTensorLogError(self):
with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(
tensor, output_stream=tf_logging.error)
self.evaluate(print_op)
self.assertTrue("E" in printed.contents())
expected = "[0 1 2 ... 7 8 9]"
self.assertTrue(expected in printed.contents())
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:10,代码来源:logging_ops_logging_level_test.py
示例14: testPrintTensorsToFile
def testPrintTensorsToFile(self):
tmpfile_name = tempfile.mktemp(".printv2_test")
tensor_0 = math_ops.range(0, 10)
print_op_0 = logging_ops.print_v2(tensor_0,
output_stream="file://"+tmpfile_name)
self.evaluate(print_op_0)
tensor_1 = math_ops.range(11, 20)
print_op_1 = logging_ops.print_v2(tensor_1,
output_stream="file://"+tmpfile_name)
self.evaluate(print_op_1)
try:
f = open(tmpfile_name, "r")
line_0 = f.readline()
expected_0 = "[0 1 2 ... 7 8 9]"
self.assertTrue(expected_0 in line_0)
line_1 = f.readline()
expected_1 = "[11 12 13 ... 17 18 19]"
self.assertTrue(expected_1 in line_1)
f.close()
os.remove(tmpfile_name)
except IOError as e:
self.fail(e)
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:22,代码来源:logging_ops_test.py
示例15: testPrintTwoVariablesInStructWithAssignAdd
def testPrintTwoVariablesInStructWithAssignAdd(self):
with self.cached_session():
var_one = variables.Variable(2.14)
plus_one = var_one.assign_add(1.0)
var_two = variables.Variable(math_ops.range(10))
if not context.executing_eagerly():
variables.global_variables_initializer().run()
with self.captureWritesToStream(sys.stderr) as printed:
self.evaluate(plus_one)
print_op = logging_ops.print_v2(var_one, {"second": var_two})
self.evaluate(print_op)
expected = "3.14 {'second': [0 1 2 ... 7 8 9]}"
self.assertTrue((expected + "\n") in printed.contents())
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:13,代码来源:logging_ops_test.py
示例16: testPrintOneTensorVarySummarize
def testPrintOneTensorVarySummarize(self):
with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor, summarize=1)
self.evaluate(print_op)
expected = "[0 ... 9]"
self.assertTrue((expected + "\n") in printed.contents())
with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor, summarize=2)
self.evaluate(print_op)
expected = "[0 1 ... 8 9]"
self.assertTrue((expected + "\n") in printed.contents())
with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor, summarize=3)
self.evaluate(print_op)
expected = "[0 1 2 ... 7 8 9]"
self.assertTrue((expected + "\n") in printed.contents())
with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor, summarize=-1)
self.evaluate(print_op)
expected = "[0 1 2 3 4 5 6 7 8 9]"
self.assertTrue((expected + "\n") in printed.contents())
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:36,代码来源:logging_ops_test.py
示例17: testPrintComplexTensorStruct
def testPrintComplexTensorStruct(self):
with self.cached_session():
tensor = math_ops.range(10)
small_tensor = constant_op.constant([0.3, 12.4, -16.1])
big_tensor = math_ops.mul(tensor, 10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(
"first:", tensor, "middle:",
{"small": small_tensor, "Big": big_tensor}, 10,
[tensor * 2, tensor])
self.evaluate(print_op)
# Note that the keys in the dict will always be sorted,
# so 'Big' comes before 'small'
expected = ("first: [0 1 2 ... 7 8 9] "
"middle: {'Big': [0 10 20 ... 70 80 90], "
"'small': [0.3 12.4 -16.1]} "
"10 [[0 2 4 ... 14 16 18], [0 1 2 ... 7 8 9]]")
self.assertTrue((expected + "\n") in printed.contents())
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:18,代码来源:logging_ops_test.py
示例18: _print_tensor
def _print_tensor(op_name, output_idx, num_elements, tensor, output_tensor):
"""Prints a tensor value to a file.
Args:
op_name: the name of the Op that outputs the tensor to be printed.
output_idx: which output of the Op it is (0 means the first output).
num_elements: number of elements to print.
tensor: the tensor needs to be returned.
output_tensor: the tensor needs to be printed.
Returns:
The same tensor passed via the "tensor" argument.
"""
msg = '"%s:%d" '%(op_name, output_idx)
output_stream = _OUTPUT_STREAM_ESCAPE + self._trace_file_path
print_op = logging_ops.print_v2(msg, array_ops.shape(output_tensor),
' @', self._replica_id,
'\n', output_tensor,
summarize=num_elements,
output_stream=output_stream)
with ops.control_dependencies([print_op]):
return array_ops.identity(tensor).op
开发者ID:Ajaycs99,项目名称:tensorflow,代码行数:22,代码来源:tensor_tracer.py
示例19: testPrintSparseTensorInDataStruct
def testPrintSparseTensorInDataStruct(self):
with self.cached_session():
ind = [[0, 0], [1, 0], [1, 3], [4, 1], [1, 4], [3, 2], [3, 3]]
val = [0, 10, 13, 4, 14, 32, 33]
shape = [5, 6]
sparse = sparse_tensor.SparseTensor(
constant_op.constant(ind, dtypes.int64),
constant_op.constant(val, dtypes.int64),
constant_op.constant(shape, dtypes.int64))
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2([sparse])
self.evaluate(print_op)
expected = ("['SparseTensor(indices=[[0 0]\n"
" [1 0]\n"
" [1 3]\n"
" ...\n"
" [1 4]\n"
" [3 2]\n"
" [3 3]], values=[0 10 13 ... 14 32 33], shape=[5 6])']")
self.assertTrue((expected + "\n") in printed.contents())
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:22,代码来源:logging_ops_test.py
示例20: _print_tensor
def _print_tensor(tensor_name, num_elements, tensor, output_tensor):
"""Prints a tensor value to a file.
Args:
tensor_name: name of the tensor being traced.
num_elements: number of elements to print (-1 means print all).
tensor: the tensor needs to be returned.
output_tensor: the tensor needs to be printed.
Returns:
The same tensor passed via the "tensor" argument.
Raises:
ValueError: If tensor_name is not already in
self._tensorname_idx_map.
"""
if self._submode == _SUBMODE_BRIEF:
if tensor_name not in self._tensorname_idx_map:
raise ValueError(
'Tensor name %s is not in the tensorname_idx_map'%tensor_name)
msg = '%d'%self._tensorname_idx_map[tensor_name]
else:
msg = '"%s"'%tensor_name
if self._trace_file_path:
output_stream = _OUTPUT_STREAM_ESCAPE + self._trace_file_path
else:
output_stream = sys.stderr
print_op = logging_ops.print_v2(msg, array_ops.shape(output_tensor),
'@', self._replica_id,
'\n', output_tensor, '\n',
summarize=num_elements,
output_stream=output_stream)
with ops.control_dependencies([print_op]):
return array_ops.identity(tensor).op
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:36,代码来源:tensor_tracer.py
注:本文中的tensorflow.python.ops.logging_ops.print_v2函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论