本文整理汇总了Python中tensorflow.python.ops.logging_ops.print_v2函数的典型用法代码示例。如果您正苦于以下问题:Python print_v2函数的具体用法?Python print_v2怎么用?Python print_v2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_v2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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())
示例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)
示例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())
示例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())
示例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())
示例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())
示例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())
示例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())
示例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())
示例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())
示例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())
示例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)
示例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())
示例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)
示例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())