Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/ops/gen_logging_ops.py: 11%

514 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-03 07:57 +0000

1"""Python wrappers around TensorFlow ops. 

2 

3This file is MACHINE GENERATED! Do not edit. 

4""" 

5 

6import collections 

7 

8from tensorflow.python import pywrap_tfe as pywrap_tfe 

9from tensorflow.python.eager import context as _context 

10from tensorflow.python.eager import core as _core 

11from tensorflow.python.eager import execute as _execute 

12from tensorflow.python.framework import dtypes as _dtypes 

13from tensorflow.security.fuzzing.py import annotation_types as _atypes 

14 

15from tensorflow.python.framework import op_def_registry as _op_def_registry 

16from tensorflow.python.framework import ops as _ops 

17from tensorflow.python.framework import op_def_library as _op_def_library 

18from tensorflow.python.util.deprecation import deprecated_endpoints 

19from tensorflow.python.util import dispatch as _dispatch 

20from tensorflow.python.util.tf_export import tf_export 

21 

22from typing import TypeVar 

23 

24def _assert(condition, data, summarize=3, name=None): 

25 r"""Asserts that the given condition is true. 

26 

27 If `condition` evaluates to false, print the list of tensors in `data`. 

28 `summarize` determines how many entries of the tensors to print. 

29 

30 Args: 

31 condition: A `Tensor` of type `bool`. The condition to evaluate. 

32 data: A list of `Tensor` objects. 

33 The tensors to print out when condition is false. 

34 summarize: An optional `int`. Defaults to `3`. 

35 Print this many entries of each tensor. 

36 name: A name for the operation (optional). 

37 

38 Returns: 

39 The created Operation. 

40 """ 

41 _ctx = _context._context or _context.context() 

42 tld = _ctx._thread_local_data 

43 if tld.is_eager: 

44 try: 

45 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

46 _ctx, "Assert", name, condition, data, "summarize", summarize) 

47 return _result 

48 except _core._NotOkStatusException as e: 

49 _ops.raise_from_not_ok_status(e, name) 

50 except _core._FallbackException: 

51 pass 

52 try: 

53 return _assert_eager_fallback( 

54 condition, data, summarize=summarize, name=name, ctx=_ctx) 

55 except _core._SymbolicException: 

56 pass # Add nodes to the TensorFlow graph. 

57 # Add nodes to the TensorFlow graph. 

58 if summarize is None: 

59 summarize = 3 

60 summarize = _execute.make_int(summarize, "summarize") 

61 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

62 "Assert", condition=condition, data=data, summarize=summarize, 

63 name=name) 

64 return _op 

65Assert = tf_export("raw_ops.Assert")(_ops.to_raw_op(_assert)) 

66 

67 

68def _assert_eager_fallback(condition, data, summarize, name, ctx): 

69 if summarize is None: 

70 summarize = 3 

71 summarize = _execute.make_int(summarize, "summarize") 

72 _attr_T, data = _execute.convert_to_mixed_eager_tensors(data, ctx) 

73 condition = _ops.convert_to_tensor(condition, _dtypes.bool) 

74 _inputs_flat = [condition] + list(data) 

75 _attrs = ("T", _attr_T, "summarize", summarize) 

76 _result = _execute.execute(b"Assert", 0, inputs=_inputs_flat, attrs=_attrs, 

77 ctx=ctx, name=name) 

78 _result = None 

79 return _result 

80 

81 

82def audio_summary(tag, tensor, sample_rate, max_outputs=3, name=None): 

83 r"""Outputs a `Summary` protocol buffer with audio. 

84 

85 The summary has up to `max_outputs` summary values containing audio. The 

86 audio is built from `tensor` which must be 3-D with shape `[batch_size, 

87 frames, channels]` or 2-D with shape `[batch_size, frames]`. The values are 

88 assumed to be in the range of `[-1.0, 1.0]` with a sample rate of `sample_rate`. 

89 

90 The `tag` argument is a scalar `Tensor` of type `string`. It is used to 

91 build the `tag` of the summary values: 

92 

93 * If `max_outputs` is 1, the summary value tag is '*tag*/audio'. 

94 * If `max_outputs` is greater than 1, the summary value tags are 

95 generated sequentially as '*tag*/audio/0', '*tag*/audio/1', etc. 

96 

97 Args: 

98 tag: A `Tensor` of type `string`. 

99 Scalar. Used to build the `tag` attribute of the summary values. 

100 tensor: A `Tensor` of type `float32`. 2-D of shape `[batch_size, frames]`. 

101 sample_rate: A `float`. The sample rate of the signal in hertz. 

102 max_outputs: An optional `int` that is `>= 1`. Defaults to `3`. 

103 Max number of batch elements to generate audio for. 

104 name: A name for the operation (optional). 

105 

106 Returns: 

107 A `Tensor` of type `string`. 

108 """ 

109 _ctx = _context._context or _context.context() 

110 tld = _ctx._thread_local_data 

111 if tld.is_eager: 

112 try: 

113 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

114 _ctx, "AudioSummary", name, tag, tensor, "sample_rate", sample_rate, 

115 "max_outputs", max_outputs) 

116 return _result 

117 except _core._NotOkStatusException as e: 

118 _ops.raise_from_not_ok_status(e, name) 

119 except _core._FallbackException: 

120 pass 

121 try: 

122 return audio_summary_eager_fallback( 

123 tag, tensor, sample_rate=sample_rate, max_outputs=max_outputs, 

124 name=name, ctx=_ctx) 

125 except _core._SymbolicException: 

126 pass # Add nodes to the TensorFlow graph. 

127 # Add nodes to the TensorFlow graph. 

128 sample_rate = _execute.make_float(sample_rate, "sample_rate") 

129 if max_outputs is None: 

130 max_outputs = 3 

131 max_outputs = _execute.make_int(max_outputs, "max_outputs") 

132 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

133 "AudioSummary", tag=tag, tensor=tensor, sample_rate=sample_rate, 

134 max_outputs=max_outputs, name=name) 

135 _result = _outputs[:] 

136 if _execute.must_record_gradient(): 

137 _attrs = ("sample_rate", _op.get_attr("sample_rate"), "max_outputs", 

138 _op._get_attr_int("max_outputs")) 

139 _inputs_flat = _op.inputs 

140 _execute.record_gradient( 

141 "AudioSummary", _inputs_flat, _attrs, _result) 

142 _result, = _result 

143 return _result 

144 

145AudioSummary = tf_export("raw_ops.AudioSummary")(_ops.to_raw_op(audio_summary)) 

146 

147 

148def audio_summary_eager_fallback(tag, tensor, sample_rate, max_outputs, name, ctx): 

149 sample_rate = _execute.make_float(sample_rate, "sample_rate") 

150 if max_outputs is None: 

151 max_outputs = 3 

152 max_outputs = _execute.make_int(max_outputs, "max_outputs") 

153 tag = _ops.convert_to_tensor(tag, _dtypes.string) 

154 tensor = _ops.convert_to_tensor(tensor, _dtypes.float32) 

155 _inputs_flat = [tag, tensor] 

156 _attrs = ("sample_rate", sample_rate, "max_outputs", max_outputs) 

157 _result = _execute.execute(b"AudioSummary", 1, inputs=_inputs_flat, 

158 attrs=_attrs, ctx=ctx, name=name) 

159 if _execute.must_record_gradient(): 

160 _execute.record_gradient( 

161 "AudioSummary", _inputs_flat, _attrs, _result) 

162 _result, = _result 

163 return _result 

164 

165 

166def audio_summary_v2(tag, tensor, sample_rate, max_outputs=3, name=None): 

167 r"""Outputs a `Summary` protocol buffer with audio. 

168 

169 The summary has up to `max_outputs` summary values containing audio. The 

170 audio is built from `tensor` which must be 3-D with shape `[batch_size, 

171 frames, channels]` or 2-D with shape `[batch_size, frames]`. The values are 

172 assumed to be in the range of `[-1.0, 1.0]` with a sample rate of `sample_rate`. 

173 

174 The `tag` argument is a scalar `Tensor` of type `string`. It is used to 

175 build the `tag` of the summary values: 

176 

177 * If `max_outputs` is 1, the summary value tag is '*tag*/audio'. 

178 * If `max_outputs` is greater than 1, the summary value tags are 

179 generated sequentially as '*tag*/audio/0', '*tag*/audio/1', etc. 

180 

181 Args: 

182 tag: A `Tensor` of type `string`. 

183 Scalar. Used to build the `tag` attribute of the summary values. 

184 tensor: A `Tensor` of type `float32`. 2-D of shape `[batch_size, frames]`. 

185 sample_rate: A `Tensor` of type `float32`. 

186 The sample rate of the signal in hertz. 

187 max_outputs: An optional `int` that is `>= 1`. Defaults to `3`. 

188 Max number of batch elements to generate audio for. 

189 name: A name for the operation (optional). 

190 

191 Returns: 

192 A `Tensor` of type `string`. 

193 """ 

194 _ctx = _context._context or _context.context() 

195 tld = _ctx._thread_local_data 

196 if tld.is_eager: 

197 try: 

198 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

199 _ctx, "AudioSummaryV2", name, tag, tensor, sample_rate, "max_outputs", 

200 max_outputs) 

201 return _result 

202 except _core._NotOkStatusException as e: 

203 _ops.raise_from_not_ok_status(e, name) 

204 except _core._FallbackException: 

205 pass 

206 try: 

207 return audio_summary_v2_eager_fallback( 

208 tag, tensor, sample_rate, max_outputs=max_outputs, name=name, 

209 ctx=_ctx) 

210 except _core._SymbolicException: 

211 pass # Add nodes to the TensorFlow graph. 

212 # Add nodes to the TensorFlow graph. 

213 if max_outputs is None: 

214 max_outputs = 3 

215 max_outputs = _execute.make_int(max_outputs, "max_outputs") 

216 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

217 "AudioSummaryV2", tag=tag, tensor=tensor, sample_rate=sample_rate, 

218 max_outputs=max_outputs, name=name) 

219 _result = _outputs[:] 

220 if _execute.must_record_gradient(): 

221 _attrs = ("max_outputs", _op._get_attr_int("max_outputs")) 

222 _inputs_flat = _op.inputs 

223 _execute.record_gradient( 

224 "AudioSummaryV2", _inputs_flat, _attrs, _result) 

225 _result, = _result 

226 return _result 

227 

228AudioSummaryV2 = tf_export("raw_ops.AudioSummaryV2")(_ops.to_raw_op(audio_summary_v2)) 

229 

230 

231def audio_summary_v2_eager_fallback(tag, tensor, sample_rate, max_outputs, name, ctx): 

232 if max_outputs is None: 

233 max_outputs = 3 

234 max_outputs = _execute.make_int(max_outputs, "max_outputs") 

235 tag = _ops.convert_to_tensor(tag, _dtypes.string) 

236 tensor = _ops.convert_to_tensor(tensor, _dtypes.float32) 

237 sample_rate = _ops.convert_to_tensor(sample_rate, _dtypes.float32) 

238 _inputs_flat = [tag, tensor, sample_rate] 

239 _attrs = ("max_outputs", max_outputs) 

240 _result = _execute.execute(b"AudioSummaryV2", 1, inputs=_inputs_flat, 

241 attrs=_attrs, ctx=ctx, name=name) 

242 if _execute.must_record_gradient(): 

243 _execute.record_gradient( 

244 "AudioSummaryV2", _inputs_flat, _attrs, _result) 

245 _result, = _result 

246 return _result 

247 

248 

249def histogram_summary(tag, values, name=None): 

250 r"""Outputs a `Summary` protocol buffer with a histogram. 

251 

252 The generated 

253 [`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto) 

254 has one summary value containing a histogram for `values`. 

255 

256 This op reports an `InvalidArgument` error if any value is not finite. 

257 

258 Args: 

259 tag: A `Tensor` of type `string`. 

260 Scalar. Tag to use for the `Summary.Value`. 

261 values: A `Tensor`. Must be one of the following types: `float32`, `float64`, `int32`, `uint8`, `int16`, `int8`, `int64`, `bfloat16`, `uint16`, `half`, `uint32`, `uint64`. 

262 Any shape. Values to use to build the histogram. 

263 name: A name for the operation (optional). 

264 

265 Returns: 

266 A `Tensor` of type `string`. 

267 """ 

268 _ctx = _context._context or _context.context() 

269 tld = _ctx._thread_local_data 

270 if tld.is_eager: 

271 try: 

272 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

273 _ctx, "HistogramSummary", name, tag, values) 

274 return _result 

275 except _core._NotOkStatusException as e: 

276 _ops.raise_from_not_ok_status(e, name) 

277 except _core._FallbackException: 

278 pass 

279 try: 

280 return histogram_summary_eager_fallback( 

281 tag, values, name=name, ctx=_ctx) 

282 except _core._SymbolicException: 

283 pass # Add nodes to the TensorFlow graph. 

284 # Add nodes to the TensorFlow graph. 

285 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

286 "HistogramSummary", tag=tag, values=values, name=name) 

287 _result = _outputs[:] 

288 if _execute.must_record_gradient(): 

289 _attrs = ("T", _op._get_attr_type("T")) 

290 _inputs_flat = _op.inputs 

291 _execute.record_gradient( 

292 "HistogramSummary", _inputs_flat, _attrs, _result) 

293 _result, = _result 

294 return _result 

295 

296HistogramSummary = tf_export("raw_ops.HistogramSummary")(_ops.to_raw_op(histogram_summary)) 

297 

298 

299def histogram_summary_eager_fallback(tag, values, name, ctx): 

300 _attr_T, (values,) = _execute.args_to_matching_eager([values], ctx, [_dtypes.float32, _dtypes.float64, _dtypes.int32, _dtypes.uint8, _dtypes.int16, _dtypes.int8, _dtypes.int64, _dtypes.bfloat16, _dtypes.uint16, _dtypes.half, _dtypes.uint32, _dtypes.uint64, ], _dtypes.float32) 

301 tag = _ops.convert_to_tensor(tag, _dtypes.string) 

302 _inputs_flat = [tag, values] 

303 _attrs = ("T", _attr_T) 

304 _result = _execute.execute(b"HistogramSummary", 1, inputs=_inputs_flat, 

305 attrs=_attrs, ctx=ctx, name=name) 

306 if _execute.must_record_gradient(): 

307 _execute.record_gradient( 

308 "HistogramSummary", _inputs_flat, _attrs, _result) 

309 _result, = _result 

310 return _result 

311 

312 

313def image_summary(tag, tensor, max_images=3, bad_color=_execute.make_tensor("""dtype: DT_UINT8 tensor_shape { dim { size: 4 } } int_val: 255 int_val: 0 int_val: 0 int_val: 255 """, "bad_color"), name=None): 

314 r"""Outputs a `Summary` protocol buffer with images. 

315 

316 The summary has up to `max_images` summary values containing images. The 

317 images are built from `tensor` which must be 4-D with shape `[batch_size, 

318 height, width, channels]` and where `channels` can be: 

319 

320 * 1: `tensor` is interpreted as Grayscale. 

321 * 3: `tensor` is interpreted as RGB. 

322 * 4: `tensor` is interpreted as RGBA. 

323 

324 The images have the same number of channels as the input tensor. For float 

325 input, the values are normalized one image at a time to fit in the range 

326 `[0, 255]`. `uint8` values are unchanged. The op uses two different 

327 normalization algorithms: 

328 

329 * If the input values are all positive, they are rescaled so the largest one 

330 is 255. 

331 

332 * If any input value is negative, the values are shifted so input value 0.0 

333 is at 127. They are then rescaled so that either the smallest value is 0, 

334 or the largest one is 255. 

335 

336 The `tag` argument is a scalar `Tensor` of type `string`. It is used to 

337 build the `tag` of the summary values: 

338 

339 * If `max_images` is 1, the summary value tag is '*tag*/image'. 

340 * If `max_images` is greater than 1, the summary value tags are 

341 generated sequentially as '*tag*/image/0', '*tag*/image/1', etc. 

342 

343 The `bad_color` argument is the color to use in the generated images for 

344 non-finite input values. It is a `uint8` 1-D tensor of length `channels`. 

345 Each element must be in the range `[0, 255]` (It represents the value of a 

346 pixel in the output image). Non-finite values in the input tensor are 

347 replaced by this tensor in the output image. The default value is the color 

348 red. 

349 

350 Args: 

351 tag: A `Tensor` of type `string`. 

352 Scalar. Used to build the `tag` attribute of the summary values. 

353 tensor: A `Tensor`. Must be one of the following types: `uint8`, `float32`, `half`, `float64`. 

354 4-D of shape `[batch_size, height, width, channels]` where 

355 `channels` is 1, 3, or 4. 

356 max_images: An optional `int` that is `>= 1`. Defaults to `3`. 

357 Max number of batch elements to generate images for. 

358 bad_color: An optional `tf.TensorProto`. Defaults to `dtype: DT_UINT8 tensor_shape { dim { size: 4 } } int_val: 255 int_val: 0 int_val: 0 int_val: 255`. 

359 Color to use for pixels with non-finite values. 

360 name: A name for the operation (optional). 

361 

362 Returns: 

363 A `Tensor` of type `string`. 

364 """ 

365 _ctx = _context._context or _context.context() 

366 tld = _ctx._thread_local_data 

367 if tld.is_eager: 

368 try: 

369 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

370 _ctx, "ImageSummary", name, tag, tensor, "max_images", max_images, 

371 "bad_color", bad_color) 

372 return _result 

373 except _core._NotOkStatusException as e: 

374 _ops.raise_from_not_ok_status(e, name) 

375 except _core._FallbackException: 

376 pass 

377 try: 

378 return image_summary_eager_fallback( 

379 tag, tensor, max_images=max_images, bad_color=bad_color, name=name, 

380 ctx=_ctx) 

381 except _core._SymbolicException: 

382 pass # Add nodes to the TensorFlow graph. 

383 # Add nodes to the TensorFlow graph. 

384 if max_images is None: 

385 max_images = 3 

386 max_images = _execute.make_int(max_images, "max_images") 

387 if bad_color is None: 

388 bad_color = _execute.make_tensor("""dtype: DT_UINT8 tensor_shape { dim { size: 4 } } int_val: 255 int_val: 0 int_val: 0 int_val: 255 """, "bad_color") 

389 bad_color = _execute.make_tensor(bad_color, "bad_color") 

390 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

391 "ImageSummary", tag=tag, tensor=tensor, max_images=max_images, 

392 bad_color=bad_color, name=name) 

393 _result = _outputs[:] 

394 if _execute.must_record_gradient(): 

395 _attrs = ("max_images", _op._get_attr_int("max_images"), "T", 

396 _op._get_attr_type("T"), "bad_color", _op.get_attr("bad_color")) 

397 _inputs_flat = _op.inputs 

398 _execute.record_gradient( 

399 "ImageSummary", _inputs_flat, _attrs, _result) 

400 _result, = _result 

401 return _result 

402 

403ImageSummary = tf_export("raw_ops.ImageSummary")(_ops.to_raw_op(image_summary)) 

404 

405 

406def image_summary_eager_fallback(tag, tensor, max_images, bad_color, name, ctx): 

407 if max_images is None: 

408 max_images = 3 

409 max_images = _execute.make_int(max_images, "max_images") 

410 if bad_color is None: 

411 bad_color = _execute.make_tensor("""dtype: DT_UINT8 tensor_shape { dim { size: 4 } } int_val: 255 int_val: 0 int_val: 0 int_val: 255 """, "bad_color") 

412 bad_color = _execute.make_tensor(bad_color, "bad_color") 

413 _attr_T, (tensor,) = _execute.args_to_matching_eager([tensor], ctx, [_dtypes.uint8, _dtypes.float32, _dtypes.half, _dtypes.float64, ], _dtypes.float32) 

414 tag = _ops.convert_to_tensor(tag, _dtypes.string) 

415 _inputs_flat = [tag, tensor] 

416 _attrs = ("max_images", max_images, "T", _attr_T, "bad_color", bad_color) 

417 _result = _execute.execute(b"ImageSummary", 1, inputs=_inputs_flat, 

418 attrs=_attrs, ctx=ctx, name=name) 

419 if _execute.must_record_gradient(): 

420 _execute.record_gradient( 

421 "ImageSummary", _inputs_flat, _attrs, _result) 

422 _result, = _result 

423 return _result 

424 

425 

426def merge_summary(inputs, name=None): 

427 r"""Merges summaries. 

428 

429 This op creates a 

430 [`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto) 

431 protocol buffer that contains the union of all the values in the input 

432 summaries. 

433 

434 When the Op is run, it reports an `InvalidArgument` error if multiple values 

435 in the summaries to merge use the same tag. 

436 

437 Args: 

438 inputs: A list of at least 1 `Tensor` objects with type `string`. 

439 Can be of any shape. Each must contain serialized `Summary` protocol 

440 buffers. 

441 name: A name for the operation (optional). 

442 

443 Returns: 

444 A `Tensor` of type `string`. 

445 """ 

446 _ctx = _context._context or _context.context() 

447 tld = _ctx._thread_local_data 

448 if tld.is_eager: 

449 try: 

450 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

451 _ctx, "MergeSummary", name, inputs) 

452 return _result 

453 except _core._NotOkStatusException as e: 

454 _ops.raise_from_not_ok_status(e, name) 

455 except _core._FallbackException: 

456 pass 

457 try: 

458 return merge_summary_eager_fallback( 

459 inputs, name=name, ctx=_ctx) 

460 except _core._SymbolicException: 

461 pass # Add nodes to the TensorFlow graph. 

462 # Add nodes to the TensorFlow graph. 

463 if not isinstance(inputs, (list, tuple)): 

464 raise TypeError( 

465 "Expected list for 'inputs' argument to " 

466 "'merge_summary' Op, not %r." % inputs) 

467 _attr_N = len(inputs) 

468 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

469 "MergeSummary", inputs=inputs, name=name) 

470 _result = _outputs[:] 

471 if _execute.must_record_gradient(): 

472 _attrs = ("N", _op._get_attr_int("N")) 

473 _inputs_flat = _op.inputs 

474 _execute.record_gradient( 

475 "MergeSummary", _inputs_flat, _attrs, _result) 

476 _result, = _result 

477 return _result 

478 

479MergeSummary = tf_export("raw_ops.MergeSummary")(_ops.to_raw_op(merge_summary)) 

480 

481 

482def merge_summary_eager_fallback(inputs, name, ctx): 

483 if not isinstance(inputs, (list, tuple)): 

484 raise TypeError( 

485 "Expected list for 'inputs' argument to " 

486 "'merge_summary' Op, not %r." % inputs) 

487 _attr_N = len(inputs) 

488 inputs = _ops.convert_n_to_tensor(inputs, _dtypes.string) 

489 _inputs_flat = list(inputs) 

490 _attrs = ("N", _attr_N) 

491 _result = _execute.execute(b"MergeSummary", 1, inputs=_inputs_flat, 

492 attrs=_attrs, ctx=ctx, name=name) 

493 if _execute.must_record_gradient(): 

494 _execute.record_gradient( 

495 "MergeSummary", _inputs_flat, _attrs, _result) 

496 _result, = _result 

497 return _result 

498 

499 

500def _print(input, data, message="", first_n=-1, summarize=3, name=None): 

501 r"""Prints a list of tensors. 

502 

503 Passes `input` through to `output` and prints `data` when evaluating. 

504 

505 Args: 

506 input: A `Tensor`. The tensor passed to `output` 

507 data: A list of `Tensor` objects. 

508 A list of tensors to print out when op is evaluated. 

509 message: An optional `string`. Defaults to `""`. 

510 A string, prefix of the error message. 

511 first_n: An optional `int`. Defaults to `-1`. 

512 Only log `first_n` number of times. -1 disables logging. 

513 summarize: An optional `int`. Defaults to `3`. 

514 Only print this many entries of each tensor. 

515 name: A name for the operation (optional). 

516 

517 Returns: 

518 A `Tensor`. Has the same type as `input`. 

519 """ 

520 _ctx = _context._context or _context.context() 

521 tld = _ctx._thread_local_data 

522 if tld.is_eager: 

523 try: 

524 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

525 _ctx, "Print", name, input, data, "message", message, "first_n", 

526 first_n, "summarize", summarize) 

527 return _result 

528 except _core._NotOkStatusException as e: 

529 _ops.raise_from_not_ok_status(e, name) 

530 except _core._FallbackException: 

531 pass 

532 try: 

533 return _print_eager_fallback( 

534 input, data, message=message, first_n=first_n, summarize=summarize, 

535 name=name, ctx=_ctx) 

536 except _core._SymbolicException: 

537 pass # Add nodes to the TensorFlow graph. 

538 # Add nodes to the TensorFlow graph. 

539 if message is None: 

540 message = "" 

541 message = _execute.make_str(message, "message") 

542 if first_n is None: 

543 first_n = -1 

544 first_n = _execute.make_int(first_n, "first_n") 

545 if summarize is None: 

546 summarize = 3 

547 summarize = _execute.make_int(summarize, "summarize") 

548 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

549 "Print", input=input, data=data, message=message, first_n=first_n, 

550 summarize=summarize, name=name) 

551 _result = _outputs[:] 

552 if _execute.must_record_gradient(): 

553 _attrs = ("T", _op._get_attr_type("T"), "U", _op.get_attr("U"), "message", 

554 _op.get_attr("message"), "first_n", 

555 _op._get_attr_int("first_n"), "summarize", 

556 _op._get_attr_int("summarize")) 

557 _inputs_flat = _op.inputs 

558 _execute.record_gradient( 

559 "Print", _inputs_flat, _attrs, _result) 

560 _result, = _result 

561 return _result 

562 

563Print = tf_export("raw_ops.Print")(_ops.to_raw_op(_print)) 

564 

565 

566def _print_eager_fallback(input, data, message, first_n, summarize, name, ctx): 

567 if message is None: 

568 message = "" 

569 message = _execute.make_str(message, "message") 

570 if first_n is None: 

571 first_n = -1 

572 first_n = _execute.make_int(first_n, "first_n") 

573 if summarize is None: 

574 summarize = 3 

575 summarize = _execute.make_int(summarize, "summarize") 

576 _attr_T, (input,) = _execute.args_to_matching_eager([input], ctx, []) 

577 _attr_U, data = _execute.convert_to_mixed_eager_tensors(data, ctx) 

578 _inputs_flat = [input] + list(data) 

579 _attrs = ("T", _attr_T, "U", _attr_U, "message", message, "first_n", 

580 first_n, "summarize", summarize) 

581 _result = _execute.execute(b"Print", 1, inputs=_inputs_flat, attrs=_attrs, 

582 ctx=ctx, name=name) 

583 if _execute.must_record_gradient(): 

584 _execute.record_gradient( 

585 "Print", _inputs_flat, _attrs, _result) 

586 _result, = _result 

587 return _result 

588 

589 

590def print_v2(input, output_stream="stderr", end="\n", name=None): 

591 r"""Prints a string scalar. 

592 

593 Prints a string scalar to the desired output_stream. 

594 

595 Args: 

596 input: A `Tensor` of type `string`. The string scalar to print. 

597 output_stream: An optional `string`. Defaults to `"stderr"`. 

598 A string specifying the output stream or logging level to print to. 

599 end: An optional `string`. Defaults to `"\n"`. 

600 name: A name for the operation (optional). 

601 

602 Returns: 

603 The created Operation. 

604 """ 

605 _ctx = _context._context or _context.context() 

606 tld = _ctx._thread_local_data 

607 if tld.is_eager: 

608 try: 

609 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

610 _ctx, "PrintV2", name, input, "output_stream", output_stream, "end", 

611 end) 

612 return _result 

613 except _core._NotOkStatusException as e: 

614 _ops.raise_from_not_ok_status(e, name) 

615 except _core._FallbackException: 

616 pass 

617 try: 

618 return print_v2_eager_fallback( 

619 input, output_stream=output_stream, end=end, name=name, ctx=_ctx) 

620 except _core._SymbolicException: 

621 pass # Add nodes to the TensorFlow graph. 

622 # Add nodes to the TensorFlow graph. 

623 if output_stream is None: 

624 output_stream = "stderr" 

625 output_stream = _execute.make_str(output_stream, "output_stream") 

626 if end is None: 

627 end = "\n" 

628 end = _execute.make_str(end, "end") 

629 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

630 "PrintV2", input=input, output_stream=output_stream, end=end, 

631 name=name) 

632 return _op 

633PrintV2 = tf_export("raw_ops.PrintV2")(_ops.to_raw_op(print_v2)) 

634 

635 

636def print_v2_eager_fallback(input, output_stream, end, name, ctx): 

637 if output_stream is None: 

638 output_stream = "stderr" 

639 output_stream = _execute.make_str(output_stream, "output_stream") 

640 if end is None: 

641 end = "\n" 

642 end = _execute.make_str(end, "end") 

643 input = _ops.convert_to_tensor(input, _dtypes.string) 

644 _inputs_flat = [input] 

645 _attrs = ("output_stream", output_stream, "end", end) 

646 _result = _execute.execute(b"PrintV2", 0, inputs=_inputs_flat, attrs=_attrs, 

647 ctx=ctx, name=name) 

648 _result = None 

649 return _result 

650 

651 

652def scalar_summary(tags, values, name=None): 

653 r"""Outputs a `Summary` protocol buffer with scalar values. 

654 

655 The input `tags` and `values` must have the same shape. The generated summary 

656 has a summary value for each tag-value pair in `tags` and `values`. 

657 

658 Args: 

659 tags: A `Tensor` of type `string`. Tags for the summary. 

660 values: A `Tensor`. Must be one of the following types: `float32`, `float64`, `int32`, `uint8`, `int16`, `int8`, `int64`, `bfloat16`, `uint16`, `half`, `uint32`, `uint64`. 

661 Same shape as `tags. Values for the summary. 

662 name: A name for the operation (optional). 

663 

664 Returns: 

665 A `Tensor` of type `string`. 

666 """ 

667 _ctx = _context._context or _context.context() 

668 tld = _ctx._thread_local_data 

669 if tld.is_eager: 

670 try: 

671 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

672 _ctx, "ScalarSummary", name, tags, values) 

673 return _result 

674 except _core._NotOkStatusException as e: 

675 _ops.raise_from_not_ok_status(e, name) 

676 except _core._FallbackException: 

677 pass 

678 try: 

679 return scalar_summary_eager_fallback( 

680 tags, values, name=name, ctx=_ctx) 

681 except _core._SymbolicException: 

682 pass # Add nodes to the TensorFlow graph. 

683 # Add nodes to the TensorFlow graph. 

684 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

685 "ScalarSummary", tags=tags, values=values, name=name) 

686 _result = _outputs[:] 

687 if _execute.must_record_gradient(): 

688 _attrs = ("T", _op._get_attr_type("T")) 

689 _inputs_flat = _op.inputs 

690 _execute.record_gradient( 

691 "ScalarSummary", _inputs_flat, _attrs, _result) 

692 _result, = _result 

693 return _result 

694 

695ScalarSummary = tf_export("raw_ops.ScalarSummary")(_ops.to_raw_op(scalar_summary)) 

696 

697 

698def scalar_summary_eager_fallback(tags, values, name, ctx): 

699 _attr_T, (values,) = _execute.args_to_matching_eager([values], ctx, [_dtypes.float32, _dtypes.float64, _dtypes.int32, _dtypes.uint8, _dtypes.int16, _dtypes.int8, _dtypes.int64, _dtypes.bfloat16, _dtypes.uint16, _dtypes.half, _dtypes.uint32, _dtypes.uint64, ]) 

700 tags = _ops.convert_to_tensor(tags, _dtypes.string) 

701 _inputs_flat = [tags, values] 

702 _attrs = ("T", _attr_T) 

703 _result = _execute.execute(b"ScalarSummary", 1, inputs=_inputs_flat, 

704 attrs=_attrs, ctx=ctx, name=name) 

705 if _execute.must_record_gradient(): 

706 _execute.record_gradient( 

707 "ScalarSummary", _inputs_flat, _attrs, _result) 

708 _result, = _result 

709 return _result 

710 

711 

712def tensor_summary(tensor, description="", labels=[], display_name="", name=None): 

713 r"""Outputs a `Summary` protocol buffer with a tensor. 

714 

715 This op is being phased out in favor of TensorSummaryV2, which lets callers pass 

716 a tag as well as a serialized SummaryMetadata proto string that contains 

717 plugin-specific data. We will keep this op to maintain backwards compatibility. 

718 

719 Args: 

720 tensor: A `Tensor`. A tensor to serialize. 

721 description: An optional `string`. Defaults to `""`. 

722 A json-encoded SummaryDescription proto. 

723 labels: An optional list of `strings`. Defaults to `[]`. 

724 An unused list of strings. 

725 display_name: An optional `string`. Defaults to `""`. An unused string. 

726 name: A name for the operation (optional). 

727 

728 Returns: 

729 A `Tensor` of type `string`. 

730 """ 

731 _ctx = _context._context or _context.context() 

732 tld = _ctx._thread_local_data 

733 if tld.is_eager: 

734 try: 

735 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

736 _ctx, "TensorSummary", name, tensor, "description", description, 

737 "labels", labels, "display_name", display_name) 

738 return _result 

739 except _core._NotOkStatusException as e: 

740 _ops.raise_from_not_ok_status(e, name) 

741 except _core._FallbackException: 

742 pass 

743 try: 

744 return tensor_summary_eager_fallback( 

745 tensor, description=description, labels=labels, 

746 display_name=display_name, name=name, ctx=_ctx) 

747 except _core._SymbolicException: 

748 pass # Add nodes to the TensorFlow graph. 

749 # Add nodes to the TensorFlow graph. 

750 if description is None: 

751 description = "" 

752 description = _execute.make_str(description, "description") 

753 if labels is None: 

754 labels = [] 

755 if not isinstance(labels, (list, tuple)): 

756 raise TypeError( 

757 "Expected list for 'labels' argument to " 

758 "'tensor_summary' Op, not %r." % labels) 

759 labels = [_execute.make_str(_s, "labels") for _s in labels] 

760 if display_name is None: 

761 display_name = "" 

762 display_name = _execute.make_str(display_name, "display_name") 

763 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

764 "TensorSummary", tensor=tensor, description=description, 

765 labels=labels, display_name=display_name, name=name) 

766 _result = _outputs[:] 

767 if _execute.must_record_gradient(): 

768 _attrs = ("T", _op._get_attr_type("T"), "description", 

769 _op.get_attr("description"), "labels", _op.get_attr("labels"), 

770 "display_name", _op.get_attr("display_name")) 

771 _inputs_flat = _op.inputs 

772 _execute.record_gradient( 

773 "TensorSummary", _inputs_flat, _attrs, _result) 

774 _result, = _result 

775 return _result 

776 

777TensorSummary = tf_export("raw_ops.TensorSummary")(_ops.to_raw_op(tensor_summary)) 

778 

779 

780def tensor_summary_eager_fallback(tensor, description, labels, display_name, name, ctx): 

781 if description is None: 

782 description = "" 

783 description = _execute.make_str(description, "description") 

784 if labels is None: 

785 labels = [] 

786 if not isinstance(labels, (list, tuple)): 

787 raise TypeError( 

788 "Expected list for 'labels' argument to " 

789 "'tensor_summary' Op, not %r." % labels) 

790 labels = [_execute.make_str(_s, "labels") for _s in labels] 

791 if display_name is None: 

792 display_name = "" 

793 display_name = _execute.make_str(display_name, "display_name") 

794 _attr_T, (tensor,) = _execute.args_to_matching_eager([tensor], ctx, []) 

795 _inputs_flat = [tensor] 

796 _attrs = ("T", _attr_T, "description", description, "labels", labels, 

797 "display_name", display_name) 

798 _result = _execute.execute(b"TensorSummary", 1, inputs=_inputs_flat, 

799 attrs=_attrs, ctx=ctx, name=name) 

800 if _execute.must_record_gradient(): 

801 _execute.record_gradient( 

802 "TensorSummary", _inputs_flat, _attrs, _result) 

803 _result, = _result 

804 return _result 

805 

806 

807def tensor_summary_v2(tag, tensor, serialized_summary_metadata, name=None): 

808 r"""Outputs a `Summary` protocol buffer with a tensor and per-plugin data. 

809 

810 Args: 

811 tag: A `Tensor` of type `string`. 

812 A string attached to this summary. Used for organization in TensorBoard. 

813 tensor: A `Tensor`. A tensor to serialize. 

814 serialized_summary_metadata: A `Tensor` of type `string`. 

815 A serialized SummaryMetadata proto. Contains plugin 

816 data. 

817 name: A name for the operation (optional). 

818 

819 Returns: 

820 A `Tensor` of type `string`. 

821 """ 

822 _ctx = _context._context or _context.context() 

823 tld = _ctx._thread_local_data 

824 if tld.is_eager: 

825 try: 

826 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

827 _ctx, "TensorSummaryV2", name, tag, tensor, 

828 serialized_summary_metadata) 

829 return _result 

830 except _core._NotOkStatusException as e: 

831 _ops.raise_from_not_ok_status(e, name) 

832 except _core._FallbackException: 

833 pass 

834 try: 

835 return tensor_summary_v2_eager_fallback( 

836 tag, tensor, serialized_summary_metadata, name=name, ctx=_ctx) 

837 except _core._SymbolicException: 

838 pass # Add nodes to the TensorFlow graph. 

839 # Add nodes to the TensorFlow graph. 

840 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

841 "TensorSummaryV2", tag=tag, tensor=tensor, 

842 serialized_summary_metadata=serialized_summary_metadata, 

843 name=name) 

844 _result = _outputs[:] 

845 if _execute.must_record_gradient(): 

846 _attrs = ("T", _op._get_attr_type("T")) 

847 _inputs_flat = _op.inputs 

848 _execute.record_gradient( 

849 "TensorSummaryV2", _inputs_flat, _attrs, _result) 

850 _result, = _result 

851 return _result 

852 

853TensorSummaryV2 = tf_export("raw_ops.TensorSummaryV2")(_ops.to_raw_op(tensor_summary_v2)) 

854 

855 

856def tensor_summary_v2_eager_fallback(tag, tensor, serialized_summary_metadata, name, ctx): 

857 _attr_T, (tensor,) = _execute.args_to_matching_eager([tensor], ctx, []) 

858 tag = _ops.convert_to_tensor(tag, _dtypes.string) 

859 serialized_summary_metadata = _ops.convert_to_tensor(serialized_summary_metadata, _dtypes.string) 

860 _inputs_flat = [tag, tensor, serialized_summary_metadata] 

861 _attrs = ("T", _attr_T) 

862 _result = _execute.execute(b"TensorSummaryV2", 1, inputs=_inputs_flat, 

863 attrs=_attrs, ctx=ctx, name=name) 

864 if _execute.must_record_gradient(): 

865 _execute.record_gradient( 

866 "TensorSummaryV2", _inputs_flat, _attrs, _result) 

867 _result, = _result 

868 return _result 

869 

870 

871@_dispatch.add_fallback_dispatch_list 

872@_dispatch.add_type_based_api_dispatcher 

873@tf_export('timestamp') 

874def timestamp(name=None): 

875 r"""Provides the time since epoch in seconds. 

876 

877 Returns the timestamp as a `float64` for seconds since the Unix epoch. 

878 

879 Common usages include: 

880 * Logging 

881 * Providing a random number seed 

882 * Debugging graph execution 

883 * Generating timing information, mainly through comparison of timestamps 

884 

885 Note: In graph mode, the timestamp is computed when the op is executed, 

886 not when it is added to the graph. In eager mode, the timestamp is computed 

887 when the op is eagerly executed. 

888 

889 Args: 

890 name: A name for the operation (optional). 

891 

892 Returns: 

893 A `Tensor` of type `float64`. 

894 """ 

895 _ctx = _context._context or _context.context() 

896 tld = _ctx._thread_local_data 

897 if tld.is_eager: 

898 try: 

899 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

900 _ctx, "Timestamp", name) 

901 return _result 

902 except _core._NotOkStatusException as e: 

903 _ops.raise_from_not_ok_status(e, name) 

904 except _core._FallbackException: 

905 pass 

906 try: 

907 _result = _dispatcher_for_timestamp( 

908 (name,), None) 

909 if _result is not NotImplemented: 

910 return _result 

911 return timestamp_eager_fallback( 

912 name=name, ctx=_ctx) 

913 except _core._SymbolicException: 

914 pass # Add nodes to the TensorFlow graph. 

915 except (TypeError, ValueError): 

916 _result = _dispatch.dispatch( 

917 timestamp, (), dict(name=name) 

918 ) 

919 if _result is not _dispatch.OpDispatcher.NOT_SUPPORTED: 

920 return _result 

921 raise 

922 else: 

923 _result = _dispatcher_for_timestamp( 

924 (name,), None) 

925 if _result is not NotImplemented: 

926 return _result 

927 # Add nodes to the TensorFlow graph. 

928 try: 

929 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

930 "Timestamp", name=name) 

931 except (TypeError, ValueError): 

932 _result = _dispatch.dispatch( 

933 timestamp, (), dict(name=name) 

934 ) 

935 if _result is not _dispatch.OpDispatcher.NOT_SUPPORTED: 

936 return _result 

937 raise 

938 _result = _outputs[:] 

939 if _execute.must_record_gradient(): 

940 _attrs = () 

941 _inputs_flat = _op.inputs 

942 _execute.record_gradient( 

943 "Timestamp", _inputs_flat, _attrs, _result) 

944 _result, = _result 

945 return _result 

946 

947Timestamp = tf_export("raw_ops.Timestamp")(_ops.to_raw_op(timestamp)) 

948_dispatcher_for_timestamp = timestamp._tf_type_based_dispatcher.Dispatch 

949 

950 

951def timestamp_eager_fallback(name, ctx): 

952 _inputs_flat = [] 

953 _attrs = None 

954 _result = _execute.execute(b"Timestamp", 1, inputs=_inputs_flat, 

955 attrs=_attrs, ctx=ctx, name=name) 

956 if _execute.must_record_gradient(): 

957 _execute.record_gradient( 

958 "Timestamp", _inputs_flat, _attrs, _result) 

959 _result, = _result 

960 return _result 

961