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

2257 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 adjust_contrast(images, contrast_factor, min_value, max_value, name=None): 

25 r"""Deprecated. Disallowed in GraphDef version >= 2. 

26 

27 Args: 

28 images: A `Tensor`. Must be one of the following types: `uint8`, `int8`, `int16`, `int32`, `int64`, `float32`, `float64`. 

29 contrast_factor: A `Tensor` of type `float32`. 

30 min_value: A `Tensor` of type `float32`. 

31 max_value: A `Tensor` of type `float32`. 

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

33 

34 Returns: 

35 A `Tensor` of type `float32`. 

36 """ 

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

38 tld = _ctx._thread_local_data 

39 if tld.is_eager: 

40 try: 

41 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

42 _ctx, "AdjustContrast", name, images, contrast_factor, min_value, 

43 max_value) 

44 return _result 

45 except _core._NotOkStatusException as e: 

46 _ops.raise_from_not_ok_status(e, name) 

47 except _core._FallbackException: 

48 pass 

49 try: 

50 return adjust_contrast_eager_fallback( 

51 images, contrast_factor, min_value, max_value, name=name, ctx=_ctx) 

52 except _core._SymbolicException: 

53 pass # Add nodes to the TensorFlow graph. 

54 # Add nodes to the TensorFlow graph. 

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

56 "AdjustContrast", images=images, contrast_factor=contrast_factor, 

57 min_value=min_value, max_value=max_value, name=name) 

58 _result = _outputs[:] 

59 if _execute.must_record_gradient(): 

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

61 _inputs_flat = _op.inputs 

62 _execute.record_gradient( 

63 "AdjustContrast", _inputs_flat, _attrs, _result) 

64 _result, = _result 

65 return _result 

66 

67AdjustContrast = tf_export("raw_ops.AdjustContrast")(_ops.to_raw_op(adjust_contrast)) 

68 

69 

70def adjust_contrast_eager_fallback(images, contrast_factor, min_value, max_value, name, ctx): 

71 _attr_T, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.uint8, _dtypes.int8, _dtypes.int16, _dtypes.int32, _dtypes.int64, _dtypes.float32, _dtypes.float64, ]) 

72 contrast_factor = _ops.convert_to_tensor(contrast_factor, _dtypes.float32) 

73 min_value = _ops.convert_to_tensor(min_value, _dtypes.float32) 

74 max_value = _ops.convert_to_tensor(max_value, _dtypes.float32) 

75 _inputs_flat = [images, contrast_factor, min_value, max_value] 

76 _attrs = ("T", _attr_T) 

77 _result = _execute.execute(b"AdjustContrast", 1, inputs=_inputs_flat, 

78 attrs=_attrs, ctx=ctx, name=name) 

79 if _execute.must_record_gradient(): 

80 _execute.record_gradient( 

81 "AdjustContrast", _inputs_flat, _attrs, _result) 

82 _result, = _result 

83 return _result 

84 

85 

86def adjust_contrastv2(images, contrast_factor, name=None): 

87 r"""Adjust the contrast of one or more images. 

88 

89 `images` is a tensor of at least 3 dimensions. The last 3 dimensions are 

90 interpreted as `[height, width, channels]`. The other dimensions only 

91 represent a collection of images, such as `[batch, height, width, channels].` 

92 

93 Contrast is adjusted independently for each channel of each image. 

94 

95 For each channel, the Op first computes the mean of the image pixels in the 

96 channel and then adjusts each component of each pixel to 

97 `(x - mean) * contrast_factor + mean`. 

98 

99 Args: 

100 images: A `Tensor`. Must be one of the following types: `half`, `float32`. 

101 Images to adjust. At least 3-D. 

102 contrast_factor: A `Tensor` of type `float32`. 

103 A float multiplier for adjusting contrast. 

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

105 

106 Returns: 

107 A `Tensor`. Has the same type as `images`. 

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, "AdjustContrastv2", name, images, contrast_factor) 

115 return _result 

116 except _core._NotOkStatusException as e: 

117 _ops.raise_from_not_ok_status(e, name) 

118 except _core._FallbackException: 

119 pass 

120 try: 

121 return adjust_contrastv2_eager_fallback( 

122 images, contrast_factor, name=name, ctx=_ctx) 

123 except _core._SymbolicException: 

124 pass # Add nodes to the TensorFlow graph. 

125 # Add nodes to the TensorFlow graph. 

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

127 "AdjustContrastv2", images=images, contrast_factor=contrast_factor, 

128 name=name) 

129 _result = _outputs[:] 

130 if _execute.must_record_gradient(): 

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

132 _inputs_flat = _op.inputs 

133 _execute.record_gradient( 

134 "AdjustContrastv2", _inputs_flat, _attrs, _result) 

135 _result, = _result 

136 return _result 

137 

138AdjustContrastv2 = tf_export("raw_ops.AdjustContrastv2")(_ops.to_raw_op(adjust_contrastv2)) 

139 

140 

141def adjust_contrastv2_eager_fallback(images, contrast_factor, name, ctx): 

142 _attr_T, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.half, _dtypes.float32, ], _dtypes.float32) 

143 contrast_factor = _ops.convert_to_tensor(contrast_factor, _dtypes.float32) 

144 _inputs_flat = [images, contrast_factor] 

145 _attrs = ("T", _attr_T) 

146 _result = _execute.execute(b"AdjustContrastv2", 1, inputs=_inputs_flat, 

147 attrs=_attrs, ctx=ctx, name=name) 

148 if _execute.must_record_gradient(): 

149 _execute.record_gradient( 

150 "AdjustContrastv2", _inputs_flat, _attrs, _result) 

151 _result, = _result 

152 return _result 

153 

154 

155def adjust_hue(images, delta, name=None): 

156 r"""Adjust the hue of one or more images. 

157 

158 `images` is a tensor of at least 3 dimensions. The last dimension is 

159 interpreted as channels, and must be three. 

160 

161 The input image is considered in the RGB colorspace. Conceptually, the RGB 

162 colors are first mapped into HSV. A delta is then applied all the hue values, 

163 and then remapped back to RGB colorspace. 

164 

165 Args: 

166 images: A `Tensor`. Must be one of the following types: `half`, `float32`. 

167 Images to adjust. At least 3-D. 

168 delta: A `Tensor` of type `float32`. A float delta to add to the hue. 

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

170 

171 Returns: 

172 A `Tensor`. Has the same type as `images`. 

173 """ 

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

175 tld = _ctx._thread_local_data 

176 if tld.is_eager: 

177 try: 

178 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

179 _ctx, "AdjustHue", name, images, delta) 

180 return _result 

181 except _core._NotOkStatusException as e: 

182 _ops.raise_from_not_ok_status(e, name) 

183 except _core._FallbackException: 

184 pass 

185 try: 

186 return adjust_hue_eager_fallback( 

187 images, delta, name=name, ctx=_ctx) 

188 except _core._SymbolicException: 

189 pass # Add nodes to the TensorFlow graph. 

190 # Add nodes to the TensorFlow graph. 

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

192 "AdjustHue", images=images, delta=delta, name=name) 

193 _result = _outputs[:] 

194 if _execute.must_record_gradient(): 

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

196 _inputs_flat = _op.inputs 

197 _execute.record_gradient( 

198 "AdjustHue", _inputs_flat, _attrs, _result) 

199 _result, = _result 

200 return _result 

201 

202AdjustHue = tf_export("raw_ops.AdjustHue")(_ops.to_raw_op(adjust_hue)) 

203 

204 

205def adjust_hue_eager_fallback(images, delta, name, ctx): 

206 _attr_T, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.half, _dtypes.float32, ], _dtypes.float32) 

207 delta = _ops.convert_to_tensor(delta, _dtypes.float32) 

208 _inputs_flat = [images, delta] 

209 _attrs = ("T", _attr_T) 

210 _result = _execute.execute(b"AdjustHue", 1, inputs=_inputs_flat, 

211 attrs=_attrs, ctx=ctx, name=name) 

212 if _execute.must_record_gradient(): 

213 _execute.record_gradient( 

214 "AdjustHue", _inputs_flat, _attrs, _result) 

215 _result, = _result 

216 return _result 

217 

218 

219def adjust_saturation(images, scale, name=None): 

220 r"""Adjust the saturation of one or more images. 

221 

222 `images` is a tensor of at least 3 dimensions. The last dimension is 

223 interpreted as channels, and must be three. 

224 

225 The input image is considered in the RGB colorspace. Conceptually, the RGB 

226 colors are first mapped into HSV. A scale is then applied all the saturation 

227 values, and then remapped back to RGB colorspace. 

228 

229 Args: 

230 images: A `Tensor`. Must be one of the following types: `half`, `float32`. 

231 Images to adjust. At least 3-D. 

232 scale: A `Tensor` of type `float32`. 

233 A float scale to add to the saturation. 

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

235 

236 Returns: 

237 A `Tensor`. Has the same type as `images`. 

238 """ 

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

240 tld = _ctx._thread_local_data 

241 if tld.is_eager: 

242 try: 

243 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

244 _ctx, "AdjustSaturation", name, images, scale) 

245 return _result 

246 except _core._NotOkStatusException as e: 

247 _ops.raise_from_not_ok_status(e, name) 

248 except _core._FallbackException: 

249 pass 

250 try: 

251 return adjust_saturation_eager_fallback( 

252 images, scale, name=name, ctx=_ctx) 

253 except _core._SymbolicException: 

254 pass # Add nodes to the TensorFlow graph. 

255 # Add nodes to the TensorFlow graph. 

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

257 "AdjustSaturation", images=images, scale=scale, name=name) 

258 _result = _outputs[:] 

259 if _execute.must_record_gradient(): 

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

261 _inputs_flat = _op.inputs 

262 _execute.record_gradient( 

263 "AdjustSaturation", _inputs_flat, _attrs, _result) 

264 _result, = _result 

265 return _result 

266 

267AdjustSaturation = tf_export("raw_ops.AdjustSaturation")(_ops.to_raw_op(adjust_saturation)) 

268 

269 

270def adjust_saturation_eager_fallback(images, scale, name, ctx): 

271 _attr_T, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.half, _dtypes.float32, ], _dtypes.float32) 

272 scale = _ops.convert_to_tensor(scale, _dtypes.float32) 

273 _inputs_flat = [images, scale] 

274 _attrs = ("T", _attr_T) 

275 _result = _execute.execute(b"AdjustSaturation", 1, inputs=_inputs_flat, 

276 attrs=_attrs, ctx=ctx, name=name) 

277 if _execute.must_record_gradient(): 

278 _execute.record_gradient( 

279 "AdjustSaturation", _inputs_flat, _attrs, _result) 

280 _result, = _result 

281 return _result 

282 

283_CombinedNonMaxSuppressionOutput = collections.namedtuple( 

284 "CombinedNonMaxSuppression", 

285 ["nmsed_boxes", "nmsed_scores", "nmsed_classes", "valid_detections"]) 

286 

287 

288def combined_non_max_suppression(boxes, scores, max_output_size_per_class, max_total_size, iou_threshold, score_threshold, pad_per_class=False, clip_boxes=True, name=None): 

289 r"""Greedily selects a subset of bounding boxes in descending order of score, 

290 

291 This operation performs non_max_suppression on the inputs per batch, across 

292 all classes. 

293 Prunes away boxes that have high intersection-over-union (IOU) overlap 

294 with previously selected boxes. Bounding boxes are supplied as 

295 [y1, x1, y2, x2], where (y1, x1) and (y2, x2) are the coordinates of any 

296 diagonal pair of box corners and the coordinates can be provided as normalized 

297 (i.e., lying in the interval [0, 1]) or absolute. Note that this algorithm 

298 is agnostic to where the origin is in the coordinate system. Also note that 

299 this algorithm is invariant to orthogonal transformations and translations 

300 of the coordinate system; thus translating or reflections of the coordinate 

301 system result in the same boxes being selected by the algorithm. 

302 The output of this operation is the final boxes, scores and classes tensor 

303 returned after performing non_max_suppression. 

304 

305 Args: 

306 boxes: A `Tensor` of type `float32`. 

307 A 4-D float tensor of shape `[batch_size, num_boxes, q, 4]`. If `q` is 1 then 

308 same boxes are used for all classes otherwise, if `q` is equal to number of 

309 classes, class-specific boxes are used. 

310 scores: A `Tensor` of type `float32`. 

311 A 3-D float tensor of shape `[batch_size, num_boxes, num_classes]` 

312 representing a single score corresponding to each box (each row of boxes). 

313 max_output_size_per_class: A `Tensor` of type `int32`. 

314 A scalar integer tensor representing the maximum number of 

315 boxes to be selected by non max suppression per class 

316 max_total_size: A `Tensor` of type `int32`. 

317 An int32 scalar representing the maximum number of boxes retained over all 

318 classes. Note that setting this value to a large number may result in OOM error 

319 depending on the system workload. 

320 iou_threshold: A `Tensor` of type `float32`. 

321 A 0-D float tensor representing the threshold for deciding whether 

322 boxes overlap too much with respect to IOU. 

323 score_threshold: A `Tensor` of type `float32`. 

324 A 0-D float tensor representing the threshold for deciding when to remove 

325 boxes based on score. 

326 pad_per_class: An optional `bool`. Defaults to `False`. 

327 If false, the output nmsed boxes, scores and classes 

328 are padded/clipped to `max_total_size`. If true, the 

329 output nmsed boxes, scores and classes are padded to be of length 

330 `max_size_per_class`*`num_classes`, unless it exceeds `max_total_size` in 

331 which case it is clipped to `max_total_size`. Defaults to false. 

332 clip_boxes: An optional `bool`. Defaults to `True`. 

333 If true, assume the box coordinates are between [0, 1] and clip the output boxes 

334 if they fall beyond [0, 1]. If false, do not do clipping and output the box 

335 coordinates as it is. 

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

337 

338 Returns: 

339 A tuple of `Tensor` objects (nmsed_boxes, nmsed_scores, nmsed_classes, valid_detections). 

340 

341 nmsed_boxes: A `Tensor` of type `float32`. 

342 nmsed_scores: A `Tensor` of type `float32`. 

343 nmsed_classes: A `Tensor` of type `float32`. 

344 valid_detections: A `Tensor` of type `int32`. 

345 """ 

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

347 tld = _ctx._thread_local_data 

348 if tld.is_eager: 

349 try: 

350 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

351 _ctx, "CombinedNonMaxSuppression", name, boxes, scores, 

352 max_output_size_per_class, max_total_size, iou_threshold, 

353 score_threshold, "pad_per_class", pad_per_class, "clip_boxes", 

354 clip_boxes) 

355 _result = _CombinedNonMaxSuppressionOutput._make(_result) 

356 return _result 

357 except _core._NotOkStatusException as e: 

358 _ops.raise_from_not_ok_status(e, name) 

359 except _core._FallbackException: 

360 pass 

361 try: 

362 return combined_non_max_suppression_eager_fallback( 

363 boxes, scores, max_output_size_per_class, max_total_size, 

364 iou_threshold, score_threshold, pad_per_class=pad_per_class, 

365 clip_boxes=clip_boxes, name=name, ctx=_ctx) 

366 except _core._SymbolicException: 

367 pass # Add nodes to the TensorFlow graph. 

368 # Add nodes to the TensorFlow graph. 

369 if pad_per_class is None: 

370 pad_per_class = False 

371 pad_per_class = _execute.make_bool(pad_per_class, "pad_per_class") 

372 if clip_boxes is None: 

373 clip_boxes = True 

374 clip_boxes = _execute.make_bool(clip_boxes, "clip_boxes") 

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

376 "CombinedNonMaxSuppression", boxes=boxes, scores=scores, 

377 max_output_size_per_class=max_output_size_per_class, 

378 max_total_size=max_total_size, 

379 iou_threshold=iou_threshold, 

380 score_threshold=score_threshold, 

381 pad_per_class=pad_per_class, 

382 clip_boxes=clip_boxes, name=name) 

383 _result = _outputs[:] 

384 if _execute.must_record_gradient(): 

385 _attrs = ("pad_per_class", _op._get_attr_bool("pad_per_class"), 

386 "clip_boxes", _op._get_attr_bool("clip_boxes")) 

387 _inputs_flat = _op.inputs 

388 _execute.record_gradient( 

389 "CombinedNonMaxSuppression", _inputs_flat, _attrs, _result) 

390 _result = _CombinedNonMaxSuppressionOutput._make(_result) 

391 return _result 

392 

393CombinedNonMaxSuppression = tf_export("raw_ops.CombinedNonMaxSuppression")(_ops.to_raw_op(combined_non_max_suppression)) 

394 

395 

396def combined_non_max_suppression_eager_fallback(boxes, scores, max_output_size_per_class, max_total_size, iou_threshold, score_threshold, pad_per_class, clip_boxes, name, ctx): 

397 if pad_per_class is None: 

398 pad_per_class = False 

399 pad_per_class = _execute.make_bool(pad_per_class, "pad_per_class") 

400 if clip_boxes is None: 

401 clip_boxes = True 

402 clip_boxes = _execute.make_bool(clip_boxes, "clip_boxes") 

403 boxes = _ops.convert_to_tensor(boxes, _dtypes.float32) 

404 scores = _ops.convert_to_tensor(scores, _dtypes.float32) 

405 max_output_size_per_class = _ops.convert_to_tensor(max_output_size_per_class, _dtypes.int32) 

406 max_total_size = _ops.convert_to_tensor(max_total_size, _dtypes.int32) 

407 iou_threshold = _ops.convert_to_tensor(iou_threshold, _dtypes.float32) 

408 score_threshold = _ops.convert_to_tensor(score_threshold, _dtypes.float32) 

409 _inputs_flat = [boxes, scores, max_output_size_per_class, max_total_size, iou_threshold, score_threshold] 

410 _attrs = ("pad_per_class", pad_per_class, "clip_boxes", clip_boxes) 

411 _result = _execute.execute(b"CombinedNonMaxSuppression", 4, 

412 inputs=_inputs_flat, attrs=_attrs, ctx=ctx, 

413 name=name) 

414 if _execute.must_record_gradient(): 

415 _execute.record_gradient( 

416 "CombinedNonMaxSuppression", _inputs_flat, _attrs, _result) 

417 _result = _CombinedNonMaxSuppressionOutput._make(_result) 

418 return _result 

419 

420 

421def crop_and_resize(image, boxes, box_ind, crop_size, method="bilinear", extrapolation_value=0, name=None): 

422 r"""Extracts crops from the input image tensor and resizes them. 

423 

424 Extracts crops from the input image tensor and resizes them using bilinear 

425 sampling or nearest neighbor sampling (possibly with aspect ratio change) to a 

426 common output size specified by `crop_size`. This is more general than the 

427 `crop_to_bounding_box` op which extracts a fixed size slice from the input image 

428 and does not allow resizing or aspect ratio change. 

429 

430 Returns a tensor with `crops` from the input `image` at positions defined at the 

431 bounding box locations in `boxes`. The cropped boxes are all resized (with 

432 bilinear or nearest neighbor interpolation) to a fixed 

433 `size = [crop_height, crop_width]`. The result is a 4-D tensor 

434 `[num_boxes, crop_height, crop_width, depth]`. The resizing is corner aligned. 

435 In particular, if `boxes = [[0, 0, 1, 1]]`, the method will give identical 

436 results to using `tf.image.resize_bilinear()` or 

437 `tf.image.resize_nearest_neighbor()`(depends on the `method` argument) with 

438 `align_corners=True`. 

439 

440 Args: 

441 image: A `Tensor`. Must be one of the following types: `uint8`, `uint16`, `int8`, `int16`, `int32`, `int64`, `half`, `float32`, `float64`. 

442 A 4-D tensor of shape `[batch, image_height, image_width, depth]`. 

443 Both `image_height` and `image_width` need to be positive. 

444 boxes: A `Tensor` of type `float32`. 

445 A 2-D tensor of shape `[num_boxes, 4]`. The `i`-th row of the tensor 

446 specifies the coordinates of a box in the `box_ind[i]` image and is specified 

447 in normalized coordinates `[y1, x1, y2, x2]`. A normalized coordinate value of 

448 `y` is mapped to the image coordinate at `y * (image_height - 1)`, so as the 

449 `[0, 1]` interval of normalized image height is mapped to 

450 `[0, image_height - 1]` in image height coordinates. We do allow `y1` > `y2`, in 

451 which case the sampled crop is an up-down flipped version of the original 

452 image. The width dimension is treated similarly. Normalized coordinates 

453 outside the `[0, 1]` range are allowed, in which case we use 

454 `extrapolation_value` to extrapolate the input image values. 

455 box_ind: A `Tensor` of type `int32`. 

456 A 1-D tensor of shape `[num_boxes]` with int32 values in `[0, batch)`. 

457 The value of `box_ind[i]` specifies the image that the `i`-th box refers to. 

458 crop_size: A `Tensor` of type `int32`. 

459 A 1-D tensor of 2 elements, `size = [crop_height, crop_width]`. All 

460 cropped image patches are resized to this size. The aspect ratio of the image 

461 content is not preserved. Both `crop_height` and `crop_width` need to be 

462 positive. 

463 method: An optional `string` from: `"bilinear", "nearest"`. Defaults to `"bilinear"`. 

464 A string specifying the sampling method for resizing. It can be either 

465 `"bilinear"` or `"nearest"` and default to `"bilinear"`. Currently two sampling 

466 methods are supported: Bilinear and Nearest Neighbor. 

467 extrapolation_value: An optional `float`. Defaults to `0`. 

468 Value used for extrapolation, when applicable. 

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

470 

471 Returns: 

472 A `Tensor` of type `float32`. 

473 """ 

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

475 tld = _ctx._thread_local_data 

476 if tld.is_eager: 

477 try: 

478 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

479 _ctx, "CropAndResize", name, image, boxes, box_ind, crop_size, 

480 "method", method, "extrapolation_value", extrapolation_value) 

481 return _result 

482 except _core._NotOkStatusException as e: 

483 _ops.raise_from_not_ok_status(e, name) 

484 except _core._FallbackException: 

485 pass 

486 try: 

487 return crop_and_resize_eager_fallback( 

488 image, boxes, box_ind, crop_size, method=method, 

489 extrapolation_value=extrapolation_value, name=name, ctx=_ctx) 

490 except _core._SymbolicException: 

491 pass # Add nodes to the TensorFlow graph. 

492 # Add nodes to the TensorFlow graph. 

493 if method is None: 

494 method = "bilinear" 

495 method = _execute.make_str(method, "method") 

496 if extrapolation_value is None: 

497 extrapolation_value = 0 

498 extrapolation_value = _execute.make_float(extrapolation_value, "extrapolation_value") 

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

500 "CropAndResize", image=image, boxes=boxes, box_ind=box_ind, 

501 crop_size=crop_size, method=method, 

502 extrapolation_value=extrapolation_value, name=name) 

503 _result = _outputs[:] 

504 if _execute.must_record_gradient(): 

505 _attrs = ("T", _op._get_attr_type("T"), "method", _op.get_attr("method"), 

506 "extrapolation_value", _op.get_attr("extrapolation_value")) 

507 _inputs_flat = _op.inputs 

508 _execute.record_gradient( 

509 "CropAndResize", _inputs_flat, _attrs, _result) 

510 _result, = _result 

511 return _result 

512 

513CropAndResize = tf_export("raw_ops.CropAndResize")(_ops.to_raw_op(crop_and_resize)) 

514 

515 

516def crop_and_resize_eager_fallback(image, boxes, box_ind, crop_size, method, extrapolation_value, name, ctx): 

517 if method is None: 

518 method = "bilinear" 

519 method = _execute.make_str(method, "method") 

520 if extrapolation_value is None: 

521 extrapolation_value = 0 

522 extrapolation_value = _execute.make_float(extrapolation_value, "extrapolation_value") 

523 _attr_T, (image,) = _execute.args_to_matching_eager([image], ctx, [_dtypes.uint8, _dtypes.uint16, _dtypes.int8, _dtypes.int16, _dtypes.int32, _dtypes.int64, _dtypes.half, _dtypes.float32, _dtypes.float64, ]) 

524 boxes = _ops.convert_to_tensor(boxes, _dtypes.float32) 

525 box_ind = _ops.convert_to_tensor(box_ind, _dtypes.int32) 

526 crop_size = _ops.convert_to_tensor(crop_size, _dtypes.int32) 

527 _inputs_flat = [image, boxes, box_ind, crop_size] 

528 _attrs = ("T", _attr_T, "method", method, "extrapolation_value", 

529 extrapolation_value) 

530 _result = _execute.execute(b"CropAndResize", 1, inputs=_inputs_flat, 

531 attrs=_attrs, ctx=ctx, name=name) 

532 if _execute.must_record_gradient(): 

533 _execute.record_gradient( 

534 "CropAndResize", _inputs_flat, _attrs, _result) 

535 _result, = _result 

536 return _result 

537 

538 

539def crop_and_resize_grad_boxes(grads, image, boxes, box_ind, method="bilinear", name=None): 

540 r"""Computes the gradient of the crop_and_resize op wrt the input boxes tensor. 

541 

542 Args: 

543 grads: A `Tensor` of type `float32`. 

544 A 4-D tensor of shape `[num_boxes, crop_height, crop_width, depth]`. 

545 image: A `Tensor`. Must be one of the following types: `uint8`, `uint16`, `int8`, `int16`, `int32`, `int64`, `half`, `float32`, `float64`. 

546 A 4-D tensor of shape `[batch, image_height, image_width, depth]`. 

547 Both `image_height` and `image_width` need to be positive. 

548 boxes: A `Tensor` of type `float32`. 

549 A 2-D tensor of shape `[num_boxes, 4]`. The `i`-th row of the tensor 

550 specifies the coordinates of a box in the `box_ind[i]` image and is specified 

551 in normalized coordinates `[y1, x1, y2, x2]`. A normalized coordinate value of 

552 `y` is mapped to the image coordinate at `y * (image_height - 1)`, so as the 

553 `[0, 1]` interval of normalized image height is mapped to 

554 `[0, image_height - 1] in image height coordinates. We do allow y1 > y2, in 

555 which case the sampled crop is an up-down flipped version of the original 

556 image. The width dimension is treated similarly. Normalized coordinates 

557 outside the `[0, 1]` range are allowed, in which case we use 

558 `extrapolation_value` to extrapolate the input image values. 

559 box_ind: A `Tensor` of type `int32`. 

560 A 1-D tensor of shape `[num_boxes]` with int32 values in `[0, batch)`. 

561 The value of `box_ind[i]` specifies the image that the `i`-th box refers to. 

562 method: An optional `string` from: `"bilinear"`. Defaults to `"bilinear"`. 

563 A string specifying the interpolation method. Only 'bilinear' is 

564 supported for now. 

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

566 

567 Returns: 

568 A `Tensor` of type `float32`. 

569 """ 

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

571 tld = _ctx._thread_local_data 

572 if tld.is_eager: 

573 try: 

574 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

575 _ctx, "CropAndResizeGradBoxes", name, grads, image, boxes, box_ind, 

576 "method", method) 

577 return _result 

578 except _core._NotOkStatusException as e: 

579 _ops.raise_from_not_ok_status(e, name) 

580 except _core._FallbackException: 

581 pass 

582 try: 

583 return crop_and_resize_grad_boxes_eager_fallback( 

584 grads, image, boxes, box_ind, method=method, name=name, ctx=_ctx) 

585 except _core._SymbolicException: 

586 pass # Add nodes to the TensorFlow graph. 

587 # Add nodes to the TensorFlow graph. 

588 if method is None: 

589 method = "bilinear" 

590 method = _execute.make_str(method, "method") 

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

592 "CropAndResizeGradBoxes", grads=grads, image=image, boxes=boxes, 

593 box_ind=box_ind, method=method, name=name) 

594 _result = _outputs[:] 

595 if _execute.must_record_gradient(): 

596 _attrs = ("T", _op._get_attr_type("T"), "method", _op.get_attr("method")) 

597 _inputs_flat = _op.inputs 

598 _execute.record_gradient( 

599 "CropAndResizeGradBoxes", _inputs_flat, _attrs, _result) 

600 _result, = _result 

601 return _result 

602 

603CropAndResizeGradBoxes = tf_export("raw_ops.CropAndResizeGradBoxes")(_ops.to_raw_op(crop_and_resize_grad_boxes)) 

604 

605 

606def crop_and_resize_grad_boxes_eager_fallback(grads, image, boxes, box_ind, method, name, ctx): 

607 if method is None: 

608 method = "bilinear" 

609 method = _execute.make_str(method, "method") 

610 _attr_T, (image,) = _execute.args_to_matching_eager([image], ctx, [_dtypes.uint8, _dtypes.uint16, _dtypes.int8, _dtypes.int16, _dtypes.int32, _dtypes.int64, _dtypes.half, _dtypes.float32, _dtypes.float64, ]) 

611 grads = _ops.convert_to_tensor(grads, _dtypes.float32) 

612 boxes = _ops.convert_to_tensor(boxes, _dtypes.float32) 

613 box_ind = _ops.convert_to_tensor(box_ind, _dtypes.int32) 

614 _inputs_flat = [grads, image, boxes, box_ind] 

615 _attrs = ("T", _attr_T, "method", method) 

616 _result = _execute.execute(b"CropAndResizeGradBoxes", 1, 

617 inputs=_inputs_flat, attrs=_attrs, ctx=ctx, 

618 name=name) 

619 if _execute.must_record_gradient(): 

620 _execute.record_gradient( 

621 "CropAndResizeGradBoxes", _inputs_flat, _attrs, _result) 

622 _result, = _result 

623 return _result 

624 

625 

626def crop_and_resize_grad_image(grads, boxes, box_ind, image_size, T, method="bilinear", name=None): 

627 r"""Computes the gradient of the crop_and_resize op wrt the input image tensor. 

628 

629 Args: 

630 grads: A `Tensor` of type `float32`. 

631 A 4-D tensor of shape `[num_boxes, crop_height, crop_width, depth]`. 

632 boxes: A `Tensor` of type `float32`. 

633 A 2-D tensor of shape `[num_boxes, 4]`. The `i`-th row of the tensor 

634 specifies the coordinates of a box in the `box_ind[i]` image and is specified 

635 in normalized coordinates `[y1, x1, y2, x2]`. A normalized coordinate value of 

636 `y` is mapped to the image coordinate at `y * (image_height - 1)`, so as the 

637 `[0, 1]` interval of normalized image height is mapped to 

638 `[0, image_height - 1] in image height coordinates. We do allow y1 > y2, in 

639 which case the sampled crop is an up-down flipped version of the original 

640 image. The width dimension is treated similarly. Normalized coordinates 

641 outside the `[0, 1]` range are allowed, in which case we use 

642 `extrapolation_value` to extrapolate the input image values. 

643 box_ind: A `Tensor` of type `int32`. 

644 A 1-D tensor of shape `[num_boxes]` with int32 values in `[0, batch)`. 

645 The value of `box_ind[i]` specifies the image that the `i`-th box refers to. 

646 image_size: A `Tensor` of type `int32`. 

647 A 1-D tensor with value `[batch, image_height, image_width, depth]` 

648 containing the original image size. Both `image_height` and `image_width` need 

649 to be positive. 

650 T: A `tf.DType` from: `tf.float32, tf.half, tf.float64`. 

651 method: An optional `string` from: `"bilinear", "nearest"`. Defaults to `"bilinear"`. 

652 A string specifying the interpolation method. Only 'bilinear' is 

653 supported for now. 

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

655 

656 Returns: 

657 A `Tensor` of type `T`. 

658 """ 

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

660 tld = _ctx._thread_local_data 

661 if tld.is_eager: 

662 try: 

663 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

664 _ctx, "CropAndResizeGradImage", name, grads, boxes, box_ind, 

665 image_size, "T", T, "method", method) 

666 return _result 

667 except _core._NotOkStatusException as e: 

668 _ops.raise_from_not_ok_status(e, name) 

669 except _core._FallbackException: 

670 pass 

671 try: 

672 return crop_and_resize_grad_image_eager_fallback( 

673 grads, boxes, box_ind, image_size, T=T, method=method, name=name, 

674 ctx=_ctx) 

675 except _core._SymbolicException: 

676 pass # Add nodes to the TensorFlow graph. 

677 # Add nodes to the TensorFlow graph. 

678 T = _execute.make_type(T, "T") 

679 if method is None: 

680 method = "bilinear" 

681 method = _execute.make_str(method, "method") 

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

683 "CropAndResizeGradImage", grads=grads, boxes=boxes, box_ind=box_ind, 

684 image_size=image_size, T=T, method=method, 

685 name=name) 

686 _result = _outputs[:] 

687 if _execute.must_record_gradient(): 

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

689 _inputs_flat = _op.inputs 

690 _execute.record_gradient( 

691 "CropAndResizeGradImage", _inputs_flat, _attrs, _result) 

692 _result, = _result 

693 return _result 

694 

695CropAndResizeGradImage = tf_export("raw_ops.CropAndResizeGradImage")(_ops.to_raw_op(crop_and_resize_grad_image)) 

696 

697 

698def crop_and_resize_grad_image_eager_fallback(grads, boxes, box_ind, image_size, T, method, name, ctx): 

699 T = _execute.make_type(T, "T") 

700 if method is None: 

701 method = "bilinear" 

702 method = _execute.make_str(method, "method") 

703 grads = _ops.convert_to_tensor(grads, _dtypes.float32) 

704 boxes = _ops.convert_to_tensor(boxes, _dtypes.float32) 

705 box_ind = _ops.convert_to_tensor(box_ind, _dtypes.int32) 

706 image_size = _ops.convert_to_tensor(image_size, _dtypes.int32) 

707 _inputs_flat = [grads, boxes, box_ind, image_size] 

708 _attrs = ("T", T, "method", method) 

709 _result = _execute.execute(b"CropAndResizeGradImage", 1, 

710 inputs=_inputs_flat, attrs=_attrs, ctx=ctx, 

711 name=name) 

712 if _execute.must_record_gradient(): 

713 _execute.record_gradient( 

714 "CropAndResizeGradImage", _inputs_flat, _attrs, _result) 

715 _result, = _result 

716 return _result 

717 

718 

719def decode_and_crop_jpeg(contents, crop_window, channels=0, ratio=1, fancy_upscaling=True, try_recover_truncated=False, acceptable_fraction=1, dct_method="", name=None): 

720 r"""Decode and Crop a JPEG-encoded image to a uint8 tensor. 

721 

722 The attr `channels` indicates the desired number of color channels for the 

723 decoded image. 

724 

725 Accepted values are: 

726 

727 * 0: Use the number of channels in the JPEG-encoded image. 

728 * 1: output a grayscale image. 

729 * 3: output an RGB image. 

730 

731 If needed, the JPEG-encoded image is transformed to match the requested number 

732 of color channels. 

733 

734 The attr `ratio` allows downscaling the image by an integer factor during 

735 decoding. Allowed values are: 1, 2, 4, and 8. This is much faster than 

736 downscaling the image later. 

737 

738 

739 It is equivalent to a combination of decode and crop, but much faster by only 

740 decoding partial jpeg image. 

741 

742 Args: 

743 contents: A `Tensor` of type `string`. 0-D. The JPEG-encoded image. 

744 crop_window: A `Tensor` of type `int32`. 

745 1-D. The crop window: [crop_y, crop_x, crop_height, crop_width]. 

746 channels: An optional `int`. Defaults to `0`. 

747 Number of color channels for the decoded image. 

748 ratio: An optional `int`. Defaults to `1`. Downscaling ratio. 

749 fancy_upscaling: An optional `bool`. Defaults to `True`. 

750 If true use a slower but nicer upscaling of the 

751 chroma planes (yuv420/422 only). 

752 try_recover_truncated: An optional `bool`. Defaults to `False`. 

753 If true try to recover an image from truncated input. 

754 acceptable_fraction: An optional `float`. Defaults to `1`. 

755 The minimum required fraction of lines before a truncated 

756 input is accepted. 

757 dct_method: An optional `string`. Defaults to `""`. 

758 string specifying a hint about the algorithm used for 

759 decompression. Defaults to "" which maps to a system-specific 

760 default. Currently valid values are ["INTEGER_FAST", 

761 "INTEGER_ACCURATE"]. The hint may be ignored (e.g., the internal 

762 jpeg library changes to a version that does not have that specific 

763 option.) 

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

765 

766 Returns: 

767 A `Tensor` of type `uint8`. 

768 """ 

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

770 tld = _ctx._thread_local_data 

771 if tld.is_eager: 

772 try: 

773 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

774 _ctx, "DecodeAndCropJpeg", name, contents, crop_window, "channels", 

775 channels, "ratio", ratio, "fancy_upscaling", fancy_upscaling, 

776 "try_recover_truncated", try_recover_truncated, "acceptable_fraction", 

777 acceptable_fraction, "dct_method", dct_method) 

778 return _result 

779 except _core._NotOkStatusException as e: 

780 _ops.raise_from_not_ok_status(e, name) 

781 except _core._FallbackException: 

782 pass 

783 try: 

784 return decode_and_crop_jpeg_eager_fallback( 

785 contents, crop_window, channels=channels, ratio=ratio, 

786 fancy_upscaling=fancy_upscaling, 

787 try_recover_truncated=try_recover_truncated, 

788 acceptable_fraction=acceptable_fraction, dct_method=dct_method, 

789 name=name, ctx=_ctx) 

790 except _core._SymbolicException: 

791 pass # Add nodes to the TensorFlow graph. 

792 # Add nodes to the TensorFlow graph. 

793 if channels is None: 

794 channels = 0 

795 channels = _execute.make_int(channels, "channels") 

796 if ratio is None: 

797 ratio = 1 

798 ratio = _execute.make_int(ratio, "ratio") 

799 if fancy_upscaling is None: 

800 fancy_upscaling = True 

801 fancy_upscaling = _execute.make_bool(fancy_upscaling, "fancy_upscaling") 

802 if try_recover_truncated is None: 

803 try_recover_truncated = False 

804 try_recover_truncated = _execute.make_bool(try_recover_truncated, "try_recover_truncated") 

805 if acceptable_fraction is None: 

806 acceptable_fraction = 1 

807 acceptable_fraction = _execute.make_float(acceptable_fraction, "acceptable_fraction") 

808 if dct_method is None: 

809 dct_method = "" 

810 dct_method = _execute.make_str(dct_method, "dct_method") 

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

812 "DecodeAndCropJpeg", contents=contents, crop_window=crop_window, 

813 channels=channels, ratio=ratio, 

814 fancy_upscaling=fancy_upscaling, 

815 try_recover_truncated=try_recover_truncated, 

816 acceptable_fraction=acceptable_fraction, 

817 dct_method=dct_method, name=name) 

818 _result = _outputs[:] 

819 if _execute.must_record_gradient(): 

820 _attrs = ("channels", _op._get_attr_int("channels"), "ratio", 

821 _op._get_attr_int("ratio"), "fancy_upscaling", 

822 _op._get_attr_bool("fancy_upscaling"), "try_recover_truncated", 

823 _op._get_attr_bool("try_recover_truncated"), 

824 "acceptable_fraction", _op.get_attr("acceptable_fraction"), 

825 "dct_method", _op.get_attr("dct_method")) 

826 _inputs_flat = _op.inputs 

827 _execute.record_gradient( 

828 "DecodeAndCropJpeg", _inputs_flat, _attrs, _result) 

829 _result, = _result 

830 return _result 

831 

832DecodeAndCropJpeg = tf_export("raw_ops.DecodeAndCropJpeg")(_ops.to_raw_op(decode_and_crop_jpeg)) 

833 

834 

835def decode_and_crop_jpeg_eager_fallback(contents, crop_window, channels, ratio, fancy_upscaling, try_recover_truncated, acceptable_fraction, dct_method, name, ctx): 

836 if channels is None: 

837 channels = 0 

838 channels = _execute.make_int(channels, "channels") 

839 if ratio is None: 

840 ratio = 1 

841 ratio = _execute.make_int(ratio, "ratio") 

842 if fancy_upscaling is None: 

843 fancy_upscaling = True 

844 fancy_upscaling = _execute.make_bool(fancy_upscaling, "fancy_upscaling") 

845 if try_recover_truncated is None: 

846 try_recover_truncated = False 

847 try_recover_truncated = _execute.make_bool(try_recover_truncated, "try_recover_truncated") 

848 if acceptable_fraction is None: 

849 acceptable_fraction = 1 

850 acceptable_fraction = _execute.make_float(acceptable_fraction, "acceptable_fraction") 

851 if dct_method is None: 

852 dct_method = "" 

853 dct_method = _execute.make_str(dct_method, "dct_method") 

854 contents = _ops.convert_to_tensor(contents, _dtypes.string) 

855 crop_window = _ops.convert_to_tensor(crop_window, _dtypes.int32) 

856 _inputs_flat = [contents, crop_window] 

857 _attrs = ("channels", channels, "ratio", ratio, "fancy_upscaling", 

858 fancy_upscaling, "try_recover_truncated", try_recover_truncated, 

859 "acceptable_fraction", acceptable_fraction, "dct_method", dct_method) 

860 _result = _execute.execute(b"DecodeAndCropJpeg", 1, inputs=_inputs_flat, 

861 attrs=_attrs, ctx=ctx, name=name) 

862 if _execute.must_record_gradient(): 

863 _execute.record_gradient( 

864 "DecodeAndCropJpeg", _inputs_flat, _attrs, _result) 

865 _result, = _result 

866 return _result 

867 

868 

869def decode_bmp(contents, channels=0, name=None): 

870 r"""Decode the first frame of a BMP-encoded image to a uint8 tensor. 

871 

872 The attr `channels` indicates the desired number of color channels for the 

873 decoded image. 

874 

875 Accepted values are: 

876 

877 * 0: Use the number of channels in the BMP-encoded image. 

878 * 3: output an RGB image. 

879 * 4: output an RGBA image. 

880 

881 Args: 

882 contents: A `Tensor` of type `string`. 0-D. The BMP-encoded image. 

883 channels: An optional `int`. Defaults to `0`. 

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

885 

886 Returns: 

887 A `Tensor` of type `uint8`. 

888 """ 

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

890 tld = _ctx._thread_local_data 

891 if tld.is_eager: 

892 try: 

893 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

894 _ctx, "DecodeBmp", name, contents, "channels", channels) 

895 return _result 

896 except _core._NotOkStatusException as e: 

897 _ops.raise_from_not_ok_status(e, name) 

898 except _core._FallbackException: 

899 pass 

900 try: 

901 return decode_bmp_eager_fallback( 

902 contents, channels=channels, name=name, ctx=_ctx) 

903 except _core._SymbolicException: 

904 pass # Add nodes to the TensorFlow graph. 

905 # Add nodes to the TensorFlow graph. 

906 if channels is None: 

907 channels = 0 

908 channels = _execute.make_int(channels, "channels") 

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

910 "DecodeBmp", contents=contents, channels=channels, name=name) 

911 _result = _outputs[:] 

912 if _execute.must_record_gradient(): 

913 _attrs = ("channels", _op._get_attr_int("channels")) 

914 _inputs_flat = _op.inputs 

915 _execute.record_gradient( 

916 "DecodeBmp", _inputs_flat, _attrs, _result) 

917 _result, = _result 

918 return _result 

919 

920DecodeBmp = tf_export("raw_ops.DecodeBmp")(_ops.to_raw_op(decode_bmp)) 

921 

922 

923def decode_bmp_eager_fallback(contents, channels, name, ctx): 

924 if channels is None: 

925 channels = 0 

926 channels = _execute.make_int(channels, "channels") 

927 contents = _ops.convert_to_tensor(contents, _dtypes.string) 

928 _inputs_flat = [contents] 

929 _attrs = ("channels", channels) 

930 _result = _execute.execute(b"DecodeBmp", 1, inputs=_inputs_flat, 

931 attrs=_attrs, ctx=ctx, name=name) 

932 if _execute.must_record_gradient(): 

933 _execute.record_gradient( 

934 "DecodeBmp", _inputs_flat, _attrs, _result) 

935 _result, = _result 

936 return _result 

937 

938 

939def decode_gif(contents, name=None): 

940 r"""Decode the frame(s) of a GIF-encoded image to a uint8 tensor. 

941 

942 GIF images with frame or transparency compression are not supported. 

943 On Linux and MacOS systems, convert animated GIFs from compressed to 

944 uncompressed by running: 

945 

946 convert $src.gif -coalesce $dst.gif 

947 

948 This op also supports decoding JPEGs and PNGs, though it is cleaner to use 

949 `tf.io.decode_image`. 

950 

951 Args: 

952 contents: A `Tensor` of type `string`. 0-D. The GIF-encoded image. 

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

954 

955 Returns: 

956 A `Tensor` of type `uint8`. 

957 """ 

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

959 tld = _ctx._thread_local_data 

960 if tld.is_eager: 

961 try: 

962 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

963 _ctx, "DecodeGif", name, contents) 

964 return _result 

965 except _core._NotOkStatusException as e: 

966 _ops.raise_from_not_ok_status(e, name) 

967 except _core._FallbackException: 

968 pass 

969 try: 

970 return decode_gif_eager_fallback( 

971 contents, name=name, ctx=_ctx) 

972 except _core._SymbolicException: 

973 pass # Add nodes to the TensorFlow graph. 

974 # Add nodes to the TensorFlow graph. 

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

976 "DecodeGif", contents=contents, name=name) 

977 _result = _outputs[:] 

978 if _execute.must_record_gradient(): 

979 _attrs = () 

980 _inputs_flat = _op.inputs 

981 _execute.record_gradient( 

982 "DecodeGif", _inputs_flat, _attrs, _result) 

983 _result, = _result 

984 return _result 

985 

986DecodeGif = tf_export("raw_ops.DecodeGif")(_ops.to_raw_op(decode_gif)) 

987 

988 

989def decode_gif_eager_fallback(contents, name, ctx): 

990 contents = _ops.convert_to_tensor(contents, _dtypes.string) 

991 _inputs_flat = [contents] 

992 _attrs = None 

993 _result = _execute.execute(b"DecodeGif", 1, inputs=_inputs_flat, 

994 attrs=_attrs, ctx=ctx, name=name) 

995 if _execute.must_record_gradient(): 

996 _execute.record_gradient( 

997 "DecodeGif", _inputs_flat, _attrs, _result) 

998 _result, = _result 

999 return _result 

1000 

1001 

1002def decode_image(contents, channels=0, dtype=_dtypes.uint8, expand_animations=True, name=None): 

1003 r"""Function for decode_bmp, decode_gif, decode_jpeg, and decode_png. 

1004 

1005 Detects whether an image is a BMP, GIF, JPEG, or PNG, and performs the 

1006 appropriate operation to convert the input bytes string into a Tensor of type 

1007 dtype. 

1008 

1009 *NOTE*: decode_gif returns a 4-D array [num_frames, height, width, 3], as 

1010 opposed to decode_bmp, decode_jpeg and decode_png, which return 3-D arrays 

1011 [height, width, num_channels]. Make sure to take this into account when 

1012 constructing your graph if you are intermixing GIF files with BMP, JPEG, and/or 

1013 PNG files. Alternately, set the expand_animations argument of this function to 

1014 False, in which case the op will return 3-dimensional tensors and will truncate 

1015 animated GIF files to the first frame. 

1016 

1017 *NOTE*: If the first frame of an animated GIF does not occupy the entire 

1018 canvas (maximum frame width x maximum frame height), then it fills the 

1019 unoccupied areas (in the first frame) with zeros (black). For frames after the 

1020 first frame that does not occupy the entire canvas, it uses the previous 

1021 frame to fill the unoccupied areas. 

1022 

1023 Args: 

1024 contents: A `Tensor` of type `string`. 0-D. The encoded image bytes. 

1025 channels: An optional `int`. Defaults to `0`. 

1026 Number of color channels for the decoded image. 

1027 dtype: An optional `tf.DType` from: `tf.uint8, tf.uint16, tf.float32`. Defaults to `tf.uint8`. 

1028 The desired DType of the returned Tensor. 

1029 expand_animations: An optional `bool`. Defaults to `True`. 

1030 Controls the output shape of the returned op. If True, the returned op will 

1031 produce a 3-D tensor for PNG, JPEG, and BMP files; and a 4-D tensor for all 

1032 GIFs, whether animated or not. If, False, the returned op will produce a 3-D 

1033 tensor for all file types and will truncate animated GIFs to the first frame. 

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

1035 

1036 Returns: 

1037 A `Tensor` of type `dtype`. 

1038 """ 

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

1040 tld = _ctx._thread_local_data 

1041 if tld.is_eager: 

1042 try: 

1043 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

1044 _ctx, "DecodeImage", name, contents, "channels", channels, "dtype", 

1045 dtype, "expand_animations", expand_animations) 

1046 return _result 

1047 except _core._NotOkStatusException as e: 

1048 _ops.raise_from_not_ok_status(e, name) 

1049 except _core._FallbackException: 

1050 pass 

1051 try: 

1052 return decode_image_eager_fallback( 

1053 contents, channels=channels, dtype=dtype, 

1054 expand_animations=expand_animations, name=name, ctx=_ctx) 

1055 except _core._SymbolicException: 

1056 pass # Add nodes to the TensorFlow graph. 

1057 # Add nodes to the TensorFlow graph. 

1058 if channels is None: 

1059 channels = 0 

1060 channels = _execute.make_int(channels, "channels") 

1061 if dtype is None: 

1062 dtype = _dtypes.uint8 

1063 dtype = _execute.make_type(dtype, "dtype") 

1064 if expand_animations is None: 

1065 expand_animations = True 

1066 expand_animations = _execute.make_bool(expand_animations, "expand_animations") 

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

1068 "DecodeImage", contents=contents, channels=channels, dtype=dtype, 

1069 expand_animations=expand_animations, name=name) 

1070 _result = _outputs[:] 

1071 if _execute.must_record_gradient(): 

1072 _attrs = ("channels", _op._get_attr_int("channels"), "dtype", 

1073 _op._get_attr_type("dtype"), "expand_animations", 

1074 _op._get_attr_bool("expand_animations")) 

1075 _inputs_flat = _op.inputs 

1076 _execute.record_gradient( 

1077 "DecodeImage", _inputs_flat, _attrs, _result) 

1078 _result, = _result 

1079 return _result 

1080 

1081DecodeImage = tf_export("raw_ops.DecodeImage")(_ops.to_raw_op(decode_image)) 

1082 

1083 

1084def decode_image_eager_fallback(contents, channels, dtype, expand_animations, name, ctx): 

1085 if channels is None: 

1086 channels = 0 

1087 channels = _execute.make_int(channels, "channels") 

1088 if dtype is None: 

1089 dtype = _dtypes.uint8 

1090 dtype = _execute.make_type(dtype, "dtype") 

1091 if expand_animations is None: 

1092 expand_animations = True 

1093 expand_animations = _execute.make_bool(expand_animations, "expand_animations") 

1094 contents = _ops.convert_to_tensor(contents, _dtypes.string) 

1095 _inputs_flat = [contents] 

1096 _attrs = ("channels", channels, "dtype", dtype, "expand_animations", 

1097 expand_animations) 

1098 _result = _execute.execute(b"DecodeImage", 1, inputs=_inputs_flat, 

1099 attrs=_attrs, ctx=ctx, name=name) 

1100 if _execute.must_record_gradient(): 

1101 _execute.record_gradient( 

1102 "DecodeImage", _inputs_flat, _attrs, _result) 

1103 _result, = _result 

1104 return _result 

1105 

1106 

1107def decode_jpeg(contents, channels=0, ratio=1, fancy_upscaling=True, try_recover_truncated=False, acceptable_fraction=1, dct_method="", name=None): 

1108 r"""Decode a JPEG-encoded image to a uint8 tensor. 

1109 

1110 The attr `channels` indicates the desired number of color channels for the 

1111 decoded image. 

1112 

1113 Accepted values are: 

1114 

1115 * 0: Use the number of channels in the JPEG-encoded image. 

1116 * 1: output a grayscale image. 

1117 * 3: output an RGB image. 

1118 

1119 If needed, the JPEG-encoded image is transformed to match the requested number 

1120 of color channels. 

1121 

1122 The attr `ratio` allows downscaling the image by an integer factor during 

1123 decoding. Allowed values are: 1, 2, 4, and 8. This is much faster than 

1124 downscaling the image later. 

1125 

1126 

1127 This op also supports decoding PNGs and non-animated GIFs since the interface is 

1128 the same, though it is cleaner to use `tf.io.decode_image`. 

1129 

1130 Args: 

1131 contents: A `Tensor` of type `string`. 0-D. The JPEG-encoded image. 

1132 channels: An optional `int`. Defaults to `0`. 

1133 Number of color channels for the decoded image. 

1134 ratio: An optional `int`. Defaults to `1`. Downscaling ratio. 

1135 fancy_upscaling: An optional `bool`. Defaults to `True`. 

1136 If true use a slower but nicer upscaling of the 

1137 chroma planes (yuv420/422 only). 

1138 try_recover_truncated: An optional `bool`. Defaults to `False`. 

1139 If true try to recover an image from truncated input. 

1140 acceptable_fraction: An optional `float`. Defaults to `1`. 

1141 The minimum required fraction of lines before a truncated 

1142 input is accepted. 

1143 dct_method: An optional `string`. Defaults to `""`. 

1144 string specifying a hint about the algorithm used for 

1145 decompression. Defaults to "" which maps to a system-specific 

1146 default. Currently valid values are ["INTEGER_FAST", 

1147 "INTEGER_ACCURATE"]. The hint may be ignored (e.g., the internal 

1148 jpeg library changes to a version that does not have that specific 

1149 option.) 

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

1151 

1152 Returns: 

1153 A `Tensor` of type `uint8`. 

1154 """ 

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

1156 tld = _ctx._thread_local_data 

1157 if tld.is_eager: 

1158 try: 

1159 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

1160 _ctx, "DecodeJpeg", name, contents, "channels", channels, "ratio", 

1161 ratio, "fancy_upscaling", fancy_upscaling, "try_recover_truncated", 

1162 try_recover_truncated, "acceptable_fraction", acceptable_fraction, 

1163 "dct_method", dct_method) 

1164 return _result 

1165 except _core._NotOkStatusException as e: 

1166 _ops.raise_from_not_ok_status(e, name) 

1167 except _core._FallbackException: 

1168 pass 

1169 try: 

1170 return decode_jpeg_eager_fallback( 

1171 contents, channels=channels, ratio=ratio, 

1172 fancy_upscaling=fancy_upscaling, 

1173 try_recover_truncated=try_recover_truncated, 

1174 acceptable_fraction=acceptable_fraction, dct_method=dct_method, 

1175 name=name, ctx=_ctx) 

1176 except _core._SymbolicException: 

1177 pass # Add nodes to the TensorFlow graph. 

1178 # Add nodes to the TensorFlow graph. 

1179 if channels is None: 

1180 channels = 0 

1181 channels = _execute.make_int(channels, "channels") 

1182 if ratio is None: 

1183 ratio = 1 

1184 ratio = _execute.make_int(ratio, "ratio") 

1185 if fancy_upscaling is None: 

1186 fancy_upscaling = True 

1187 fancy_upscaling = _execute.make_bool(fancy_upscaling, "fancy_upscaling") 

1188 if try_recover_truncated is None: 

1189 try_recover_truncated = False 

1190 try_recover_truncated = _execute.make_bool(try_recover_truncated, "try_recover_truncated") 

1191 if acceptable_fraction is None: 

1192 acceptable_fraction = 1 

1193 acceptable_fraction = _execute.make_float(acceptable_fraction, "acceptable_fraction") 

1194 if dct_method is None: 

1195 dct_method = "" 

1196 dct_method = _execute.make_str(dct_method, "dct_method") 

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

1198 "DecodeJpeg", contents=contents, channels=channels, ratio=ratio, 

1199 fancy_upscaling=fancy_upscaling, 

1200 try_recover_truncated=try_recover_truncated, 

1201 acceptable_fraction=acceptable_fraction, 

1202 dct_method=dct_method, name=name) 

1203 _result = _outputs[:] 

1204 if _execute.must_record_gradient(): 

1205 _attrs = ("channels", _op._get_attr_int("channels"), "ratio", 

1206 _op._get_attr_int("ratio"), "fancy_upscaling", 

1207 _op._get_attr_bool("fancy_upscaling"), "try_recover_truncated", 

1208 _op._get_attr_bool("try_recover_truncated"), 

1209 "acceptable_fraction", _op.get_attr("acceptable_fraction"), 

1210 "dct_method", _op.get_attr("dct_method")) 

1211 _inputs_flat = _op.inputs 

1212 _execute.record_gradient( 

1213 "DecodeJpeg", _inputs_flat, _attrs, _result) 

1214 _result, = _result 

1215 return _result 

1216 

1217DecodeJpeg = tf_export("raw_ops.DecodeJpeg")(_ops.to_raw_op(decode_jpeg)) 

1218 

1219 

1220def decode_jpeg_eager_fallback(contents, channels, ratio, fancy_upscaling, try_recover_truncated, acceptable_fraction, dct_method, name, ctx): 

1221 if channels is None: 

1222 channels = 0 

1223 channels = _execute.make_int(channels, "channels") 

1224 if ratio is None: 

1225 ratio = 1 

1226 ratio = _execute.make_int(ratio, "ratio") 

1227 if fancy_upscaling is None: 

1228 fancy_upscaling = True 

1229 fancy_upscaling = _execute.make_bool(fancy_upscaling, "fancy_upscaling") 

1230 if try_recover_truncated is None: 

1231 try_recover_truncated = False 

1232 try_recover_truncated = _execute.make_bool(try_recover_truncated, "try_recover_truncated") 

1233 if acceptable_fraction is None: 

1234 acceptable_fraction = 1 

1235 acceptable_fraction = _execute.make_float(acceptable_fraction, "acceptable_fraction") 

1236 if dct_method is None: 

1237 dct_method = "" 

1238 dct_method = _execute.make_str(dct_method, "dct_method") 

1239 contents = _ops.convert_to_tensor(contents, _dtypes.string) 

1240 _inputs_flat = [contents] 

1241 _attrs = ("channels", channels, "ratio", ratio, "fancy_upscaling", 

1242 fancy_upscaling, "try_recover_truncated", try_recover_truncated, 

1243 "acceptable_fraction", acceptable_fraction, "dct_method", dct_method) 

1244 _result = _execute.execute(b"DecodeJpeg", 1, inputs=_inputs_flat, 

1245 attrs=_attrs, ctx=ctx, name=name) 

1246 if _execute.must_record_gradient(): 

1247 _execute.record_gradient( 

1248 "DecodeJpeg", _inputs_flat, _attrs, _result) 

1249 _result, = _result 

1250 return _result 

1251 

1252 

1253def decode_png(contents, channels=0, dtype=_dtypes.uint8, name=None): 

1254 r"""Decode a PNG-encoded image to a uint8 or uint16 tensor. 

1255 

1256 The attr `channels` indicates the desired number of color channels for the 

1257 decoded image. 

1258 

1259 Accepted values are: 

1260 

1261 * 0: Use the number of channels in the PNG-encoded image. 

1262 * 1: output a grayscale image. 

1263 * 3: output an RGB image. 

1264 * 4: output an RGBA image. 

1265 

1266 If needed, the PNG-encoded image is transformed to match the requested number 

1267 of color channels. 

1268 

1269 This op also supports decoding JPEGs and non-animated GIFs since the interface 

1270 is the same, though it is cleaner to use `tf.io.decode_image`. 

1271 

1272 Args: 

1273 contents: A `Tensor` of type `string`. 0-D. The PNG-encoded image. 

1274 channels: An optional `int`. Defaults to `0`. 

1275 Number of color channels for the decoded image. 

1276 dtype: An optional `tf.DType` from: `tf.uint8, tf.uint16`. Defaults to `tf.uint8`. 

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

1278 

1279 Returns: 

1280 A `Tensor` of type `dtype`. 

1281 """ 

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

1283 tld = _ctx._thread_local_data 

1284 if tld.is_eager: 

1285 try: 

1286 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

1287 _ctx, "DecodePng", name, contents, "channels", channels, "dtype", 

1288 dtype) 

1289 return _result 

1290 except _core._NotOkStatusException as e: 

1291 _ops.raise_from_not_ok_status(e, name) 

1292 except _core._FallbackException: 

1293 pass 

1294 try: 

1295 return decode_png_eager_fallback( 

1296 contents, channels=channels, dtype=dtype, name=name, ctx=_ctx) 

1297 except _core._SymbolicException: 

1298 pass # Add nodes to the TensorFlow graph. 

1299 # Add nodes to the TensorFlow graph. 

1300 if channels is None: 

1301 channels = 0 

1302 channels = _execute.make_int(channels, "channels") 

1303 if dtype is None: 

1304 dtype = _dtypes.uint8 

1305 dtype = _execute.make_type(dtype, "dtype") 

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

1307 "DecodePng", contents=contents, channels=channels, dtype=dtype, 

1308 name=name) 

1309 _result = _outputs[:] 

1310 if _execute.must_record_gradient(): 

1311 _attrs = ("channels", _op._get_attr_int("channels"), "dtype", 

1312 _op._get_attr_type("dtype")) 

1313 _inputs_flat = _op.inputs 

1314 _execute.record_gradient( 

1315 "DecodePng", _inputs_flat, _attrs, _result) 

1316 _result, = _result 

1317 return _result 

1318 

1319DecodePng = tf_export("raw_ops.DecodePng")(_ops.to_raw_op(decode_png)) 

1320 

1321 

1322def decode_png_eager_fallback(contents, channels, dtype, name, ctx): 

1323 if channels is None: 

1324 channels = 0 

1325 channels = _execute.make_int(channels, "channels") 

1326 if dtype is None: 

1327 dtype = _dtypes.uint8 

1328 dtype = _execute.make_type(dtype, "dtype") 

1329 contents = _ops.convert_to_tensor(contents, _dtypes.string) 

1330 _inputs_flat = [contents] 

1331 _attrs = ("channels", channels, "dtype", dtype) 

1332 _result = _execute.execute(b"DecodePng", 1, inputs=_inputs_flat, 

1333 attrs=_attrs, ctx=ctx, name=name) 

1334 if _execute.must_record_gradient(): 

1335 _execute.record_gradient( 

1336 "DecodePng", _inputs_flat, _attrs, _result) 

1337 _result, = _result 

1338 return _result 

1339 

1340 

1341def draw_bounding_boxes(images, boxes, name=None): 

1342 r"""Draw bounding boxes on a batch of images. 

1343 

1344 Outputs a copy of `images` but draws on top of the pixels zero or more bounding 

1345 boxes specified by the locations in `boxes`. The coordinates of the each 

1346 bounding box in `boxes` are encoded as `[y_min, x_min, y_max, x_max]`. The 

1347 bounding box coordinates are floats in `[0.0, 1.0]` relative to the width and 

1348 height of the underlying image. 

1349 

1350 For example, if an image is 100 x 200 pixels (height x width) and the bounding 

1351 box is `[0.1, 0.2, 0.5, 0.9]`, the upper-left and bottom-right coordinates of 

1352 the bounding box will be `(40, 10)` to `(180, 50)` (in (x,y) coordinates). 

1353 

1354 Parts of the bounding box may fall outside the image. 

1355 

1356 Args: 

1357 images: A `Tensor`. Must be one of the following types: `float32`, `half`. 

1358 4-D with shape `[batch, height, width, depth]`. A batch of images. 

1359 boxes: A `Tensor` of type `float32`. 

1360 3-D with shape `[batch, num_bounding_boxes, 4]` containing bounding 

1361 boxes. 

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

1363 

1364 Returns: 

1365 A `Tensor`. Has the same type as `images`. 

1366 """ 

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

1368 tld = _ctx._thread_local_data 

1369 if tld.is_eager: 

1370 try: 

1371 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

1372 _ctx, "DrawBoundingBoxes", name, images, boxes) 

1373 return _result 

1374 except _core._NotOkStatusException as e: 

1375 _ops.raise_from_not_ok_status(e, name) 

1376 except _core._FallbackException: 

1377 pass 

1378 try: 

1379 return draw_bounding_boxes_eager_fallback( 

1380 images, boxes, name=name, ctx=_ctx) 

1381 except _core._SymbolicException: 

1382 pass # Add nodes to the TensorFlow graph. 

1383 # Add nodes to the TensorFlow graph. 

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

1385 "DrawBoundingBoxes", images=images, boxes=boxes, name=name) 

1386 _result = _outputs[:] 

1387 if _execute.must_record_gradient(): 

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

1389 _inputs_flat = _op.inputs 

1390 _execute.record_gradient( 

1391 "DrawBoundingBoxes", _inputs_flat, _attrs, _result) 

1392 _result, = _result 

1393 return _result 

1394 

1395DrawBoundingBoxes = tf_export("raw_ops.DrawBoundingBoxes")(_ops.to_raw_op(draw_bounding_boxes)) 

1396 

1397 

1398def draw_bounding_boxes_eager_fallback(images, boxes, name, ctx): 

1399 _attr_T, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.float32, _dtypes.half, ], _dtypes.float32) 

1400 boxes = _ops.convert_to_tensor(boxes, _dtypes.float32) 

1401 _inputs_flat = [images, boxes] 

1402 _attrs = ("T", _attr_T) 

1403 _result = _execute.execute(b"DrawBoundingBoxes", 1, inputs=_inputs_flat, 

1404 attrs=_attrs, ctx=ctx, name=name) 

1405 if _execute.must_record_gradient(): 

1406 _execute.record_gradient( 

1407 "DrawBoundingBoxes", _inputs_flat, _attrs, _result) 

1408 _result, = _result 

1409 return _result 

1410 

1411 

1412def draw_bounding_boxes_v2(images, boxes, colors, name=None): 

1413 r"""Draw bounding boxes on a batch of images. 

1414 

1415 Outputs a copy of `images` but draws on top of the pixels zero or more bounding 

1416 boxes specified by the locations in `boxes`. The coordinates of the each 

1417 bounding box in `boxes` are encoded as `[y_min, x_min, y_max, x_max]`. The 

1418 bounding box coordinates are floats in `[0.0, 1.0]` relative to the width and 

1419 height of the underlying image. 

1420 

1421 For example, if an image is 100 x 200 pixels (height x width) and the bounding 

1422 box is `[0.1, 0.2, 0.5, 0.9]`, the upper-left and bottom-right coordinates of 

1423 the bounding box will be `(40, 10)` to `(100, 50)` (in (x,y) coordinates). 

1424 

1425 Parts of the bounding box may fall outside the image. 

1426 

1427 Args: 

1428 images: A `Tensor`. Must be one of the following types: `float32`, `half`. 

1429 4-D with shape `[batch, height, width, depth]`. A batch of images. 

1430 boxes: A `Tensor` of type `float32`. 

1431 3-D with shape `[batch, num_bounding_boxes, 4]` containing bounding 

1432 boxes. 

1433 colors: A `Tensor` of type `float32`. 

1434 2-D. A list of RGBA colors to cycle through for the boxes. 

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

1436 

1437 Returns: 

1438 A `Tensor`. Has the same type as `images`. 

1439 """ 

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

1441 tld = _ctx._thread_local_data 

1442 if tld.is_eager: 

1443 try: 

1444 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

1445 _ctx, "DrawBoundingBoxesV2", name, images, boxes, colors) 

1446 return _result 

1447 except _core._NotOkStatusException as e: 

1448 _ops.raise_from_not_ok_status(e, name) 

1449 except _core._FallbackException: 

1450 pass 

1451 try: 

1452 return draw_bounding_boxes_v2_eager_fallback( 

1453 images, boxes, colors, name=name, ctx=_ctx) 

1454 except _core._SymbolicException: 

1455 pass # Add nodes to the TensorFlow graph. 

1456 # Add nodes to the TensorFlow graph. 

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

1458 "DrawBoundingBoxesV2", images=images, boxes=boxes, colors=colors, 

1459 name=name) 

1460 _result = _outputs[:] 

1461 if _execute.must_record_gradient(): 

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

1463 _inputs_flat = _op.inputs 

1464 _execute.record_gradient( 

1465 "DrawBoundingBoxesV2", _inputs_flat, _attrs, _result) 

1466 _result, = _result 

1467 return _result 

1468 

1469DrawBoundingBoxesV2 = tf_export("raw_ops.DrawBoundingBoxesV2")(_ops.to_raw_op(draw_bounding_boxes_v2)) 

1470 

1471 

1472def draw_bounding_boxes_v2_eager_fallback(images, boxes, colors, name, ctx): 

1473 _attr_T, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.float32, _dtypes.half, ], _dtypes.float32) 

1474 boxes = _ops.convert_to_tensor(boxes, _dtypes.float32) 

1475 colors = _ops.convert_to_tensor(colors, _dtypes.float32) 

1476 _inputs_flat = [images, boxes, colors] 

1477 _attrs = ("T", _attr_T) 

1478 _result = _execute.execute(b"DrawBoundingBoxesV2", 1, inputs=_inputs_flat, 

1479 attrs=_attrs, ctx=ctx, name=name) 

1480 if _execute.must_record_gradient(): 

1481 _execute.record_gradient( 

1482 "DrawBoundingBoxesV2", _inputs_flat, _attrs, _result) 

1483 _result, = _result 

1484 return _result 

1485 

1486 

1487def encode_jpeg(image, format="", quality=95, progressive=False, optimize_size=False, chroma_downsampling=True, density_unit="in", x_density=300, y_density=300, xmp_metadata="", name=None): 

1488 r"""JPEG-encode an image. 

1489 

1490 `image` is a 3-D uint8 Tensor of shape `[height, width, channels]`. 

1491 

1492 The attr `format` can be used to override the color format of the encoded 

1493 output. Values can be: 

1494 

1495 * `''`: Use a default format based on the number of channels in the image. 

1496 * `grayscale`: Output a grayscale JPEG image. The `channels` dimension 

1497 of `image` must be 1. 

1498 * `rgb`: Output an RGB JPEG image. The `channels` dimension 

1499 of `image` must be 3. 

1500 

1501 If `format` is not specified or is the empty string, a default format is picked 

1502 in function of the number of channels in `image`: 

1503 

1504 * 1: Output a grayscale image. 

1505 * 3: Output an RGB image. 

1506 

1507 Args: 

1508 image: A `Tensor` of type `uint8`. 

1509 3-D with shape `[height, width, channels]`. 

1510 format: An optional `string` from: `"", "grayscale", "rgb"`. Defaults to `""`. 

1511 Per pixel image format. 

1512 quality: An optional `int`. Defaults to `95`. 

1513 Quality of the compression from 0 to 100 (higher is better and slower). 

1514 progressive: An optional `bool`. Defaults to `False`. 

1515 If True, create a JPEG that loads progressively (coarse to fine). 

1516 optimize_size: An optional `bool`. Defaults to `False`. 

1517 If True, spend CPU/RAM to reduce size with no quality change. 

1518 chroma_downsampling: An optional `bool`. Defaults to `True`. 

1519 See http://en.wikipedia.org/wiki/Chroma_subsampling. 

1520 density_unit: An optional `string` from: `"in", "cm"`. Defaults to `"in"`. 

1521 Unit used to specify `x_density` and `y_density`: 

1522 pixels per inch (`'in'`) or centimeter (`'cm'`). 

1523 x_density: An optional `int`. Defaults to `300`. 

1524 Horizontal pixels per density unit. 

1525 y_density: An optional `int`. Defaults to `300`. 

1526 Vertical pixels per density unit. 

1527 xmp_metadata: An optional `string`. Defaults to `""`. 

1528 If not empty, embed this XMP metadata in the image header. 

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

1530 

1531 Returns: 

1532 A `Tensor` of type `string`. 

1533 """ 

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

1535 tld = _ctx._thread_local_data 

1536 if tld.is_eager: 

1537 try: 

1538 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

1539 _ctx, "EncodeJpeg", name, image, "format", format, "quality", quality, 

1540 "progressive", progressive, "optimize_size", optimize_size, 

1541 "chroma_downsampling", chroma_downsampling, "density_unit", 

1542 density_unit, "x_density", x_density, "y_density", y_density, 

1543 "xmp_metadata", xmp_metadata) 

1544 return _result 

1545 except _core._NotOkStatusException as e: 

1546 _ops.raise_from_not_ok_status(e, name) 

1547 except _core._FallbackException: 

1548 pass 

1549 try: 

1550 return encode_jpeg_eager_fallback( 

1551 image, format=format, quality=quality, progressive=progressive, 

1552 optimize_size=optimize_size, 

1553 chroma_downsampling=chroma_downsampling, density_unit=density_unit, 

1554 x_density=x_density, y_density=y_density, xmp_metadata=xmp_metadata, 

1555 name=name, ctx=_ctx) 

1556 except _core._SymbolicException: 

1557 pass # Add nodes to the TensorFlow graph. 

1558 # Add nodes to the TensorFlow graph. 

1559 if format is None: 

1560 format = "" 

1561 format = _execute.make_str(format, "format") 

1562 if quality is None: 

1563 quality = 95 

1564 quality = _execute.make_int(quality, "quality") 

1565 if progressive is None: 

1566 progressive = False 

1567 progressive = _execute.make_bool(progressive, "progressive") 

1568 if optimize_size is None: 

1569 optimize_size = False 

1570 optimize_size = _execute.make_bool(optimize_size, "optimize_size") 

1571 if chroma_downsampling is None: 

1572 chroma_downsampling = True 

1573 chroma_downsampling = _execute.make_bool(chroma_downsampling, "chroma_downsampling") 

1574 if density_unit is None: 

1575 density_unit = "in" 

1576 density_unit = _execute.make_str(density_unit, "density_unit") 

1577 if x_density is None: 

1578 x_density = 300 

1579 x_density = _execute.make_int(x_density, "x_density") 

1580 if y_density is None: 

1581 y_density = 300 

1582 y_density = _execute.make_int(y_density, "y_density") 

1583 if xmp_metadata is None: 

1584 xmp_metadata = "" 

1585 xmp_metadata = _execute.make_str(xmp_metadata, "xmp_metadata") 

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

1587 "EncodeJpeg", image=image, format=format, quality=quality, 

1588 progressive=progressive, optimize_size=optimize_size, 

1589 chroma_downsampling=chroma_downsampling, 

1590 density_unit=density_unit, x_density=x_density, 

1591 y_density=y_density, xmp_metadata=xmp_metadata, 

1592 name=name) 

1593 _result = _outputs[:] 

1594 if _execute.must_record_gradient(): 

1595 _attrs = ("format", _op.get_attr("format"), "quality", 

1596 _op._get_attr_int("quality"), "progressive", 

1597 _op._get_attr_bool("progressive"), "optimize_size", 

1598 _op._get_attr_bool("optimize_size"), "chroma_downsampling", 

1599 _op._get_attr_bool("chroma_downsampling"), "density_unit", 

1600 _op.get_attr("density_unit"), "x_density", 

1601 _op._get_attr_int("x_density"), "y_density", 

1602 _op._get_attr_int("y_density"), "xmp_metadata", 

1603 _op.get_attr("xmp_metadata")) 

1604 _inputs_flat = _op.inputs 

1605 _execute.record_gradient( 

1606 "EncodeJpeg", _inputs_flat, _attrs, _result) 

1607 _result, = _result 

1608 return _result 

1609 

1610EncodeJpeg = tf_export("raw_ops.EncodeJpeg")(_ops.to_raw_op(encode_jpeg)) 

1611 

1612 

1613def encode_jpeg_eager_fallback(image, format, quality, progressive, optimize_size, chroma_downsampling, density_unit, x_density, y_density, xmp_metadata, name, ctx): 

1614 if format is None: 

1615 format = "" 

1616 format = _execute.make_str(format, "format") 

1617 if quality is None: 

1618 quality = 95 

1619 quality = _execute.make_int(quality, "quality") 

1620 if progressive is None: 

1621 progressive = False 

1622 progressive = _execute.make_bool(progressive, "progressive") 

1623 if optimize_size is None: 

1624 optimize_size = False 

1625 optimize_size = _execute.make_bool(optimize_size, "optimize_size") 

1626 if chroma_downsampling is None: 

1627 chroma_downsampling = True 

1628 chroma_downsampling = _execute.make_bool(chroma_downsampling, "chroma_downsampling") 

1629 if density_unit is None: 

1630 density_unit = "in" 

1631 density_unit = _execute.make_str(density_unit, "density_unit") 

1632 if x_density is None: 

1633 x_density = 300 

1634 x_density = _execute.make_int(x_density, "x_density") 

1635 if y_density is None: 

1636 y_density = 300 

1637 y_density = _execute.make_int(y_density, "y_density") 

1638 if xmp_metadata is None: 

1639 xmp_metadata = "" 

1640 xmp_metadata = _execute.make_str(xmp_metadata, "xmp_metadata") 

1641 image = _ops.convert_to_tensor(image, _dtypes.uint8) 

1642 _inputs_flat = [image] 

1643 _attrs = ("format", format, "quality", quality, "progressive", progressive, 

1644 "optimize_size", optimize_size, "chroma_downsampling", chroma_downsampling, 

1645 "density_unit", density_unit, "x_density", x_density, "y_density", 

1646 y_density, "xmp_metadata", xmp_metadata) 

1647 _result = _execute.execute(b"EncodeJpeg", 1, inputs=_inputs_flat, 

1648 attrs=_attrs, ctx=ctx, name=name) 

1649 if _execute.must_record_gradient(): 

1650 _execute.record_gradient( 

1651 "EncodeJpeg", _inputs_flat, _attrs, _result) 

1652 _result, = _result 

1653 return _result 

1654 

1655 

1656def encode_jpeg_variable_quality(images, quality, name=None): 

1657 r"""JPEG encode input image with provided compression quality. 

1658 

1659 `image` is a 3-D uint8 Tensor of shape `[height, width, channels]`. 

1660 `quality` is an int32 jpeg compression quality value between 0 and 100. 

1661 

1662 Args: 

1663 images: A `Tensor` of type `uint8`. Images to adjust. At least 3-D. 

1664 quality: A `Tensor` of type `int32`. An int quality to encode to. 

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

1666 

1667 Returns: 

1668 A `Tensor` of type `string`. 

1669 """ 

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

1671 tld = _ctx._thread_local_data 

1672 if tld.is_eager: 

1673 try: 

1674 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

1675 _ctx, "EncodeJpegVariableQuality", name, images, quality) 

1676 return _result 

1677 except _core._NotOkStatusException as e: 

1678 _ops.raise_from_not_ok_status(e, name) 

1679 except _core._FallbackException: 

1680 pass 

1681 try: 

1682 return encode_jpeg_variable_quality_eager_fallback( 

1683 images, quality, name=name, ctx=_ctx) 

1684 except _core._SymbolicException: 

1685 pass # Add nodes to the TensorFlow graph. 

1686 # Add nodes to the TensorFlow graph. 

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

1688 "EncodeJpegVariableQuality", images=images, quality=quality, 

1689 name=name) 

1690 _result = _outputs[:] 

1691 if _execute.must_record_gradient(): 

1692 _attrs = () 

1693 _inputs_flat = _op.inputs 

1694 _execute.record_gradient( 

1695 "EncodeJpegVariableQuality", _inputs_flat, _attrs, _result) 

1696 _result, = _result 

1697 return _result 

1698 

1699EncodeJpegVariableQuality = tf_export("raw_ops.EncodeJpegVariableQuality")(_ops.to_raw_op(encode_jpeg_variable_quality)) 

1700 

1701 

1702def encode_jpeg_variable_quality_eager_fallback(images, quality, name, ctx): 

1703 images = _ops.convert_to_tensor(images, _dtypes.uint8) 

1704 quality = _ops.convert_to_tensor(quality, _dtypes.int32) 

1705 _inputs_flat = [images, quality] 

1706 _attrs = None 

1707 _result = _execute.execute(b"EncodeJpegVariableQuality", 1, 

1708 inputs=_inputs_flat, attrs=_attrs, ctx=ctx, 

1709 name=name) 

1710 if _execute.must_record_gradient(): 

1711 _execute.record_gradient( 

1712 "EncodeJpegVariableQuality", _inputs_flat, _attrs, _result) 

1713 _result, = _result 

1714 return _result 

1715 

1716 

1717def encode_png(image, compression=-1, name=None): 

1718 r"""PNG-encode an image. 

1719 

1720 `image` is a 3-D uint8 or uint16 Tensor of shape `[height, width, channels]` 

1721 where `channels` is: 

1722 

1723 * 1: for grayscale. 

1724 * 2: for grayscale + alpha. 

1725 * 3: for RGB. 

1726 * 4: for RGBA. 

1727 

1728 The ZLIB compression level, `compression`, can be -1 for the PNG-encoder 

1729 default or a value from 0 to 9. 9 is the highest compression level, generating 

1730 the smallest output, but is slower. 

1731 

1732 Args: 

1733 image: A `Tensor`. Must be one of the following types: `uint8`, `uint16`. 

1734 3-D with shape `[height, width, channels]`. 

1735 compression: An optional `int`. Defaults to `-1`. Compression level. 

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

1737 

1738 Returns: 

1739 A `Tensor` of type `string`. 

1740 """ 

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

1742 tld = _ctx._thread_local_data 

1743 if tld.is_eager: 

1744 try: 

1745 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

1746 _ctx, "EncodePng", name, image, "compression", compression) 

1747 return _result 

1748 except _core._NotOkStatusException as e: 

1749 _ops.raise_from_not_ok_status(e, name) 

1750 except _core._FallbackException: 

1751 pass 

1752 try: 

1753 return encode_png_eager_fallback( 

1754 image, compression=compression, name=name, ctx=_ctx) 

1755 except _core._SymbolicException: 

1756 pass # Add nodes to the TensorFlow graph. 

1757 # Add nodes to the TensorFlow graph. 

1758 if compression is None: 

1759 compression = -1 

1760 compression = _execute.make_int(compression, "compression") 

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

1762 "EncodePng", image=image, compression=compression, name=name) 

1763 _result = _outputs[:] 

1764 if _execute.must_record_gradient(): 

1765 _attrs = ("compression", _op._get_attr_int("compression"), "T", 

1766 _op._get_attr_type("T")) 

1767 _inputs_flat = _op.inputs 

1768 _execute.record_gradient( 

1769 "EncodePng", _inputs_flat, _attrs, _result) 

1770 _result, = _result 

1771 return _result 

1772 

1773EncodePng = tf_export("raw_ops.EncodePng")(_ops.to_raw_op(encode_png)) 

1774 

1775 

1776def encode_png_eager_fallback(image, compression, name, ctx): 

1777 if compression is None: 

1778 compression = -1 

1779 compression = _execute.make_int(compression, "compression") 

1780 _attr_T, (image,) = _execute.args_to_matching_eager([image], ctx, [_dtypes.uint8, _dtypes.uint16, ], _dtypes.uint8) 

1781 _inputs_flat = [image] 

1782 _attrs = ("compression", compression, "T", _attr_T) 

1783 _result = _execute.execute(b"EncodePng", 1, inputs=_inputs_flat, 

1784 attrs=_attrs, ctx=ctx, name=name) 

1785 if _execute.must_record_gradient(): 

1786 _execute.record_gradient( 

1787 "EncodePng", _inputs_flat, _attrs, _result) 

1788 _result, = _result 

1789 return _result 

1790 

1791 

1792def extract_glimpse(input, size, offsets, centered=True, normalized=True, uniform_noise=True, noise="uniform", name=None): 

1793 r"""Extracts a glimpse from the input tensor. 

1794 

1795 Returns a set of windows called glimpses extracted at location 

1796 `offsets` from the input tensor. If the windows only partially 

1797 overlaps the inputs, the non overlapping areas will be filled with 

1798 random noise. 

1799 

1800 The result is a 4-D tensor of shape `[batch_size, glimpse_height, 

1801 glimpse_width, channels]`. The channels and batch dimensions are the 

1802 same as that of the input tensor. The height and width of the output 

1803 windows are specified in the `size` parameter. 

1804 

1805 The argument `normalized` and `centered` controls how the windows are built: 

1806 

1807 * If the coordinates are normalized but not centered, 0.0 and 1.0 

1808 correspond to the minimum and maximum of each height and width 

1809 dimension. 

1810 * If the coordinates are both normalized and centered, they range from 

1811 -1.0 to 1.0. The coordinates (-1.0, -1.0) correspond to the upper 

1812 left corner, the lower right corner is located at (1.0, 1.0) and the 

1813 center is at (0, 0). 

1814 * If the coordinates are not normalized they are interpreted as 

1815 numbers of pixels. 

1816 

1817 Args: 

1818 input: A `Tensor` of type `float32`. 

1819 A 4-D float tensor of shape `[batch_size, height, width, channels]`. 

1820 size: A `Tensor` of type `int32`. 

1821 A 1-D tensor of 2 elements containing the size of the glimpses 

1822 to extract. The glimpse height must be specified first, following 

1823 by the glimpse width. 

1824 offsets: A `Tensor` of type `float32`. 

1825 A 2-D integer tensor of shape `[batch_size, 2]` containing 

1826 the y, x locations of the center of each window. 

1827 centered: An optional `bool`. Defaults to `True`. 

1828 indicates if the offset coordinates are centered relative to 

1829 the image, in which case the (0, 0) offset is relative to the center 

1830 of the input images. If false, the (0,0) offset corresponds to the 

1831 upper left corner of the input images. 

1832 normalized: An optional `bool`. Defaults to `True`. 

1833 indicates if the offset coordinates are normalized. 

1834 uniform_noise: An optional `bool`. Defaults to `True`. 

1835 indicates if the noise should be generated using a 

1836 uniform distribution or a Gaussian distribution. 

1837 noise: An optional `string`. Defaults to `"uniform"`. 

1838 indicates if the noise should `uniform`, `gaussian`, or 

1839 `zero`. The default is `uniform` which means the noise type 

1840 will be decided by `uniform_noise`. 

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

1842 

1843 Returns: 

1844 A `Tensor` of type `float32`. 

1845 """ 

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

1847 tld = _ctx._thread_local_data 

1848 if tld.is_eager: 

1849 try: 

1850 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

1851 _ctx, "ExtractGlimpse", name, input, size, offsets, "centered", 

1852 centered, "normalized", normalized, "uniform_noise", uniform_noise, 

1853 "noise", noise) 

1854 return _result 

1855 except _core._NotOkStatusException as e: 

1856 _ops.raise_from_not_ok_status(e, name) 

1857 except _core._FallbackException: 

1858 pass 

1859 try: 

1860 return extract_glimpse_eager_fallback( 

1861 input, size, offsets, centered=centered, normalized=normalized, 

1862 uniform_noise=uniform_noise, noise=noise, name=name, ctx=_ctx) 

1863 except _core._SymbolicException: 

1864 pass # Add nodes to the TensorFlow graph. 

1865 # Add nodes to the TensorFlow graph. 

1866 if centered is None: 

1867 centered = True 

1868 centered = _execute.make_bool(centered, "centered") 

1869 if normalized is None: 

1870 normalized = True 

1871 normalized = _execute.make_bool(normalized, "normalized") 

1872 if uniform_noise is None: 

1873 uniform_noise = True 

1874 uniform_noise = _execute.make_bool(uniform_noise, "uniform_noise") 

1875 if noise is None: 

1876 noise = "uniform" 

1877 noise = _execute.make_str(noise, "noise") 

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

1879 "ExtractGlimpse", input=input, size=size, offsets=offsets, 

1880 centered=centered, normalized=normalized, 

1881 uniform_noise=uniform_noise, noise=noise, name=name) 

1882 _result = _outputs[:] 

1883 if _execute.must_record_gradient(): 

1884 _attrs = ("centered", _op._get_attr_bool("centered"), "normalized", 

1885 _op._get_attr_bool("normalized"), "uniform_noise", 

1886 _op._get_attr_bool("uniform_noise"), "noise", 

1887 _op.get_attr("noise")) 

1888 _inputs_flat = _op.inputs 

1889 _execute.record_gradient( 

1890 "ExtractGlimpse", _inputs_flat, _attrs, _result) 

1891 _result, = _result 

1892 return _result 

1893 

1894ExtractGlimpse = tf_export("raw_ops.ExtractGlimpse")(_ops.to_raw_op(extract_glimpse)) 

1895 

1896 

1897def extract_glimpse_eager_fallback(input, size, offsets, centered, normalized, uniform_noise, noise, name, ctx): 

1898 if centered is None: 

1899 centered = True 

1900 centered = _execute.make_bool(centered, "centered") 

1901 if normalized is None: 

1902 normalized = True 

1903 normalized = _execute.make_bool(normalized, "normalized") 

1904 if uniform_noise is None: 

1905 uniform_noise = True 

1906 uniform_noise = _execute.make_bool(uniform_noise, "uniform_noise") 

1907 if noise is None: 

1908 noise = "uniform" 

1909 noise = _execute.make_str(noise, "noise") 

1910 input = _ops.convert_to_tensor(input, _dtypes.float32) 

1911 size = _ops.convert_to_tensor(size, _dtypes.int32) 

1912 offsets = _ops.convert_to_tensor(offsets, _dtypes.float32) 

1913 _inputs_flat = [input, size, offsets] 

1914 _attrs = ("centered", centered, "normalized", normalized, "uniform_noise", 

1915 uniform_noise, "noise", noise) 

1916 _result = _execute.execute(b"ExtractGlimpse", 1, inputs=_inputs_flat, 

1917 attrs=_attrs, ctx=ctx, name=name) 

1918 if _execute.must_record_gradient(): 

1919 _execute.record_gradient( 

1920 "ExtractGlimpse", _inputs_flat, _attrs, _result) 

1921 _result, = _result 

1922 return _result 

1923 

1924 

1925def extract_glimpse_v2(input, size, offsets, centered=True, normalized=True, uniform_noise=True, noise="uniform", name=None): 

1926 r"""Extracts a glimpse from the input tensor. 

1927 

1928 Returns a set of windows called glimpses extracted at location 

1929 `offsets` from the input tensor. If the windows only partially 

1930 overlaps the inputs, the non overlapping areas will be filled with 

1931 random noise. 

1932 

1933 The result is a 4-D tensor of shape `[batch_size, glimpse_height, 

1934 glimpse_width, channels]`. The channels and batch dimensions are the 

1935 same as that of the input tensor. The height and width of the output 

1936 windows are specified in the `size` parameter. 

1937 

1938 The argument `normalized` and `centered` controls how the windows are built: 

1939 

1940 * If the coordinates are normalized but not centered, 0.0 and 1.0 

1941 correspond to the minimum and maximum of each height and width 

1942 dimension. 

1943 * If the coordinates are both normalized and centered, they range from 

1944 -1.0 to 1.0. The coordinates (-1.0, -1.0) correspond to the upper 

1945 left corner, the lower right corner is located at (1.0, 1.0) and the 

1946 center is at (0, 0). 

1947 * If the coordinates are not normalized they are interpreted as 

1948 numbers of pixels. 

1949 

1950 Args: 

1951 input: A `Tensor` of type `float32`. 

1952 A 4-D float tensor of shape `[batch_size, height, width, channels]`. 

1953 size: A `Tensor` of type `int32`. 

1954 A 1-D tensor of 2 elements containing the size of the glimpses 

1955 to extract. The glimpse height must be specified first, following 

1956 by the glimpse width. 

1957 offsets: A `Tensor` of type `float32`. 

1958 A 2-D integer tensor of shape `[batch_size, 2]` containing 

1959 the y, x locations of the center of each window. 

1960 centered: An optional `bool`. Defaults to `True`. 

1961 indicates if the offset coordinates are centered relative to 

1962 the image, in which case the (0, 0) offset is relative to the center 

1963 of the input images. If false, the (0,0) offset corresponds to the 

1964 upper left corner of the input images. 

1965 normalized: An optional `bool`. Defaults to `True`. 

1966 indicates if the offset coordinates are normalized. 

1967 uniform_noise: An optional `bool`. Defaults to `True`. 

1968 indicates if the noise should be generated using a 

1969 uniform distribution or a Gaussian distribution. 

1970 noise: An optional `string`. Defaults to `"uniform"`. 

1971 indicates if the noise should `uniform`, `gaussian`, or 

1972 `zero`. The default is `uniform` which means the noise type 

1973 will be decided by `uniform_noise`. 

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

1975 

1976 Returns: 

1977 A `Tensor` of type `float32`. 

1978 """ 

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

1980 tld = _ctx._thread_local_data 

1981 if tld.is_eager: 

1982 try: 

1983 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

1984 _ctx, "ExtractGlimpseV2", name, input, size, offsets, "centered", 

1985 centered, "normalized", normalized, "uniform_noise", uniform_noise, 

1986 "noise", noise) 

1987 return _result 

1988 except _core._NotOkStatusException as e: 

1989 _ops.raise_from_not_ok_status(e, name) 

1990 except _core._FallbackException: 

1991 pass 

1992 try: 

1993 return extract_glimpse_v2_eager_fallback( 

1994 input, size, offsets, centered=centered, normalized=normalized, 

1995 uniform_noise=uniform_noise, noise=noise, name=name, ctx=_ctx) 

1996 except _core._SymbolicException: 

1997 pass # Add nodes to the TensorFlow graph. 

1998 # Add nodes to the TensorFlow graph. 

1999 if centered is None: 

2000 centered = True 

2001 centered = _execute.make_bool(centered, "centered") 

2002 if normalized is None: 

2003 normalized = True 

2004 normalized = _execute.make_bool(normalized, "normalized") 

2005 if uniform_noise is None: 

2006 uniform_noise = True 

2007 uniform_noise = _execute.make_bool(uniform_noise, "uniform_noise") 

2008 if noise is None: 

2009 noise = "uniform" 

2010 noise = _execute.make_str(noise, "noise") 

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

2012 "ExtractGlimpseV2", input=input, size=size, offsets=offsets, 

2013 centered=centered, normalized=normalized, 

2014 uniform_noise=uniform_noise, noise=noise, 

2015 name=name) 

2016 _result = _outputs[:] 

2017 if _execute.must_record_gradient(): 

2018 _attrs = ("centered", _op._get_attr_bool("centered"), "normalized", 

2019 _op._get_attr_bool("normalized"), "uniform_noise", 

2020 _op._get_attr_bool("uniform_noise"), "noise", 

2021 _op.get_attr("noise")) 

2022 _inputs_flat = _op.inputs 

2023 _execute.record_gradient( 

2024 "ExtractGlimpseV2", _inputs_flat, _attrs, _result) 

2025 _result, = _result 

2026 return _result 

2027 

2028ExtractGlimpseV2 = tf_export("raw_ops.ExtractGlimpseV2")(_ops.to_raw_op(extract_glimpse_v2)) 

2029 

2030 

2031def extract_glimpse_v2_eager_fallback(input, size, offsets, centered, normalized, uniform_noise, noise, name, ctx): 

2032 if centered is None: 

2033 centered = True 

2034 centered = _execute.make_bool(centered, "centered") 

2035 if normalized is None: 

2036 normalized = True 

2037 normalized = _execute.make_bool(normalized, "normalized") 

2038 if uniform_noise is None: 

2039 uniform_noise = True 

2040 uniform_noise = _execute.make_bool(uniform_noise, "uniform_noise") 

2041 if noise is None: 

2042 noise = "uniform" 

2043 noise = _execute.make_str(noise, "noise") 

2044 input = _ops.convert_to_tensor(input, _dtypes.float32) 

2045 size = _ops.convert_to_tensor(size, _dtypes.int32) 

2046 offsets = _ops.convert_to_tensor(offsets, _dtypes.float32) 

2047 _inputs_flat = [input, size, offsets] 

2048 _attrs = ("centered", centered, "normalized", normalized, "uniform_noise", 

2049 uniform_noise, "noise", noise) 

2050 _result = _execute.execute(b"ExtractGlimpseV2", 1, inputs=_inputs_flat, 

2051 attrs=_attrs, ctx=ctx, name=name) 

2052 if _execute.must_record_gradient(): 

2053 _execute.record_gradient( 

2054 "ExtractGlimpseV2", _inputs_flat, _attrs, _result) 

2055 _result, = _result 

2056 return _result 

2057 

2058 

2059def extract_jpeg_shape(contents, output_type=_dtypes.int32, name=None): 

2060 r"""Extract the shape information of a JPEG-encoded image. 

2061 

2062 This op only parses the image header, so it is much faster than DecodeJpeg. 

2063 

2064 Args: 

2065 contents: A `Tensor` of type `string`. 0-D. The JPEG-encoded image. 

2066 output_type: An optional `tf.DType` from: `tf.int32, tf.int64`. Defaults to `tf.int32`. 

2067 (Optional) The output type of the operation (int32 or int64). 

2068 Defaults to int32. 

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

2070 

2071 Returns: 

2072 A `Tensor` of type `output_type`. 

2073 """ 

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

2075 tld = _ctx._thread_local_data 

2076 if tld.is_eager: 

2077 try: 

2078 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

2079 _ctx, "ExtractJpegShape", name, contents, "output_type", output_type) 

2080 return _result 

2081 except _core._NotOkStatusException as e: 

2082 _ops.raise_from_not_ok_status(e, name) 

2083 except _core._FallbackException: 

2084 pass 

2085 try: 

2086 return extract_jpeg_shape_eager_fallback( 

2087 contents, output_type=output_type, name=name, ctx=_ctx) 

2088 except _core._SymbolicException: 

2089 pass # Add nodes to the TensorFlow graph. 

2090 # Add nodes to the TensorFlow graph. 

2091 if output_type is None: 

2092 output_type = _dtypes.int32 

2093 output_type = _execute.make_type(output_type, "output_type") 

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

2095 "ExtractJpegShape", contents=contents, output_type=output_type, 

2096 name=name) 

2097 _result = _outputs[:] 

2098 if _execute.must_record_gradient(): 

2099 _attrs = ("output_type", _op._get_attr_type("output_type")) 

2100 _inputs_flat = _op.inputs 

2101 _execute.record_gradient( 

2102 "ExtractJpegShape", _inputs_flat, _attrs, _result) 

2103 _result, = _result 

2104 return _result 

2105 

2106ExtractJpegShape = tf_export("raw_ops.ExtractJpegShape")(_ops.to_raw_op(extract_jpeg_shape)) 

2107 

2108 

2109def extract_jpeg_shape_eager_fallback(contents, output_type, name, ctx): 

2110 if output_type is None: 

2111 output_type = _dtypes.int32 

2112 output_type = _execute.make_type(output_type, "output_type") 

2113 contents = _ops.convert_to_tensor(contents, _dtypes.string) 

2114 _inputs_flat = [contents] 

2115 _attrs = ("output_type", output_type) 

2116 _result = _execute.execute(b"ExtractJpegShape", 1, inputs=_inputs_flat, 

2117 attrs=_attrs, ctx=ctx, name=name) 

2118 if _execute.must_record_gradient(): 

2119 _execute.record_gradient( 

2120 "ExtractJpegShape", _inputs_flat, _attrs, _result) 

2121 _result, = _result 

2122 return _result 

2123 

2124_GenerateBoundingBoxProposalsOutput = collections.namedtuple( 

2125 "GenerateBoundingBoxProposals", 

2126 ["rois", "roi_probabilities"]) 

2127 

2128 

2129def generate_bounding_box_proposals(scores, bbox_deltas, image_info, anchors, nms_threshold, pre_nms_topn, min_size, post_nms_topn=300, name=None): 

2130 r"""This op produces Region of Interests from given bounding boxes(bbox_deltas) encoded wrt anchors according to eq.2 in arXiv:1506.01497 

2131 

2132 The op selects top `pre_nms_topn` scoring boxes, decodes them with respect to anchors, 

2133 applies non-maximal suppression on overlapping boxes with higher than 

2134 `nms_threshold` intersection-over-union (iou) value, discarding boxes where shorter 

2135 side is less than `min_size`. 

2136 Inputs: 

2137 `scores`: A 4D tensor of shape [Batch, Height, Width, Num Anchors] containing the scores per anchor at given position 

2138 `bbox_deltas`: is a tensor of shape [Batch, Height, Width, 4 x Num Anchors] boxes encoded to each anchor 

2139 `anchors`: A 1D tensor of shape [4 x Num Anchors], representing the anchors. 

2140 Outputs: 

2141 `rois`: output RoIs, a 3D tensor of shape [Batch, post_nms_topn, 4], padded by 0 if less than post_nms_topn candidates found. 

2142 `roi_probabilities`: probability scores of each roi in 'rois', a 2D tensor of shape [Batch,post_nms_topn], padded with 0 if needed, sorted by scores. 

2143 

2144 Args: 

2145 scores: A `Tensor` of type `float32`. 

2146 A 4-D float tensor of shape `[num_images, height, width, num_achors]` containing scores of the boxes for given anchors, can be unsorted. 

2147 bbox_deltas: A `Tensor` of type `float32`. 

2148 A 4-D float tensor of shape `[num_images, height, width, 4 x num_anchors]`. encoding boxes with respec to each anchor. 

2149 Coordinates are given in the form [dy, dx, dh, dw]. 

2150 image_info: A `Tensor` of type `float32`. 

2151 A 2-D float tensor of shape `[num_images, 5]` containing image information Height, Width, Scale. 

2152 anchors: A `Tensor` of type `float32`. 

2153 A 2-D float tensor of shape `[num_anchors, 4]` describing the anchor boxes. Boxes are formatted in the form [y1, x1, y2, x2]. 

2154 nms_threshold: A `Tensor` of type `float32`. 

2155 A scalar float tensor for non-maximal-suppression threshold. 

2156 pre_nms_topn: A `Tensor` of type `int32`. 

2157 A scalar int tensor for the number of top scoring boxes to be used as input. 

2158 min_size: A `Tensor` of type `float32`. 

2159 A scalar float tensor. Any box that has a smaller size than min_size will be discarded. 

2160 post_nms_topn: An optional `int`. Defaults to `300`. 

2161 An integer. Maximum number of rois in the output. 

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

2163 

2164 Returns: 

2165 A tuple of `Tensor` objects (rois, roi_probabilities). 

2166 

2167 rois: A `Tensor` of type `float32`. 

2168 roi_probabilities: A `Tensor` of type `float32`. 

2169 """ 

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

2171 tld = _ctx._thread_local_data 

2172 if tld.is_eager: 

2173 try: 

2174 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

2175 _ctx, "GenerateBoundingBoxProposals", name, scores, bbox_deltas, 

2176 image_info, anchors, nms_threshold, pre_nms_topn, min_size, 

2177 "post_nms_topn", post_nms_topn) 

2178 _result = _GenerateBoundingBoxProposalsOutput._make(_result) 

2179 return _result 

2180 except _core._NotOkStatusException as e: 

2181 _ops.raise_from_not_ok_status(e, name) 

2182 except _core._FallbackException: 

2183 pass 

2184 try: 

2185 return generate_bounding_box_proposals_eager_fallback( 

2186 scores, bbox_deltas, image_info, anchors, nms_threshold, 

2187 pre_nms_topn, min_size, post_nms_topn=post_nms_topn, name=name, 

2188 ctx=_ctx) 

2189 except _core._SymbolicException: 

2190 pass # Add nodes to the TensorFlow graph. 

2191 # Add nodes to the TensorFlow graph. 

2192 if post_nms_topn is None: 

2193 post_nms_topn = 300 

2194 post_nms_topn = _execute.make_int(post_nms_topn, "post_nms_topn") 

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

2196 "GenerateBoundingBoxProposals", scores=scores, 

2197 bbox_deltas=bbox_deltas, 

2198 image_info=image_info, 

2199 anchors=anchors, 

2200 nms_threshold=nms_threshold, 

2201 pre_nms_topn=pre_nms_topn, 

2202 min_size=min_size, 

2203 post_nms_topn=post_nms_topn, 

2204 name=name) 

2205 _result = _outputs[:] 

2206 if _execute.must_record_gradient(): 

2207 _attrs = ("post_nms_topn", _op._get_attr_int("post_nms_topn")) 

2208 _inputs_flat = _op.inputs 

2209 _execute.record_gradient( 

2210 "GenerateBoundingBoxProposals", _inputs_flat, _attrs, _result) 

2211 _result = _GenerateBoundingBoxProposalsOutput._make(_result) 

2212 return _result 

2213 

2214GenerateBoundingBoxProposals = tf_export("raw_ops.GenerateBoundingBoxProposals")(_ops.to_raw_op(generate_bounding_box_proposals)) 

2215 

2216 

2217def generate_bounding_box_proposals_eager_fallback(scores, bbox_deltas, image_info, anchors, nms_threshold, pre_nms_topn, min_size, post_nms_topn, name, ctx): 

2218 if post_nms_topn is None: 

2219 post_nms_topn = 300 

2220 post_nms_topn = _execute.make_int(post_nms_topn, "post_nms_topn") 

2221 scores = _ops.convert_to_tensor(scores, _dtypes.float32) 

2222 bbox_deltas = _ops.convert_to_tensor(bbox_deltas, _dtypes.float32) 

2223 image_info = _ops.convert_to_tensor(image_info, _dtypes.float32) 

2224 anchors = _ops.convert_to_tensor(anchors, _dtypes.float32) 

2225 nms_threshold = _ops.convert_to_tensor(nms_threshold, _dtypes.float32) 

2226 pre_nms_topn = _ops.convert_to_tensor(pre_nms_topn, _dtypes.int32) 

2227 min_size = _ops.convert_to_tensor(min_size, _dtypes.float32) 

2228 _inputs_flat = [scores, bbox_deltas, image_info, anchors, nms_threshold, pre_nms_topn, min_size] 

2229 _attrs = ("post_nms_topn", post_nms_topn) 

2230 _result = _execute.execute(b"GenerateBoundingBoxProposals", 2, 

2231 inputs=_inputs_flat, attrs=_attrs, ctx=ctx, 

2232 name=name) 

2233 if _execute.must_record_gradient(): 

2234 _execute.record_gradient( 

2235 "GenerateBoundingBoxProposals", _inputs_flat, _attrs, _result) 

2236 _result = _GenerateBoundingBoxProposalsOutput._make(_result) 

2237 return _result 

2238 

2239 

2240@_dispatch.add_fallback_dispatch_list 

2241@_dispatch.add_type_based_api_dispatcher 

2242@tf_export('image.hsv_to_rgb') 

2243def hsv_to_rgb(images, name=None): 

2244 r"""Convert one or more images from HSV to RGB. 

2245 

2246 Outputs a tensor of the same shape as the `images` tensor, containing the RGB 

2247 value of the pixels. The output is only well defined if the value in `images` 

2248 are in `[0,1]`. 

2249 

2250 See `rgb_to_hsv` for a description of the HSV encoding. 

2251 

2252 Args: 

2253 images: A `Tensor`. Must be one of the following types: `half`, `bfloat16`, `float32`, `float64`. 

2254 1-D or higher rank. HSV data to convert. Last dimension must be size 3. 

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

2256 

2257 Returns: 

2258 A `Tensor`. Has the same type as `images`. 

2259 """ 

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

2261 tld = _ctx._thread_local_data 

2262 if tld.is_eager: 

2263 try: 

2264 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

2265 _ctx, "HSVToRGB", name, images) 

2266 return _result 

2267 except _core._NotOkStatusException as e: 

2268 _ops.raise_from_not_ok_status(e, name) 

2269 except _core._FallbackException: 

2270 pass 

2271 try: 

2272 _result = _dispatcher_for_hsv_to_rgb( 

2273 (images, name,), None) 

2274 if _result is not NotImplemented: 

2275 return _result 

2276 return hsv_to_rgb_eager_fallback( 

2277 images, name=name, ctx=_ctx) 

2278 except _core._SymbolicException: 

2279 pass # Add nodes to the TensorFlow graph. 

2280 except (TypeError, ValueError): 

2281 _result = _dispatch.dispatch( 

2282 hsv_to_rgb, (), dict(images=images, name=name) 

2283 ) 

2284 if _result is not _dispatch.OpDispatcher.NOT_SUPPORTED: 

2285 return _result 

2286 raise 

2287 else: 

2288 _result = _dispatcher_for_hsv_to_rgb( 

2289 (images, name,), None) 

2290 if _result is not NotImplemented: 

2291 return _result 

2292 # Add nodes to the TensorFlow graph. 

2293 try: 

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

2295 "HSVToRGB", images=images, name=name) 

2296 except (TypeError, ValueError): 

2297 _result = _dispatch.dispatch( 

2298 hsv_to_rgb, (), dict(images=images, name=name) 

2299 ) 

2300 if _result is not _dispatch.OpDispatcher.NOT_SUPPORTED: 

2301 return _result 

2302 raise 

2303 _result = _outputs[:] 

2304 if _execute.must_record_gradient(): 

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

2306 _inputs_flat = _op.inputs 

2307 _execute.record_gradient( 

2308 "HSVToRGB", _inputs_flat, _attrs, _result) 

2309 _result, = _result 

2310 return _result 

2311 

2312HSVToRGB = tf_export("raw_ops.HSVToRGB")(_ops.to_raw_op(hsv_to_rgb)) 

2313_dispatcher_for_hsv_to_rgb = hsv_to_rgb._tf_type_based_dispatcher.Dispatch 

2314 

2315 

2316def hsv_to_rgb_eager_fallback(images, name, ctx): 

2317 _attr_T, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.half, _dtypes.bfloat16, _dtypes.float32, _dtypes.float64, ], _dtypes.float32) 

2318 _inputs_flat = [images] 

2319 _attrs = ("T", _attr_T) 

2320 _result = _execute.execute(b"HSVToRGB", 1, inputs=_inputs_flat, 

2321 attrs=_attrs, ctx=ctx, name=name) 

2322 if _execute.must_record_gradient(): 

2323 _execute.record_gradient( 

2324 "HSVToRGB", _inputs_flat, _attrs, _result) 

2325 _result, = _result 

2326 return _result 

2327 

2328 

2329def image_projective_transform_v2(images, transforms, output_shape, interpolation, fill_mode="CONSTANT", name=None): 

2330 r"""Applies the given transform to each of the images. 

2331 

2332 If one row of `transforms` is `[a0, a1, a2, b0, b1, b2, c0, c1]`, then it maps 

2333 the *output* point `(x, y)` to a transformed *input* point 

2334 `(x', y') = ((a0 x + a1 y + a2) / k, (b0 x + b1 y + b2) / k)`, where 

2335 `k = c0 x + c1 y + 1`. If the transformed point lays outside of the input 

2336 image, the output pixel is set to 0. 

2337 

2338 Args: 

2339 images: A `Tensor`. Must be one of the following types: `uint8`, `int32`, `int64`, `half`, `float32`, `float64`. 

2340 4-D with shape `[batch, height, width, channels]`. 

2341 transforms: A `Tensor` of type `float32`. 

2342 2-D Tensor, `[batch, 8]` or `[1, 8]` matrix, where each row corresponds to a 3 x 3 

2343 projective transformation matrix, with the last entry assumed to be 1. If there 

2344 is one row, the same transformation will be applied to all images. 

2345 output_shape: A `Tensor` of type `int32`. 

2346 1-D Tensor [new_height, new_width]. 

2347 interpolation: A `string`. Interpolation method, "NEAREST" or "BILINEAR". 

2348 fill_mode: An optional `string`. Defaults to `"CONSTANT"`. 

2349 Fill mode, "REFLECT", "WRAP", or "CONSTANT". 

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

2351 

2352 Returns: 

2353 A `Tensor`. Has the same type as `images`. 

2354 """ 

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

2356 tld = _ctx._thread_local_data 

2357 if tld.is_eager: 

2358 try: 

2359 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

2360 _ctx, "ImageProjectiveTransformV2", name, images, transforms, 

2361 output_shape, "interpolation", interpolation, "fill_mode", fill_mode) 

2362 return _result 

2363 except _core._NotOkStatusException as e: 

2364 _ops.raise_from_not_ok_status(e, name) 

2365 except _core._FallbackException: 

2366 pass 

2367 try: 

2368 return image_projective_transform_v2_eager_fallback( 

2369 images, transforms, output_shape, interpolation=interpolation, 

2370 fill_mode=fill_mode, name=name, ctx=_ctx) 

2371 except _core._SymbolicException: 

2372 pass # Add nodes to the TensorFlow graph. 

2373 # Add nodes to the TensorFlow graph. 

2374 interpolation = _execute.make_str(interpolation, "interpolation") 

2375 if fill_mode is None: 

2376 fill_mode = "CONSTANT" 

2377 fill_mode = _execute.make_str(fill_mode, "fill_mode") 

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

2379 "ImageProjectiveTransformV2", images=images, transforms=transforms, 

2380 output_shape=output_shape, 

2381 interpolation=interpolation, 

2382 fill_mode=fill_mode, name=name) 

2383 _result = _outputs[:] 

2384 if _execute.must_record_gradient(): 

2385 _attrs = ("dtype", _op._get_attr_type("dtype"), "interpolation", 

2386 _op.get_attr("interpolation"), "fill_mode", 

2387 _op.get_attr("fill_mode")) 

2388 _inputs_flat = _op.inputs 

2389 _execute.record_gradient( 

2390 "ImageProjectiveTransformV2", _inputs_flat, _attrs, _result) 

2391 _result, = _result 

2392 return _result 

2393 

2394ImageProjectiveTransformV2 = tf_export("raw_ops.ImageProjectiveTransformV2")(_ops.to_raw_op(image_projective_transform_v2)) 

2395 

2396 

2397def image_projective_transform_v2_eager_fallback(images, transforms, output_shape, interpolation, fill_mode, name, ctx): 

2398 interpolation = _execute.make_str(interpolation, "interpolation") 

2399 if fill_mode is None: 

2400 fill_mode = "CONSTANT" 

2401 fill_mode = _execute.make_str(fill_mode, "fill_mode") 

2402 _attr_dtype, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.uint8, _dtypes.int32, _dtypes.int64, _dtypes.half, _dtypes.float32, _dtypes.float64, ]) 

2403 transforms = _ops.convert_to_tensor(transforms, _dtypes.float32) 

2404 output_shape = _ops.convert_to_tensor(output_shape, _dtypes.int32) 

2405 _inputs_flat = [images, transforms, output_shape] 

2406 _attrs = ("dtype", _attr_dtype, "interpolation", interpolation, "fill_mode", 

2407 fill_mode) 

2408 _result = _execute.execute(b"ImageProjectiveTransformV2", 1, 

2409 inputs=_inputs_flat, attrs=_attrs, ctx=ctx, 

2410 name=name) 

2411 if _execute.must_record_gradient(): 

2412 _execute.record_gradient( 

2413 "ImageProjectiveTransformV2", _inputs_flat, _attrs, _result) 

2414 _result, = _result 

2415 return _result 

2416 

2417 

2418def image_projective_transform_v3(images, transforms, output_shape, fill_value, interpolation, fill_mode="CONSTANT", name=None): 

2419 r"""Applies the given transform to each of the images. 

2420 

2421 If one row of `transforms` is `[a0, a1, a2, b0, b1, b2, c0, c1]`, then it maps 

2422 the *output* point `(x, y)` to a transformed *input* point 

2423 `(x', y') = ((a0 x + a1 y + a2) / k, (b0 x + b1 y + b2) / k)`, where 

2424 `k = c0 x + c1 y + 1`. If the transformed point lays outside of the input 

2425 image, the output pixel is set to fill_value. 

2426 

2427 Args: 

2428 images: A `Tensor`. Must be one of the following types: `uint8`, `int32`, `int64`, `half`, `float32`, `float64`. 

2429 4-D with shape `[batch, height, width, channels]`. 

2430 transforms: A `Tensor` of type `float32`. 

2431 2-D Tensor, `[batch, 8]` or `[1, 8]` matrix, where each row corresponds to a 3 x 3 

2432 projective transformation matrix, with the last entry assumed to be 1. If there 

2433 is one row, the same transformation will be applied to all images. 

2434 output_shape: A `Tensor` of type `int32`. 

2435 1-D Tensor [new_height, new_width]. 

2436 fill_value: A `Tensor` of type `float32`. 

2437 float, the value to be filled when fill_mode is constant". 

2438 interpolation: A `string`. Interpolation method, "NEAREST" or "BILINEAR". 

2439 fill_mode: An optional `string`. Defaults to `"CONSTANT"`. 

2440 Fill mode, "REFLECT", "WRAP", "CONSTANT", or "NEAREST". 

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

2442 

2443 Returns: 

2444 A `Tensor`. Has the same type as `images`. 

2445 """ 

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

2447 tld = _ctx._thread_local_data 

2448 if tld.is_eager: 

2449 try: 

2450 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

2451 _ctx, "ImageProjectiveTransformV3", name, images, transforms, 

2452 output_shape, fill_value, "interpolation", interpolation, "fill_mode", 

2453 fill_mode) 

2454 return _result 

2455 except _core._NotOkStatusException as e: 

2456 _ops.raise_from_not_ok_status(e, name) 

2457 except _core._FallbackException: 

2458 pass 

2459 try: 

2460 return image_projective_transform_v3_eager_fallback( 

2461 images, transforms, output_shape, fill_value, 

2462 interpolation=interpolation, fill_mode=fill_mode, name=name, 

2463 ctx=_ctx) 

2464 except _core._SymbolicException: 

2465 pass # Add nodes to the TensorFlow graph. 

2466 # Add nodes to the TensorFlow graph. 

2467 interpolation = _execute.make_str(interpolation, "interpolation") 

2468 if fill_mode is None: 

2469 fill_mode = "CONSTANT" 

2470 fill_mode = _execute.make_str(fill_mode, "fill_mode") 

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

2472 "ImageProjectiveTransformV3", images=images, transforms=transforms, 

2473 output_shape=output_shape, 

2474 fill_value=fill_value, 

2475 interpolation=interpolation, 

2476 fill_mode=fill_mode, name=name) 

2477 _result = _outputs[:] 

2478 if _execute.must_record_gradient(): 

2479 _attrs = ("dtype", _op._get_attr_type("dtype"), "interpolation", 

2480 _op.get_attr("interpolation"), "fill_mode", 

2481 _op.get_attr("fill_mode")) 

2482 _inputs_flat = _op.inputs 

2483 _execute.record_gradient( 

2484 "ImageProjectiveTransformV3", _inputs_flat, _attrs, _result) 

2485 _result, = _result 

2486 return _result 

2487 

2488ImageProjectiveTransformV3 = tf_export("raw_ops.ImageProjectiveTransformV3")(_ops.to_raw_op(image_projective_transform_v3)) 

2489 

2490 

2491def image_projective_transform_v3_eager_fallback(images, transforms, output_shape, fill_value, interpolation, fill_mode, name, ctx): 

2492 interpolation = _execute.make_str(interpolation, "interpolation") 

2493 if fill_mode is None: 

2494 fill_mode = "CONSTANT" 

2495 fill_mode = _execute.make_str(fill_mode, "fill_mode") 

2496 _attr_dtype, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.uint8, _dtypes.int32, _dtypes.int64, _dtypes.half, _dtypes.float32, _dtypes.float64, ]) 

2497 transforms = _ops.convert_to_tensor(transforms, _dtypes.float32) 

2498 output_shape = _ops.convert_to_tensor(output_shape, _dtypes.int32) 

2499 fill_value = _ops.convert_to_tensor(fill_value, _dtypes.float32) 

2500 _inputs_flat = [images, transforms, output_shape, fill_value] 

2501 _attrs = ("dtype", _attr_dtype, "interpolation", interpolation, "fill_mode", 

2502 fill_mode) 

2503 _result = _execute.execute(b"ImageProjectiveTransformV3", 1, 

2504 inputs=_inputs_flat, attrs=_attrs, ctx=ctx, 

2505 name=name) 

2506 if _execute.must_record_gradient(): 

2507 _execute.record_gradient( 

2508 "ImageProjectiveTransformV3", _inputs_flat, _attrs, _result) 

2509 _result, = _result 

2510 return _result 

2511 

2512 

2513def non_max_suppression(boxes, scores, max_output_size, iou_threshold=0.5, name=None): 

2514 r"""Greedily selects a subset of bounding boxes in descending order of score, 

2515 

2516 pruning away boxes that have high intersection-over-union (IOU) overlap 

2517 with previously selected boxes. Bounding boxes are supplied as 

2518 [y1, x1, y2, x2], where (y1, x1) and (y2, x2) are the coordinates of any 

2519 diagonal pair of box corners and the coordinates can be provided as normalized 

2520 (i.e., lying in the interval [0, 1]) or absolute. Note that this algorithm 

2521 is agnostic to where the origin is in the coordinate system. Note that this 

2522 algorithm is invariant to orthogonal transformations and translations 

2523 of the coordinate system; thus translating or reflections of the coordinate 

2524 system result in the same boxes being selected by the algorithm. 

2525 The output of this operation is a set of integers indexing into the input 

2526 collection of bounding boxes representing the selected boxes. The bounding 

2527 box coordinates corresponding to the selected indices can then be obtained 

2528 using the `tf.gather operation`. For example: 

2529 selected_indices = tf.image.non_max_suppression( 

2530 boxes, scores, max_output_size, iou_threshold) 

2531 selected_boxes = tf.gather(boxes, selected_indices) 

2532 

2533 Args: 

2534 boxes: A `Tensor` of type `float32`. 

2535 A 2-D float tensor of shape `[num_boxes, 4]`. 

2536 scores: A `Tensor` of type `float32`. 

2537 A 1-D float tensor of shape `[num_boxes]` representing a single 

2538 score corresponding to each box (each row of boxes). 

2539 max_output_size: A `Tensor` of type `int32`. 

2540 A scalar integer tensor representing the maximum number of 

2541 boxes to be selected by non max suppression. 

2542 iou_threshold: An optional `float`. Defaults to `0.5`. 

2543 A float representing the threshold for deciding whether boxes 

2544 overlap too much with respect to IOU. 

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

2546 

2547 Returns: 

2548 A `Tensor` of type `int32`. 

2549 """ 

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

2551 tld = _ctx._thread_local_data 

2552 if tld.is_eager: 

2553 try: 

2554 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

2555 _ctx, "NonMaxSuppression", name, boxes, scores, max_output_size, 

2556 "iou_threshold", iou_threshold) 

2557 return _result 

2558 except _core._NotOkStatusException as e: 

2559 _ops.raise_from_not_ok_status(e, name) 

2560 except _core._FallbackException: 

2561 pass 

2562 try: 

2563 return non_max_suppression_eager_fallback( 

2564 boxes, scores, max_output_size, iou_threshold=iou_threshold, 

2565 name=name, ctx=_ctx) 

2566 except _core._SymbolicException: 

2567 pass # Add nodes to the TensorFlow graph. 

2568 # Add nodes to the TensorFlow graph. 

2569 if iou_threshold is None: 

2570 iou_threshold = 0.5 

2571 iou_threshold = _execute.make_float(iou_threshold, "iou_threshold") 

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

2573 "NonMaxSuppression", boxes=boxes, scores=scores, 

2574 max_output_size=max_output_size, 

2575 iou_threshold=iou_threshold, name=name) 

2576 _result = _outputs[:] 

2577 if _execute.must_record_gradient(): 

2578 _attrs = ("iou_threshold", _op.get_attr("iou_threshold")) 

2579 _inputs_flat = _op.inputs 

2580 _execute.record_gradient( 

2581 "NonMaxSuppression", _inputs_flat, _attrs, _result) 

2582 _result, = _result 

2583 return _result 

2584 

2585NonMaxSuppression = tf_export("raw_ops.NonMaxSuppression")(_ops.to_raw_op(non_max_suppression)) 

2586 

2587 

2588def non_max_suppression_eager_fallback(boxes, scores, max_output_size, iou_threshold, name, ctx): 

2589 if iou_threshold is None: 

2590 iou_threshold = 0.5 

2591 iou_threshold = _execute.make_float(iou_threshold, "iou_threshold") 

2592 boxes = _ops.convert_to_tensor(boxes, _dtypes.float32) 

2593 scores = _ops.convert_to_tensor(scores, _dtypes.float32) 

2594 max_output_size = _ops.convert_to_tensor(max_output_size, _dtypes.int32) 

2595 _inputs_flat = [boxes, scores, max_output_size] 

2596 _attrs = ("iou_threshold", iou_threshold) 

2597 _result = _execute.execute(b"NonMaxSuppression", 1, inputs=_inputs_flat, 

2598 attrs=_attrs, ctx=ctx, name=name) 

2599 if _execute.must_record_gradient(): 

2600 _execute.record_gradient( 

2601 "NonMaxSuppression", _inputs_flat, _attrs, _result) 

2602 _result, = _result 

2603 return _result 

2604 

2605 

2606def non_max_suppression_v2(boxes, scores, max_output_size, iou_threshold, name=None): 

2607 r"""Greedily selects a subset of bounding boxes in descending order of score, 

2608 

2609 pruning away boxes that have high intersection-over-union (IOU) overlap 

2610 with previously selected boxes. Bounding boxes are supplied as 

2611 [y1, x1, y2, x2], where (y1, x1) and (y2, x2) are the coordinates of any 

2612 diagonal pair of box corners and the coordinates can be provided as normalized 

2613 (i.e., lying in the interval [0, 1]) or absolute. Note that this algorithm 

2614 is agnostic to where the origin is in the coordinate system. Note that this 

2615 algorithm is invariant to orthogonal transformations and translations 

2616 of the coordinate system; thus translating or reflections of the coordinate 

2617 system result in the same boxes being selected by the algorithm. 

2618 

2619 The output of this operation is a set of integers indexing into the input 

2620 collection of bounding boxes representing the selected boxes. The bounding 

2621 box coordinates corresponding to the selected indices can then be obtained 

2622 using the `tf.gather operation`. For example: 

2623 

2624 selected_indices = tf.image.non_max_suppression_v2( 

2625 boxes, scores, max_output_size, iou_threshold) 

2626 selected_boxes = tf.gather(boxes, selected_indices) 

2627 

2628 Args: 

2629 boxes: A `Tensor`. Must be one of the following types: `half`, `float32`. 

2630 A 2-D float tensor of shape `[num_boxes, 4]`. 

2631 scores: A `Tensor`. Must have the same type as `boxes`. 

2632 A 1-D float tensor of shape `[num_boxes]` representing a single 

2633 score corresponding to each box (each row of boxes). 

2634 max_output_size: A `Tensor` of type `int32`. 

2635 A scalar integer tensor representing the maximum number of 

2636 boxes to be selected by non max suppression. 

2637 iou_threshold: A `Tensor`. Must be one of the following types: `half`, `float32`. 

2638 A 0-D float tensor representing the threshold for deciding whether 

2639 boxes overlap too much with respect to IOU. 

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

2641 

2642 Returns: 

2643 A `Tensor` of type `int32`. 

2644 """ 

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

2646 tld = _ctx._thread_local_data 

2647 if tld.is_eager: 

2648 try: 

2649 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

2650 _ctx, "NonMaxSuppressionV2", name, boxes, scores, max_output_size, 

2651 iou_threshold) 

2652 return _result 

2653 except _core._NotOkStatusException as e: 

2654 _ops.raise_from_not_ok_status(e, name) 

2655 except _core._FallbackException: 

2656 pass 

2657 try: 

2658 return non_max_suppression_v2_eager_fallback( 

2659 boxes, scores, max_output_size, iou_threshold, name=name, ctx=_ctx) 

2660 except _core._SymbolicException: 

2661 pass # Add nodes to the TensorFlow graph. 

2662 # Add nodes to the TensorFlow graph. 

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

2664 "NonMaxSuppressionV2", boxes=boxes, scores=scores, 

2665 max_output_size=max_output_size, 

2666 iou_threshold=iou_threshold, name=name) 

2667 _result = _outputs[:] 

2668 if _execute.must_record_gradient(): 

2669 _attrs = ("T", _op._get_attr_type("T"), "T_threshold", 

2670 _op._get_attr_type("T_threshold")) 

2671 _inputs_flat = _op.inputs 

2672 _execute.record_gradient( 

2673 "NonMaxSuppressionV2", _inputs_flat, _attrs, _result) 

2674 _result, = _result 

2675 return _result 

2676 

2677NonMaxSuppressionV2 = tf_export("raw_ops.NonMaxSuppressionV2")(_ops.to_raw_op(non_max_suppression_v2)) 

2678 

2679 

2680def non_max_suppression_v2_eager_fallback(boxes, scores, max_output_size, iou_threshold, name, ctx): 

2681 _attr_T, _inputs_T = _execute.args_to_matching_eager([boxes, scores], ctx, [_dtypes.half, _dtypes.float32, ], _dtypes.float32) 

2682 (boxes, scores) = _inputs_T 

2683 _attr_T_threshold, (iou_threshold,) = _execute.args_to_matching_eager([iou_threshold], ctx, [_dtypes.half, _dtypes.float32, ], _dtypes.float32) 

2684 max_output_size = _ops.convert_to_tensor(max_output_size, _dtypes.int32) 

2685 _inputs_flat = [boxes, scores, max_output_size, iou_threshold] 

2686 _attrs = ("T", _attr_T, "T_threshold", _attr_T_threshold) 

2687 _result = _execute.execute(b"NonMaxSuppressionV2", 1, inputs=_inputs_flat, 

2688 attrs=_attrs, ctx=ctx, name=name) 

2689 if _execute.must_record_gradient(): 

2690 _execute.record_gradient( 

2691 "NonMaxSuppressionV2", _inputs_flat, _attrs, _result) 

2692 _result, = _result 

2693 return _result 

2694 

2695 

2696def non_max_suppression_v3(boxes, scores, max_output_size, iou_threshold, score_threshold, name=None): 

2697 r"""Greedily selects a subset of bounding boxes in descending order of score, 

2698 

2699 pruning away boxes that have high intersection-over-union (IOU) overlap 

2700 with previously selected boxes. Bounding boxes with score less than 

2701 `score_threshold` are removed. Bounding boxes are supplied as 

2702 [y1, x1, y2, x2], where (y1, x1) and (y2, x2) are the coordinates of any 

2703 diagonal pair of box corners and the coordinates can be provided as normalized 

2704 (i.e., lying in the interval [0, 1]) or absolute. Note that this algorithm 

2705 is agnostic to where the origin is in the coordinate system and more 

2706 generally is invariant to orthogonal transformations and translations 

2707 of the coordinate system; thus translating or reflections of the coordinate 

2708 system result in the same boxes being selected by the algorithm. 

2709 The output of this operation is a set of integers indexing into the input 

2710 collection of bounding boxes representing the selected boxes. The bounding 

2711 box coordinates corresponding to the selected indices can then be obtained 

2712 using the `tf.gather operation`. For example: 

2713 selected_indices = tf.image.non_max_suppression_v2( 

2714 boxes, scores, max_output_size, iou_threshold, score_threshold) 

2715 selected_boxes = tf.gather(boxes, selected_indices) 

2716 

2717 Args: 

2718 boxes: A `Tensor`. Must be one of the following types: `half`, `float32`. 

2719 A 2-D float tensor of shape `[num_boxes, 4]`. 

2720 scores: A `Tensor`. Must have the same type as `boxes`. 

2721 A 1-D float tensor of shape `[num_boxes]` representing a single 

2722 score corresponding to each box (each row of boxes). 

2723 max_output_size: A `Tensor` of type `int32`. 

2724 A scalar integer tensor representing the maximum number of 

2725 boxes to be selected by non max suppression. 

2726 iou_threshold: A `Tensor`. Must be one of the following types: `half`, `float32`. 

2727 A 0-D float tensor representing the threshold for deciding whether 

2728 boxes overlap too much with respect to IOU. 

2729 score_threshold: A `Tensor`. Must have the same type as `iou_threshold`. 

2730 A 0-D float tensor representing the threshold for deciding when to remove 

2731 boxes based on score. 

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

2733 

2734 Returns: 

2735 A `Tensor` of type `int32`. 

2736 """ 

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

2738 tld = _ctx._thread_local_data 

2739 if tld.is_eager: 

2740 try: 

2741 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

2742 _ctx, "NonMaxSuppressionV3", name, boxes, scores, max_output_size, 

2743 iou_threshold, score_threshold) 

2744 return _result 

2745 except _core._NotOkStatusException as e: 

2746 _ops.raise_from_not_ok_status(e, name) 

2747 except _core._FallbackException: 

2748 pass 

2749 try: 

2750 return non_max_suppression_v3_eager_fallback( 

2751 boxes, scores, max_output_size, iou_threshold, score_threshold, 

2752 name=name, ctx=_ctx) 

2753 except _core._SymbolicException: 

2754 pass # Add nodes to the TensorFlow graph. 

2755 # Add nodes to the TensorFlow graph. 

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

2757 "NonMaxSuppressionV3", boxes=boxes, scores=scores, 

2758 max_output_size=max_output_size, 

2759 iou_threshold=iou_threshold, 

2760 score_threshold=score_threshold, name=name) 

2761 _result = _outputs[:] 

2762 if _execute.must_record_gradient(): 

2763 _attrs = ("T", _op._get_attr_type("T"), "T_threshold", 

2764 _op._get_attr_type("T_threshold")) 

2765 _inputs_flat = _op.inputs 

2766 _execute.record_gradient( 

2767 "NonMaxSuppressionV3", _inputs_flat, _attrs, _result) 

2768 _result, = _result 

2769 return _result 

2770 

2771NonMaxSuppressionV3 = tf_export("raw_ops.NonMaxSuppressionV3")(_ops.to_raw_op(non_max_suppression_v3)) 

2772 

2773 

2774def non_max_suppression_v3_eager_fallback(boxes, scores, max_output_size, iou_threshold, score_threshold, name, ctx): 

2775 _attr_T, _inputs_T = _execute.args_to_matching_eager([boxes, scores], ctx, [_dtypes.half, _dtypes.float32, ], _dtypes.float32) 

2776 (boxes, scores) = _inputs_T 

2777 _attr_T_threshold, _inputs_T_threshold = _execute.args_to_matching_eager([iou_threshold, score_threshold], ctx, [_dtypes.half, _dtypes.float32, ], _dtypes.float32) 

2778 (iou_threshold, score_threshold) = _inputs_T_threshold 

2779 max_output_size = _ops.convert_to_tensor(max_output_size, _dtypes.int32) 

2780 _inputs_flat = [boxes, scores, max_output_size, iou_threshold, score_threshold] 

2781 _attrs = ("T", _attr_T, "T_threshold", _attr_T_threshold) 

2782 _result = _execute.execute(b"NonMaxSuppressionV3", 1, inputs=_inputs_flat, 

2783 attrs=_attrs, ctx=ctx, name=name) 

2784 if _execute.must_record_gradient(): 

2785 _execute.record_gradient( 

2786 "NonMaxSuppressionV3", _inputs_flat, _attrs, _result) 

2787 _result, = _result 

2788 return _result 

2789 

2790_NonMaxSuppressionV4Output = collections.namedtuple( 

2791 "NonMaxSuppressionV4", 

2792 ["selected_indices", "valid_outputs"]) 

2793 

2794 

2795def non_max_suppression_v4(boxes, scores, max_output_size, iou_threshold, score_threshold, pad_to_max_output_size=False, name=None): 

2796 r"""Greedily selects a subset of bounding boxes in descending order of score, 

2797 

2798 pruning away boxes that have high intersection-over-union (IOU) overlap 

2799 with previously selected boxes. Bounding boxes with score less than 

2800 `score_threshold` are removed. Bounding boxes are supplied as 

2801 [y1, x1, y2, x2], where (y1, x1) and (y2, x2) are the coordinates of any 

2802 diagonal pair of box corners and the coordinates can be provided as normalized 

2803 (i.e., lying in the interval [0, 1]) or absolute. Note that this algorithm 

2804 is agnostic to where the origin is in the coordinate system and more 

2805 generally is invariant to orthogonal transformations and translations 

2806 of the coordinate system; thus translating or reflections of the coordinate 

2807 system result in the same boxes being selected by the algorithm. 

2808 The output of this operation is a set of integers indexing into the input 

2809 collection of bounding boxes representing the selected boxes. The bounding 

2810 box coordinates corresponding to the selected indices can then be obtained 

2811 using the `tf.gather operation`. For example: 

2812 selected_indices = tf.image.non_max_suppression_v2( 

2813 boxes, scores, max_output_size, iou_threshold, score_threshold) 

2814 selected_boxes = tf.gather(boxes, selected_indices) 

2815 

2816 Args: 

2817 boxes: A `Tensor`. Must be one of the following types: `half`, `float32`. 

2818 A 2-D float tensor of shape `[num_boxes, 4]`. 

2819 scores: A `Tensor`. Must have the same type as `boxes`. 

2820 A 1-D float tensor of shape `[num_boxes]` representing a single 

2821 score corresponding to each box (each row of boxes). 

2822 max_output_size: A `Tensor` of type `int32`. 

2823 A scalar integer tensor representing the maximum number of 

2824 boxes to be selected by non max suppression. 

2825 iou_threshold: A `Tensor`. Must be one of the following types: `half`, `float32`. 

2826 A 0-D float tensor representing the threshold for deciding whether 

2827 boxes overlap too much with respect to IOU. 

2828 score_threshold: A `Tensor`. Must have the same type as `iou_threshold`. 

2829 A 0-D float tensor representing the threshold for deciding when to remove 

2830 boxes based on score. 

2831 pad_to_max_output_size: An optional `bool`. Defaults to `False`. 

2832 If true, the output `selected_indices` is padded to be of length 

2833 `max_output_size`. Defaults to false. 

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

2835 

2836 Returns: 

2837 A tuple of `Tensor` objects (selected_indices, valid_outputs). 

2838 

2839 selected_indices: A `Tensor` of type `int32`. 

2840 valid_outputs: A `Tensor` of type `int32`. 

2841 """ 

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

2843 tld = _ctx._thread_local_data 

2844 if tld.is_eager: 

2845 try: 

2846 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

2847 _ctx, "NonMaxSuppressionV4", name, boxes, scores, max_output_size, 

2848 iou_threshold, score_threshold, "pad_to_max_output_size", 

2849 pad_to_max_output_size) 

2850 _result = _NonMaxSuppressionV4Output._make(_result) 

2851 return _result 

2852 except _core._NotOkStatusException as e: 

2853 _ops.raise_from_not_ok_status(e, name) 

2854 except _core._FallbackException: 

2855 pass 

2856 try: 

2857 return non_max_suppression_v4_eager_fallback( 

2858 boxes, scores, max_output_size, iou_threshold, score_threshold, 

2859 pad_to_max_output_size=pad_to_max_output_size, name=name, ctx=_ctx) 

2860 except _core._SymbolicException: 

2861 pass # Add nodes to the TensorFlow graph. 

2862 # Add nodes to the TensorFlow graph. 

2863 if pad_to_max_output_size is None: 

2864 pad_to_max_output_size = False 

2865 pad_to_max_output_size = _execute.make_bool(pad_to_max_output_size, "pad_to_max_output_size") 

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

2867 "NonMaxSuppressionV4", boxes=boxes, scores=scores, 

2868 max_output_size=max_output_size, 

2869 iou_threshold=iou_threshold, 

2870 score_threshold=score_threshold, 

2871 pad_to_max_output_size=pad_to_max_output_size, 

2872 name=name) 

2873 _result = _outputs[:] 

2874 if _execute.must_record_gradient(): 

2875 _attrs = ("T", _op._get_attr_type("T"), "T_threshold", 

2876 _op._get_attr_type("T_threshold"), "pad_to_max_output_size", 

2877 _op._get_attr_bool("pad_to_max_output_size")) 

2878 _inputs_flat = _op.inputs 

2879 _execute.record_gradient( 

2880 "NonMaxSuppressionV4", _inputs_flat, _attrs, _result) 

2881 _result = _NonMaxSuppressionV4Output._make(_result) 

2882 return _result 

2883 

2884NonMaxSuppressionV4 = tf_export("raw_ops.NonMaxSuppressionV4")(_ops.to_raw_op(non_max_suppression_v4)) 

2885 

2886 

2887def non_max_suppression_v4_eager_fallback(boxes, scores, max_output_size, iou_threshold, score_threshold, pad_to_max_output_size, name, ctx): 

2888 if pad_to_max_output_size is None: 

2889 pad_to_max_output_size = False 

2890 pad_to_max_output_size = _execute.make_bool(pad_to_max_output_size, "pad_to_max_output_size") 

2891 _attr_T, _inputs_T = _execute.args_to_matching_eager([boxes, scores], ctx, [_dtypes.half, _dtypes.float32, ], _dtypes.float32) 

2892 (boxes, scores) = _inputs_T 

2893 _attr_T_threshold, _inputs_T_threshold = _execute.args_to_matching_eager([iou_threshold, score_threshold], ctx, [_dtypes.half, _dtypes.float32, ], _dtypes.float32) 

2894 (iou_threshold, score_threshold) = _inputs_T_threshold 

2895 max_output_size = _ops.convert_to_tensor(max_output_size, _dtypes.int32) 

2896 _inputs_flat = [boxes, scores, max_output_size, iou_threshold, score_threshold] 

2897 _attrs = ("T", _attr_T, "T_threshold", _attr_T_threshold, 

2898 "pad_to_max_output_size", pad_to_max_output_size) 

2899 _result = _execute.execute(b"NonMaxSuppressionV4", 2, inputs=_inputs_flat, 

2900 attrs=_attrs, ctx=ctx, name=name) 

2901 if _execute.must_record_gradient(): 

2902 _execute.record_gradient( 

2903 "NonMaxSuppressionV4", _inputs_flat, _attrs, _result) 

2904 _result = _NonMaxSuppressionV4Output._make(_result) 

2905 return _result 

2906 

2907_NonMaxSuppressionV5Output = collections.namedtuple( 

2908 "NonMaxSuppressionV5", 

2909 ["selected_indices", "selected_scores", "valid_outputs"]) 

2910 

2911 

2912def non_max_suppression_v5(boxes, scores, max_output_size, iou_threshold, score_threshold, soft_nms_sigma, pad_to_max_output_size=False, name=None): 

2913 r"""Greedily selects a subset of bounding boxes in descending order of score, 

2914 

2915 pruning away boxes that have high intersection-over-union (IOU) overlap 

2916 with previously selected boxes. Bounding boxes with score less than 

2917 `score_threshold` are removed. Bounding boxes are supplied as 

2918 [y1, x1, y2, x2], where (y1, x1) and (y2, x2) are the coordinates of any 

2919 diagonal pair of box corners and the coordinates can be provided as normalized 

2920 (i.e., lying in the interval [0, 1]) or absolute. Note that this algorithm 

2921 is agnostic to where the origin is in the coordinate system and more 

2922 generally is invariant to orthogonal transformations and translations 

2923 of the coordinate system; thus translating or reflections of the coordinate 

2924 system result in the same boxes being selected by the algorithm. 

2925 The output of this operation is a set of integers indexing into the input 

2926 collection of bounding boxes representing the selected boxes. The bounding 

2927 box coordinates corresponding to the selected indices can then be obtained 

2928 using the `tf.gather operation`. For example: 

2929 selected_indices = tf.image.non_max_suppression_v2( 

2930 boxes, scores, max_output_size, iou_threshold, score_threshold) 

2931 selected_boxes = tf.gather(boxes, selected_indices) 

2932 This op also supports a Soft-NMS (with Gaussian weighting) mode (c.f. 

2933 Bodla et al, https://arxiv.org/abs/1704.04503) where boxes reduce the score 

2934 of other overlapping boxes instead of directly causing them to be pruned. 

2935 To enable this Soft-NMS mode, set the `soft_nms_sigma` parameter to be 

2936 larger than 0. 

2937 

2938 Args: 

2939 boxes: A `Tensor`. Must be one of the following types: `half`, `float32`. 

2940 A 2-D float tensor of shape `[num_boxes, 4]`. 

2941 scores: A `Tensor`. Must have the same type as `boxes`. 

2942 A 1-D float tensor of shape `[num_boxes]` representing a single 

2943 score corresponding to each box (each row of boxes). 

2944 max_output_size: A `Tensor` of type `int32`. 

2945 A scalar integer tensor representing the maximum number of 

2946 boxes to be selected by non max suppression. 

2947 iou_threshold: A `Tensor`. Must have the same type as `boxes`. 

2948 A 0-D float tensor representing the threshold for deciding whether 

2949 boxes overlap too much with respect to IOU. 

2950 score_threshold: A `Tensor`. Must have the same type as `boxes`. 

2951 A 0-D float tensor representing the threshold for deciding when to remove 

2952 boxes based on score. 

2953 soft_nms_sigma: A `Tensor`. Must have the same type as `boxes`. 

2954 A 0-D float tensor representing the sigma parameter for Soft NMS; see Bodla et 

2955 al (c.f. https://arxiv.org/abs/1704.04503). When `soft_nms_sigma=0.0` (which 

2956 is default), we fall back to standard (hard) NMS. 

2957 pad_to_max_output_size: An optional `bool`. Defaults to `False`. 

2958 If true, the output `selected_indices` is padded to be of length 

2959 `max_output_size`. Defaults to false. 

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

2961 

2962 Returns: 

2963 A tuple of `Tensor` objects (selected_indices, selected_scores, valid_outputs). 

2964 

2965 selected_indices: A `Tensor` of type `int32`. 

2966 selected_scores: A `Tensor`. Has the same type as `boxes`. 

2967 valid_outputs: A `Tensor` of type `int32`. 

2968 """ 

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

2970 tld = _ctx._thread_local_data 

2971 if tld.is_eager: 

2972 try: 

2973 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

2974 _ctx, "NonMaxSuppressionV5", name, boxes, scores, max_output_size, 

2975 iou_threshold, score_threshold, soft_nms_sigma, 

2976 "pad_to_max_output_size", pad_to_max_output_size) 

2977 _result = _NonMaxSuppressionV5Output._make(_result) 

2978 return _result 

2979 except _core._NotOkStatusException as e: 

2980 _ops.raise_from_not_ok_status(e, name) 

2981 except _core._FallbackException: 

2982 pass 

2983 try: 

2984 return non_max_suppression_v5_eager_fallback( 

2985 boxes, scores, max_output_size, iou_threshold, score_threshold, 

2986 soft_nms_sigma, pad_to_max_output_size=pad_to_max_output_size, 

2987 name=name, ctx=_ctx) 

2988 except _core._SymbolicException: 

2989 pass # Add nodes to the TensorFlow graph. 

2990 # Add nodes to the TensorFlow graph. 

2991 if pad_to_max_output_size is None: 

2992 pad_to_max_output_size = False 

2993 pad_to_max_output_size = _execute.make_bool(pad_to_max_output_size, "pad_to_max_output_size") 

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

2995 "NonMaxSuppressionV5", boxes=boxes, scores=scores, 

2996 max_output_size=max_output_size, 

2997 iou_threshold=iou_threshold, 

2998 score_threshold=score_threshold, 

2999 soft_nms_sigma=soft_nms_sigma, 

3000 pad_to_max_output_size=pad_to_max_output_size, 

3001 name=name) 

3002 _result = _outputs[:] 

3003 if _execute.must_record_gradient(): 

3004 _attrs = ("T", _op._get_attr_type("T"), "pad_to_max_output_size", 

3005 _op._get_attr_bool("pad_to_max_output_size")) 

3006 _inputs_flat = _op.inputs 

3007 _execute.record_gradient( 

3008 "NonMaxSuppressionV5", _inputs_flat, _attrs, _result) 

3009 _result = _NonMaxSuppressionV5Output._make(_result) 

3010 return _result 

3011 

3012NonMaxSuppressionV5 = tf_export("raw_ops.NonMaxSuppressionV5")(_ops.to_raw_op(non_max_suppression_v5)) 

3013 

3014 

3015def non_max_suppression_v5_eager_fallback(boxes, scores, max_output_size, iou_threshold, score_threshold, soft_nms_sigma, pad_to_max_output_size, name, ctx): 

3016 if pad_to_max_output_size is None: 

3017 pad_to_max_output_size = False 

3018 pad_to_max_output_size = _execute.make_bool(pad_to_max_output_size, "pad_to_max_output_size") 

3019 _attr_T, _inputs_T = _execute.args_to_matching_eager([boxes, scores, iou_threshold, score_threshold, soft_nms_sigma], ctx, [_dtypes.half, _dtypes.float32, ], _dtypes.float32) 

3020 (boxes, scores, iou_threshold, score_threshold, soft_nms_sigma) = _inputs_T 

3021 max_output_size = _ops.convert_to_tensor(max_output_size, _dtypes.int32) 

3022 _inputs_flat = [boxes, scores, max_output_size, iou_threshold, score_threshold, soft_nms_sigma] 

3023 _attrs = ("T", _attr_T, "pad_to_max_output_size", pad_to_max_output_size) 

3024 _result = _execute.execute(b"NonMaxSuppressionV5", 3, inputs=_inputs_flat, 

3025 attrs=_attrs, ctx=ctx, name=name) 

3026 if _execute.must_record_gradient(): 

3027 _execute.record_gradient( 

3028 "NonMaxSuppressionV5", _inputs_flat, _attrs, _result) 

3029 _result = _NonMaxSuppressionV5Output._make(_result) 

3030 return _result 

3031 

3032 

3033def non_max_suppression_with_overlaps(overlaps, scores, max_output_size, overlap_threshold, score_threshold, name=None): 

3034 r"""Greedily selects a subset of bounding boxes in descending order of score, 

3035 

3036 pruning away boxes that have high overlaps 

3037 with previously selected boxes. Bounding boxes with score less than 

3038 `score_threshold` are removed. N-by-n overlap values are supplied as square matrix, 

3039 which allows for defining a custom overlap criterium (eg. intersection over union, 

3040 intersection over area, etc.). 

3041 

3042 The output of this operation is a set of integers indexing into the input 

3043 collection of bounding boxes representing the selected boxes. The bounding 

3044 box coordinates corresponding to the selected indices can then be obtained 

3045 using the `tf.gather operation`. For example: 

3046 

3047 selected_indices = tf.image.non_max_suppression_with_overlaps( 

3048 overlaps, scores, max_output_size, overlap_threshold, score_threshold) 

3049 selected_boxes = tf.gather(boxes, selected_indices) 

3050 

3051 Args: 

3052 overlaps: A `Tensor` of type `float32`. 

3053 A 2-D float tensor of shape `[num_boxes, num_boxes]` representing 

3054 the n-by-n box overlap values. 

3055 scores: A `Tensor` of type `float32`. 

3056 A 1-D float tensor of shape `[num_boxes]` representing a single 

3057 score corresponding to each box (each row of boxes). 

3058 max_output_size: A `Tensor` of type `int32`. 

3059 A scalar integer tensor representing the maximum number of 

3060 boxes to be selected by non max suppression. 

3061 overlap_threshold: A `Tensor` of type `float32`. 

3062 A 0-D float tensor representing the threshold for deciding whether 

3063 boxes overlap too. 

3064 score_threshold: A `Tensor` of type `float32`. 

3065 A 0-D float tensor representing the threshold for deciding when to remove 

3066 boxes based on score. 

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

3068 

3069 Returns: 

3070 A `Tensor` of type `int32`. 

3071 """ 

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

3073 tld = _ctx._thread_local_data 

3074 if tld.is_eager: 

3075 try: 

3076 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

3077 _ctx, "NonMaxSuppressionWithOverlaps", name, overlaps, scores, 

3078 max_output_size, overlap_threshold, score_threshold) 

3079 return _result 

3080 except _core._NotOkStatusException as e: 

3081 _ops.raise_from_not_ok_status(e, name) 

3082 except _core._FallbackException: 

3083 pass 

3084 try: 

3085 return non_max_suppression_with_overlaps_eager_fallback( 

3086 overlaps, scores, max_output_size, overlap_threshold, 

3087 score_threshold, name=name, ctx=_ctx) 

3088 except _core._SymbolicException: 

3089 pass # Add nodes to the TensorFlow graph. 

3090 # Add nodes to the TensorFlow graph. 

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

3092 "NonMaxSuppressionWithOverlaps", overlaps=overlaps, scores=scores, 

3093 max_output_size=max_output_size, 

3094 overlap_threshold=overlap_threshold, 

3095 score_threshold=score_threshold, 

3096 name=name) 

3097 _result = _outputs[:] 

3098 if _execute.must_record_gradient(): 

3099 _attrs = () 

3100 _inputs_flat = _op.inputs 

3101 _execute.record_gradient( 

3102 "NonMaxSuppressionWithOverlaps", _inputs_flat, _attrs, _result) 

3103 _result, = _result 

3104 return _result 

3105 

3106NonMaxSuppressionWithOverlaps = tf_export("raw_ops.NonMaxSuppressionWithOverlaps")(_ops.to_raw_op(non_max_suppression_with_overlaps)) 

3107 

3108 

3109def non_max_suppression_with_overlaps_eager_fallback(overlaps, scores, max_output_size, overlap_threshold, score_threshold, name, ctx): 

3110 overlaps = _ops.convert_to_tensor(overlaps, _dtypes.float32) 

3111 scores = _ops.convert_to_tensor(scores, _dtypes.float32) 

3112 max_output_size = _ops.convert_to_tensor(max_output_size, _dtypes.int32) 

3113 overlap_threshold = _ops.convert_to_tensor(overlap_threshold, _dtypes.float32) 

3114 score_threshold = _ops.convert_to_tensor(score_threshold, _dtypes.float32) 

3115 _inputs_flat = [overlaps, scores, max_output_size, overlap_threshold, score_threshold] 

3116 _attrs = None 

3117 _result = _execute.execute(b"NonMaxSuppressionWithOverlaps", 1, 

3118 inputs=_inputs_flat, attrs=_attrs, ctx=ctx, 

3119 name=name) 

3120 if _execute.must_record_gradient(): 

3121 _execute.record_gradient( 

3122 "NonMaxSuppressionWithOverlaps", _inputs_flat, _attrs, _result) 

3123 _result, = _result 

3124 return _result 

3125 

3126_QuantizedResizeBilinearOutput = collections.namedtuple( 

3127 "QuantizedResizeBilinear", 

3128 ["resized_images", "out_min", "out_max"]) 

3129 

3130 

3131def quantized_resize_bilinear(images, size, min, max, align_corners=False, half_pixel_centers=False, name=None): 

3132 r"""Resize quantized `images` to `size` using quantized bilinear interpolation. 

3133 

3134 Input images and output images must be quantized types. 

3135 

3136 Args: 

3137 images: A `Tensor`. Must be one of the following types: `quint8`, `qint32`, `float32`. 

3138 4-D with shape `[batch, height, width, channels]`. 

3139 size: A 1-D int32 Tensor of 2 elements: `new_height, new_width`. The 

3140 new size for the images. 

3141 min: A `Tensor` of type `float32`. 

3142 max: A `Tensor` of type `float32`. 

3143 align_corners: An optional `bool`. Defaults to `False`. 

3144 If true, the centers of the 4 corner pixels of the input and output tensors are 

3145 aligned, preserving the values at the corner pixels. Defaults to false. 

3146 half_pixel_centers: An optional `bool`. Defaults to `False`. 

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

3148 

3149 Returns: 

3150 A tuple of `Tensor` objects (resized_images, out_min, out_max). 

3151 

3152 resized_images: A `Tensor`. Has the same type as `images`. 

3153 out_min: A `Tensor` of type `float32`. 

3154 out_max: A `Tensor` of type `float32`. 

3155 """ 

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

3157 tld = _ctx._thread_local_data 

3158 if tld.is_eager: 

3159 try: 

3160 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

3161 _ctx, "QuantizedResizeBilinear", name, images, size, min, max, 

3162 "align_corners", align_corners, "half_pixel_centers", 

3163 half_pixel_centers) 

3164 _result = _QuantizedResizeBilinearOutput._make(_result) 

3165 return _result 

3166 except _core._NotOkStatusException as e: 

3167 _ops.raise_from_not_ok_status(e, name) 

3168 except _core._FallbackException: 

3169 pass 

3170 try: 

3171 return quantized_resize_bilinear_eager_fallback( 

3172 images, size, min, max, align_corners=align_corners, 

3173 half_pixel_centers=half_pixel_centers, name=name, ctx=_ctx) 

3174 except _core._SymbolicException: 

3175 pass # Add nodes to the TensorFlow graph. 

3176 # Add nodes to the TensorFlow graph. 

3177 if align_corners is None: 

3178 align_corners = False 

3179 align_corners = _execute.make_bool(align_corners, "align_corners") 

3180 if half_pixel_centers is None: 

3181 half_pixel_centers = False 

3182 half_pixel_centers = _execute.make_bool(half_pixel_centers, "half_pixel_centers") 

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

3184 "QuantizedResizeBilinear", images=images, size=size, min=min, max=max, 

3185 align_corners=align_corners, 

3186 half_pixel_centers=half_pixel_centers, 

3187 name=name) 

3188 _result = _outputs[:] 

3189 if _execute.must_record_gradient(): 

3190 _attrs = ("T", _op._get_attr_type("T"), "align_corners", 

3191 _op._get_attr_bool("align_corners"), "half_pixel_centers", 

3192 _op._get_attr_bool("half_pixel_centers")) 

3193 _inputs_flat = _op.inputs 

3194 _execute.record_gradient( 

3195 "QuantizedResizeBilinear", _inputs_flat, _attrs, _result) 

3196 _result = _QuantizedResizeBilinearOutput._make(_result) 

3197 return _result 

3198 

3199QuantizedResizeBilinear = tf_export("raw_ops.QuantizedResizeBilinear")(_ops.to_raw_op(quantized_resize_bilinear)) 

3200 

3201 

3202def quantized_resize_bilinear_eager_fallback(images, size, min, max, align_corners, half_pixel_centers, name, ctx): 

3203 if align_corners is None: 

3204 align_corners = False 

3205 align_corners = _execute.make_bool(align_corners, "align_corners") 

3206 if half_pixel_centers is None: 

3207 half_pixel_centers = False 

3208 half_pixel_centers = _execute.make_bool(half_pixel_centers, "half_pixel_centers") 

3209 _attr_T, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.quint8, _dtypes.qint32, _dtypes.float32, ]) 

3210 size = _ops.convert_to_tensor(size, _dtypes.int32) 

3211 min = _ops.convert_to_tensor(min, _dtypes.float32) 

3212 max = _ops.convert_to_tensor(max, _dtypes.float32) 

3213 _inputs_flat = [images, size, min, max] 

3214 _attrs = ("T", _attr_T, "align_corners", align_corners, 

3215 "half_pixel_centers", half_pixel_centers) 

3216 _result = _execute.execute(b"QuantizedResizeBilinear", 3, 

3217 inputs=_inputs_flat, attrs=_attrs, ctx=ctx, 

3218 name=name) 

3219 if _execute.must_record_gradient(): 

3220 _execute.record_gradient( 

3221 "QuantizedResizeBilinear", _inputs_flat, _attrs, _result) 

3222 _result = _QuantizedResizeBilinearOutput._make(_result) 

3223 return _result 

3224 

3225 

3226@_dispatch.add_fallback_dispatch_list 

3227@_dispatch.add_type_based_api_dispatcher 

3228@tf_export('image.rgb_to_hsv') 

3229def rgb_to_hsv(images, name=None): 

3230 r"""Converts one or more images from RGB to HSV. 

3231 

3232 Outputs a tensor of the same shape as the `images` tensor, containing the HSV 

3233 value of the pixels. The output is only well defined if the value in `images` 

3234 are in `[0,1]`. 

3235 

3236 `output[..., 0]` contains hue, `output[..., 1]` contains saturation, and 

3237 `output[..., 2]` contains value. All HSV values are in `[0,1]`. A hue of 0 

3238 corresponds to pure red, hue 1/3 is pure green, and 2/3 is pure blue. 

3239 

3240 Usage Example: 

3241 

3242 >>> blue_image = tf.stack([ 

3243 ... tf.zeros([5,5]), 

3244 ... tf.zeros([5,5]), 

3245 ... tf.ones([5,5])], 

3246 ... axis=-1) 

3247 >>> blue_hsv_image = tf.image.rgb_to_hsv(blue_image) 

3248 >>> blue_hsv_image[0,0].numpy() 

3249 array([0.6666667, 1. , 1. ], dtype=float32) 

3250 

3251 Args: 

3252 images: A `Tensor`. Must be one of the following types: `half`, `bfloat16`, `float32`, `float64`. 

3253 1-D or higher rank. RGB data to convert. Last dimension must be size 3. 

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

3255 

3256 Returns: 

3257 A `Tensor`. Has the same type as `images`. 

3258 """ 

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

3260 tld = _ctx._thread_local_data 

3261 if tld.is_eager: 

3262 try: 

3263 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

3264 _ctx, "RGBToHSV", name, images) 

3265 return _result 

3266 except _core._NotOkStatusException as e: 

3267 _ops.raise_from_not_ok_status(e, name) 

3268 except _core._FallbackException: 

3269 pass 

3270 try: 

3271 _result = _dispatcher_for_rgb_to_hsv( 

3272 (images, name,), None) 

3273 if _result is not NotImplemented: 

3274 return _result 

3275 return rgb_to_hsv_eager_fallback( 

3276 images, name=name, ctx=_ctx) 

3277 except _core._SymbolicException: 

3278 pass # Add nodes to the TensorFlow graph. 

3279 except (TypeError, ValueError): 

3280 _result = _dispatch.dispatch( 

3281 rgb_to_hsv, (), dict(images=images, name=name) 

3282 ) 

3283 if _result is not _dispatch.OpDispatcher.NOT_SUPPORTED: 

3284 return _result 

3285 raise 

3286 else: 

3287 _result = _dispatcher_for_rgb_to_hsv( 

3288 (images, name,), None) 

3289 if _result is not NotImplemented: 

3290 return _result 

3291 # Add nodes to the TensorFlow graph. 

3292 try: 

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

3294 "RGBToHSV", images=images, name=name) 

3295 except (TypeError, ValueError): 

3296 _result = _dispatch.dispatch( 

3297 rgb_to_hsv, (), dict(images=images, name=name) 

3298 ) 

3299 if _result is not _dispatch.OpDispatcher.NOT_SUPPORTED: 

3300 return _result 

3301 raise 

3302 _result = _outputs[:] 

3303 if _execute.must_record_gradient(): 

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

3305 _inputs_flat = _op.inputs 

3306 _execute.record_gradient( 

3307 "RGBToHSV", _inputs_flat, _attrs, _result) 

3308 _result, = _result 

3309 return _result 

3310 

3311RGBToHSV = tf_export("raw_ops.RGBToHSV")(_ops.to_raw_op(rgb_to_hsv)) 

3312_dispatcher_for_rgb_to_hsv = rgb_to_hsv._tf_type_based_dispatcher.Dispatch 

3313 

3314 

3315def rgb_to_hsv_eager_fallback(images, name, ctx): 

3316 _attr_T, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.half, _dtypes.bfloat16, _dtypes.float32, _dtypes.float64, ], _dtypes.float32) 

3317 _inputs_flat = [images] 

3318 _attrs = ("T", _attr_T) 

3319 _result = _execute.execute(b"RGBToHSV", 1, inputs=_inputs_flat, 

3320 attrs=_attrs, ctx=ctx, name=name) 

3321 if _execute.must_record_gradient(): 

3322 _execute.record_gradient( 

3323 "RGBToHSV", _inputs_flat, _attrs, _result) 

3324 _result, = _result 

3325 return _result 

3326 

3327 

3328def random_crop(image, size, seed=0, seed2=0, name=None): 

3329 r"""Randomly crop `image`. 

3330 

3331 `size` is a 1-D int64 tensor with 2 elements representing the crop height and 

3332 width. The values must be non negative. 

3333 

3334 This Op picks a random location in `image` and crops a `height` by `width` 

3335 rectangle from that location. The random location is picked so the cropped 

3336 area will fit inside the original image. 

3337 

3338 Args: 

3339 image: A `Tensor`. Must be one of the following types: `uint8`, `int8`, `int16`, `int32`, `int64`, `float32`, `float64`. 

3340 3-D of shape `[height, width, channels]`. 

3341 size: A `Tensor` of type `int64`. 

3342 1-D of length 2 containing: `crop_height`, `crop_width`.. 

3343 seed: An optional `int`. Defaults to `0`. 

3344 If either seed or seed2 are set to be non-zero, the random number 

3345 generator is seeded by the given seed. Otherwise, it is seeded by a 

3346 random seed. 

3347 seed2: An optional `int`. Defaults to `0`. 

3348 An second seed to avoid seed collision. 

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

3350 

3351 Returns: 

3352 A `Tensor`. Has the same type as `image`. 

3353 """ 

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

3355 tld = _ctx._thread_local_data 

3356 if tld.is_eager: 

3357 try: 

3358 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

3359 _ctx, "RandomCrop", name, image, size, "seed", seed, "seed2", seed2) 

3360 return _result 

3361 except _core._NotOkStatusException as e: 

3362 _ops.raise_from_not_ok_status(e, name) 

3363 except _core._FallbackException: 

3364 pass 

3365 try: 

3366 return random_crop_eager_fallback( 

3367 image, size, seed=seed, seed2=seed2, name=name, ctx=_ctx) 

3368 except _core._SymbolicException: 

3369 pass # Add nodes to the TensorFlow graph. 

3370 # Add nodes to the TensorFlow graph. 

3371 if seed is None: 

3372 seed = 0 

3373 seed = _execute.make_int(seed, "seed") 

3374 if seed2 is None: 

3375 seed2 = 0 

3376 seed2 = _execute.make_int(seed2, "seed2") 

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

3378 "RandomCrop", image=image, size=size, seed=seed, seed2=seed2, 

3379 name=name) 

3380 _result = _outputs[:] 

3381 if _execute.must_record_gradient(): 

3382 _attrs = ("T", _op._get_attr_type("T"), "seed", _op._get_attr_int("seed"), 

3383 "seed2", _op._get_attr_int("seed2")) 

3384 _inputs_flat = _op.inputs 

3385 _execute.record_gradient( 

3386 "RandomCrop", _inputs_flat, _attrs, _result) 

3387 _result, = _result 

3388 return _result 

3389 

3390RandomCrop = tf_export("raw_ops.RandomCrop")(_ops.to_raw_op(random_crop)) 

3391 

3392 

3393def random_crop_eager_fallback(image, size, seed, seed2, name, ctx): 

3394 if seed is None: 

3395 seed = 0 

3396 seed = _execute.make_int(seed, "seed") 

3397 if seed2 is None: 

3398 seed2 = 0 

3399 seed2 = _execute.make_int(seed2, "seed2") 

3400 _attr_T, (image,) = _execute.args_to_matching_eager([image], ctx, [_dtypes.uint8, _dtypes.int8, _dtypes.int16, _dtypes.int32, _dtypes.int64, _dtypes.float32, _dtypes.float64, ]) 

3401 size = _ops.convert_to_tensor(size, _dtypes.int64) 

3402 _inputs_flat = [image, size] 

3403 _attrs = ("T", _attr_T, "seed", seed, "seed2", seed2) 

3404 _result = _execute.execute(b"RandomCrop", 1, inputs=_inputs_flat, 

3405 attrs=_attrs, ctx=ctx, name=name) 

3406 if _execute.must_record_gradient(): 

3407 _execute.record_gradient( 

3408 "RandomCrop", _inputs_flat, _attrs, _result) 

3409 _result, = _result 

3410 return _result 

3411 

3412 

3413def resize_area(images, size, align_corners=False, name=None): 

3414 r"""Resize `images` to `size` using area interpolation. 

3415 

3416 Input images can be of different types but output images are always float. 

3417 

3418 The range of pixel values for the output image might be slightly different 

3419 from the range for the input image because of limited numerical precision. 

3420 To guarantee an output range, for example `[0.0, 1.0]`, apply 

3421 `tf.clip_by_value` to the output. 

3422 

3423 Each output pixel is computed by first transforming the pixel's footprint into 

3424 the input tensor and then averaging the pixels that intersect the footprint. An 

3425 input pixel's contribution to the average is weighted by the fraction of its 

3426 area that intersects the footprint. This is the same as OpenCV's INTER_AREA. 

3427 

3428 Args: 

3429 images: A `Tensor`. Must be one of the following types: `int8`, `uint8`, `int16`, `uint16`, `int32`, `int64`, `half`, `float32`, `float64`, `bfloat16`. 

3430 4-D with shape `[batch, height, width, channels]`. 

3431 size: A 1-D int32 Tensor of 2 elements: `new_height, new_width`. The 

3432 new size for the images. 

3433 align_corners: An optional `bool`. Defaults to `False`. 

3434 If true, the centers of the 4 corner pixels of the input and output tensors are 

3435 aligned, preserving the values at the corner pixels. Defaults to false. 

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

3437 

3438 Returns: 

3439 A `Tensor` of type `float32`. 

3440 """ 

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

3442 tld = _ctx._thread_local_data 

3443 if tld.is_eager: 

3444 try: 

3445 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

3446 _ctx, "ResizeArea", name, images, size, "align_corners", 

3447 align_corners) 

3448 return _result 

3449 except _core._NotOkStatusException as e: 

3450 _ops.raise_from_not_ok_status(e, name) 

3451 except _core._FallbackException: 

3452 pass 

3453 try: 

3454 return resize_area_eager_fallback( 

3455 images, size, align_corners=align_corners, name=name, ctx=_ctx) 

3456 except _core._SymbolicException: 

3457 pass # Add nodes to the TensorFlow graph. 

3458 # Add nodes to the TensorFlow graph. 

3459 if align_corners is None: 

3460 align_corners = False 

3461 align_corners = _execute.make_bool(align_corners, "align_corners") 

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

3463 "ResizeArea", images=images, size=size, align_corners=align_corners, 

3464 name=name) 

3465 _result = _outputs[:] 

3466 if _execute.must_record_gradient(): 

3467 _attrs = ("T", _op._get_attr_type("T"), "align_corners", 

3468 _op._get_attr_bool("align_corners")) 

3469 _inputs_flat = _op.inputs 

3470 _execute.record_gradient( 

3471 "ResizeArea", _inputs_flat, _attrs, _result) 

3472 _result, = _result 

3473 return _result 

3474 

3475ResizeArea = tf_export("raw_ops.ResizeArea")(_ops.to_raw_op(resize_area)) 

3476 

3477 

3478def resize_area_eager_fallback(images, size, align_corners, name, ctx): 

3479 if align_corners is None: 

3480 align_corners = False 

3481 align_corners = _execute.make_bool(align_corners, "align_corners") 

3482 _attr_T, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.int8, _dtypes.uint8, _dtypes.int16, _dtypes.uint16, _dtypes.int32, _dtypes.int64, _dtypes.half, _dtypes.float32, _dtypes.float64, _dtypes.bfloat16, ]) 

3483 size = _ops.convert_to_tensor(size, _dtypes.int32) 

3484 _inputs_flat = [images, size] 

3485 _attrs = ("T", _attr_T, "align_corners", align_corners) 

3486 _result = _execute.execute(b"ResizeArea", 1, inputs=_inputs_flat, 

3487 attrs=_attrs, ctx=ctx, name=name) 

3488 if _execute.must_record_gradient(): 

3489 _execute.record_gradient( 

3490 "ResizeArea", _inputs_flat, _attrs, _result) 

3491 _result, = _result 

3492 return _result 

3493 

3494 

3495def resize_bicubic(images, size, align_corners=False, half_pixel_centers=False, name=None): 

3496 r"""Resize `images` to `size` using bicubic interpolation. 

3497 

3498 Input images can be of different types but output images are always float. 

3499 

3500 Args: 

3501 images: A `Tensor`. Must be one of the following types: `int8`, `uint8`, `int16`, `uint16`, `int32`, `int64`, `half`, `float32`, `float64`, `bfloat16`. 

3502 4-D with shape `[batch, height, width, channels]`. 

3503 size: A 1-D int32 Tensor of 2 elements: `new_height, new_width`. The 

3504 new size for the images. 

3505 align_corners: An optional `bool`. Defaults to `False`. 

3506 If true, the centers of the 4 corner pixels of the input and output tensors are 

3507 aligned, preserving the values at the corner pixels. Defaults to false. 

3508 half_pixel_centers: An optional `bool`. Defaults to `False`. 

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

3510 

3511 Returns: 

3512 A `Tensor` of type `float32`. 

3513 """ 

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

3515 tld = _ctx._thread_local_data 

3516 if tld.is_eager: 

3517 try: 

3518 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

3519 _ctx, "ResizeBicubic", name, images, size, "align_corners", 

3520 align_corners, "half_pixel_centers", half_pixel_centers) 

3521 return _result 

3522 except _core._NotOkStatusException as e: 

3523 _ops.raise_from_not_ok_status(e, name) 

3524 except _core._FallbackException: 

3525 pass 

3526 try: 

3527 return resize_bicubic_eager_fallback( 

3528 images, size, align_corners=align_corners, 

3529 half_pixel_centers=half_pixel_centers, name=name, ctx=_ctx) 

3530 except _core._SymbolicException: 

3531 pass # Add nodes to the TensorFlow graph. 

3532 # Add nodes to the TensorFlow graph. 

3533 if align_corners is None: 

3534 align_corners = False 

3535 align_corners = _execute.make_bool(align_corners, "align_corners") 

3536 if half_pixel_centers is None: 

3537 half_pixel_centers = False 

3538 half_pixel_centers = _execute.make_bool(half_pixel_centers, "half_pixel_centers") 

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

3540 "ResizeBicubic", images=images, size=size, 

3541 align_corners=align_corners, 

3542 half_pixel_centers=half_pixel_centers, name=name) 

3543 _result = _outputs[:] 

3544 if _execute.must_record_gradient(): 

3545 _attrs = ("T", _op._get_attr_type("T"), "align_corners", 

3546 _op._get_attr_bool("align_corners"), "half_pixel_centers", 

3547 _op._get_attr_bool("half_pixel_centers")) 

3548 _inputs_flat = _op.inputs 

3549 _execute.record_gradient( 

3550 "ResizeBicubic", _inputs_flat, _attrs, _result) 

3551 _result, = _result 

3552 return _result 

3553 

3554ResizeBicubic = tf_export("raw_ops.ResizeBicubic")(_ops.to_raw_op(resize_bicubic)) 

3555 

3556 

3557def resize_bicubic_eager_fallback(images, size, align_corners, half_pixel_centers, name, ctx): 

3558 if align_corners is None: 

3559 align_corners = False 

3560 align_corners = _execute.make_bool(align_corners, "align_corners") 

3561 if half_pixel_centers is None: 

3562 half_pixel_centers = False 

3563 half_pixel_centers = _execute.make_bool(half_pixel_centers, "half_pixel_centers") 

3564 _attr_T, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.int8, _dtypes.uint8, _dtypes.int16, _dtypes.uint16, _dtypes.int32, _dtypes.int64, _dtypes.half, _dtypes.float32, _dtypes.float64, _dtypes.bfloat16, ]) 

3565 size = _ops.convert_to_tensor(size, _dtypes.int32) 

3566 _inputs_flat = [images, size] 

3567 _attrs = ("T", _attr_T, "align_corners", align_corners, 

3568 "half_pixel_centers", half_pixel_centers) 

3569 _result = _execute.execute(b"ResizeBicubic", 1, inputs=_inputs_flat, 

3570 attrs=_attrs, ctx=ctx, name=name) 

3571 if _execute.must_record_gradient(): 

3572 _execute.record_gradient( 

3573 "ResizeBicubic", _inputs_flat, _attrs, _result) 

3574 _result, = _result 

3575 return _result 

3576 

3577 

3578def resize_bicubic_grad(grads, original_image, align_corners=False, half_pixel_centers=False, name=None): 

3579 r"""Computes the gradient of bicubic interpolation. 

3580 

3581 Args: 

3582 grads: A `Tensor` of type `float32`. 

3583 4-D with shape `[batch, height, width, channels]`. 

3584 original_image: A `Tensor`. Must be one of the following types: `float32`, `float64`. 

3585 4-D with shape `[batch, orig_height, orig_width, channels]`, 

3586 The image tensor that was resized. 

3587 align_corners: An optional `bool`. Defaults to `False`. 

3588 If true, the centers of the 4 corner pixels of the input and grad tensors are 

3589 aligned. Defaults to false. 

3590 half_pixel_centers: An optional `bool`. Defaults to `False`. 

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

3592 

3593 Returns: 

3594 A `Tensor`. Has the same type as `original_image`. 

3595 """ 

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

3597 tld = _ctx._thread_local_data 

3598 if tld.is_eager: 

3599 try: 

3600 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

3601 _ctx, "ResizeBicubicGrad", name, grads, original_image, 

3602 "align_corners", align_corners, "half_pixel_centers", 

3603 half_pixel_centers) 

3604 return _result 

3605 except _core._NotOkStatusException as e: 

3606 _ops.raise_from_not_ok_status(e, name) 

3607 except _core._FallbackException: 

3608 pass 

3609 try: 

3610 return resize_bicubic_grad_eager_fallback( 

3611 grads, original_image, align_corners=align_corners, 

3612 half_pixel_centers=half_pixel_centers, name=name, ctx=_ctx) 

3613 except _core._SymbolicException: 

3614 pass # Add nodes to the TensorFlow graph. 

3615 # Add nodes to the TensorFlow graph. 

3616 if align_corners is None: 

3617 align_corners = False 

3618 align_corners = _execute.make_bool(align_corners, "align_corners") 

3619 if half_pixel_centers is None: 

3620 half_pixel_centers = False 

3621 half_pixel_centers = _execute.make_bool(half_pixel_centers, "half_pixel_centers") 

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

3623 "ResizeBicubicGrad", grads=grads, original_image=original_image, 

3624 align_corners=align_corners, 

3625 half_pixel_centers=half_pixel_centers, name=name) 

3626 _result = _outputs[:] 

3627 if _execute.must_record_gradient(): 

3628 _attrs = ("T", _op._get_attr_type("T"), "align_corners", 

3629 _op._get_attr_bool("align_corners"), "half_pixel_centers", 

3630 _op._get_attr_bool("half_pixel_centers")) 

3631 _inputs_flat = _op.inputs 

3632 _execute.record_gradient( 

3633 "ResizeBicubicGrad", _inputs_flat, _attrs, _result) 

3634 _result, = _result 

3635 return _result 

3636 

3637ResizeBicubicGrad = tf_export("raw_ops.ResizeBicubicGrad")(_ops.to_raw_op(resize_bicubic_grad)) 

3638 

3639 

3640def resize_bicubic_grad_eager_fallback(grads, original_image, align_corners, half_pixel_centers, name, ctx): 

3641 if align_corners is None: 

3642 align_corners = False 

3643 align_corners = _execute.make_bool(align_corners, "align_corners") 

3644 if half_pixel_centers is None: 

3645 half_pixel_centers = False 

3646 half_pixel_centers = _execute.make_bool(half_pixel_centers, "half_pixel_centers") 

3647 _attr_T, (original_image,) = _execute.args_to_matching_eager([original_image], ctx, [_dtypes.float32, _dtypes.float64, ]) 

3648 grads = _ops.convert_to_tensor(grads, _dtypes.float32) 

3649 _inputs_flat = [grads, original_image] 

3650 _attrs = ("T", _attr_T, "align_corners", align_corners, 

3651 "half_pixel_centers", half_pixel_centers) 

3652 _result = _execute.execute(b"ResizeBicubicGrad", 1, inputs=_inputs_flat, 

3653 attrs=_attrs, ctx=ctx, name=name) 

3654 if _execute.must_record_gradient(): 

3655 _execute.record_gradient( 

3656 "ResizeBicubicGrad", _inputs_flat, _attrs, _result) 

3657 _result, = _result 

3658 return _result 

3659 

3660 

3661def resize_bilinear(images, size, align_corners=False, half_pixel_centers=False, name=None): 

3662 r"""Resize `images` to `size` using bilinear interpolation. 

3663 

3664 Input images can be of different types but output images are always float. 

3665 

3666 Args: 

3667 images: A `Tensor`. Must be one of the following types: `int8`, `uint8`, `int16`, `uint16`, `int32`, `int64`, `bfloat16`, `half`, `float32`, `float64`, `bfloat16`. 

3668 4-D with shape `[batch, height, width, channels]`. 

3669 size: A 1-D int32 Tensor of 2 elements: `new_height, new_width`. The 

3670 new size for the images. 

3671 align_corners: An optional `bool`. Defaults to `False`. 

3672 If true, the centers of the 4 corner pixels of the input and output tensors are 

3673 aligned, preserving the values at the corner pixels. Defaults to false. 

3674 half_pixel_centers: An optional `bool`. Defaults to `False`. 

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

3676 

3677 Returns: 

3678 A `Tensor` of type `float32`. 

3679 """ 

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

3681 tld = _ctx._thread_local_data 

3682 if tld.is_eager: 

3683 try: 

3684 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

3685 _ctx, "ResizeBilinear", name, images, size, "align_corners", 

3686 align_corners, "half_pixel_centers", half_pixel_centers) 

3687 return _result 

3688 except _core._NotOkStatusException as e: 

3689 _ops.raise_from_not_ok_status(e, name) 

3690 except _core._FallbackException: 

3691 pass 

3692 try: 

3693 return resize_bilinear_eager_fallback( 

3694 images, size, align_corners=align_corners, 

3695 half_pixel_centers=half_pixel_centers, name=name, ctx=_ctx) 

3696 except _core._SymbolicException: 

3697 pass # Add nodes to the TensorFlow graph. 

3698 # Add nodes to the TensorFlow graph. 

3699 if align_corners is None: 

3700 align_corners = False 

3701 align_corners = _execute.make_bool(align_corners, "align_corners") 

3702 if half_pixel_centers is None: 

3703 half_pixel_centers = False 

3704 half_pixel_centers = _execute.make_bool(half_pixel_centers, "half_pixel_centers") 

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

3706 "ResizeBilinear", images=images, size=size, 

3707 align_corners=align_corners, 

3708 half_pixel_centers=half_pixel_centers, name=name) 

3709 _result = _outputs[:] 

3710 if _execute.must_record_gradient(): 

3711 _attrs = ("T", _op._get_attr_type("T"), "align_corners", 

3712 _op._get_attr_bool("align_corners"), "half_pixel_centers", 

3713 _op._get_attr_bool("half_pixel_centers")) 

3714 _inputs_flat = _op.inputs 

3715 _execute.record_gradient( 

3716 "ResizeBilinear", _inputs_flat, _attrs, _result) 

3717 _result, = _result 

3718 return _result 

3719 

3720ResizeBilinear = tf_export("raw_ops.ResizeBilinear")(_ops.to_raw_op(resize_bilinear)) 

3721 

3722 

3723def resize_bilinear_eager_fallback(images, size, align_corners, half_pixel_centers, name, ctx): 

3724 if align_corners is None: 

3725 align_corners = False 

3726 align_corners = _execute.make_bool(align_corners, "align_corners") 

3727 if half_pixel_centers is None: 

3728 half_pixel_centers = False 

3729 half_pixel_centers = _execute.make_bool(half_pixel_centers, "half_pixel_centers") 

3730 _attr_T, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.int8, _dtypes.uint8, _dtypes.int16, _dtypes.uint16, _dtypes.int32, _dtypes.int64, _dtypes.bfloat16, _dtypes.half, _dtypes.float32, _dtypes.float64, _dtypes.bfloat16, ]) 

3731 size = _ops.convert_to_tensor(size, _dtypes.int32) 

3732 _inputs_flat = [images, size] 

3733 _attrs = ("T", _attr_T, "align_corners", align_corners, 

3734 "half_pixel_centers", half_pixel_centers) 

3735 _result = _execute.execute(b"ResizeBilinear", 1, inputs=_inputs_flat, 

3736 attrs=_attrs, ctx=ctx, name=name) 

3737 if _execute.must_record_gradient(): 

3738 _execute.record_gradient( 

3739 "ResizeBilinear", _inputs_flat, _attrs, _result) 

3740 _result, = _result 

3741 return _result 

3742 

3743 

3744def resize_bilinear_grad(grads, original_image, align_corners=False, half_pixel_centers=False, name=None): 

3745 r"""Computes the gradient of bilinear interpolation. 

3746 

3747 Args: 

3748 grads: A `Tensor` of type `float32`. 

3749 4-D with shape `[batch, height, width, channels]`. 

3750 original_image: A `Tensor`. Must be one of the following types: `float32`, `bfloat16`, `half`, `float64`. 

3751 4-D with shape `[batch, orig_height, orig_width, channels]`, 

3752 The image tensor that was resized. 

3753 align_corners: An optional `bool`. Defaults to `False`. 

3754 If true, the centers of the 4 corner pixels of the input and grad tensors are 

3755 aligned. Defaults to false. 

3756 half_pixel_centers: An optional `bool`. Defaults to `False`. 

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

3758 

3759 Returns: 

3760 A `Tensor`. Has the same type as `original_image`. 

3761 """ 

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

3763 tld = _ctx._thread_local_data 

3764 if tld.is_eager: 

3765 try: 

3766 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

3767 _ctx, "ResizeBilinearGrad", name, grads, original_image, 

3768 "align_corners", align_corners, "half_pixel_centers", 

3769 half_pixel_centers) 

3770 return _result 

3771 except _core._NotOkStatusException as e: 

3772 _ops.raise_from_not_ok_status(e, name) 

3773 except _core._FallbackException: 

3774 pass 

3775 try: 

3776 return resize_bilinear_grad_eager_fallback( 

3777 grads, original_image, align_corners=align_corners, 

3778 half_pixel_centers=half_pixel_centers, name=name, ctx=_ctx) 

3779 except _core._SymbolicException: 

3780 pass # Add nodes to the TensorFlow graph. 

3781 # Add nodes to the TensorFlow graph. 

3782 if align_corners is None: 

3783 align_corners = False 

3784 align_corners = _execute.make_bool(align_corners, "align_corners") 

3785 if half_pixel_centers is None: 

3786 half_pixel_centers = False 

3787 half_pixel_centers = _execute.make_bool(half_pixel_centers, "half_pixel_centers") 

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

3789 "ResizeBilinearGrad", grads=grads, original_image=original_image, 

3790 align_corners=align_corners, 

3791 half_pixel_centers=half_pixel_centers, 

3792 name=name) 

3793 _result = _outputs[:] 

3794 if _execute.must_record_gradient(): 

3795 _attrs = ("T", _op._get_attr_type("T"), "align_corners", 

3796 _op._get_attr_bool("align_corners"), "half_pixel_centers", 

3797 _op._get_attr_bool("half_pixel_centers")) 

3798 _inputs_flat = _op.inputs 

3799 _execute.record_gradient( 

3800 "ResizeBilinearGrad", _inputs_flat, _attrs, _result) 

3801 _result, = _result 

3802 return _result 

3803 

3804ResizeBilinearGrad = tf_export("raw_ops.ResizeBilinearGrad")(_ops.to_raw_op(resize_bilinear_grad)) 

3805 

3806 

3807def resize_bilinear_grad_eager_fallback(grads, original_image, align_corners, half_pixel_centers, name, ctx): 

3808 if align_corners is None: 

3809 align_corners = False 

3810 align_corners = _execute.make_bool(align_corners, "align_corners") 

3811 if half_pixel_centers is None: 

3812 half_pixel_centers = False 

3813 half_pixel_centers = _execute.make_bool(half_pixel_centers, "half_pixel_centers") 

3814 _attr_T, (original_image,) = _execute.args_to_matching_eager([original_image], ctx, [_dtypes.float32, _dtypes.bfloat16, _dtypes.half, _dtypes.float64, ]) 

3815 grads = _ops.convert_to_tensor(grads, _dtypes.float32) 

3816 _inputs_flat = [grads, original_image] 

3817 _attrs = ("T", _attr_T, "align_corners", align_corners, 

3818 "half_pixel_centers", half_pixel_centers) 

3819 _result = _execute.execute(b"ResizeBilinearGrad", 1, inputs=_inputs_flat, 

3820 attrs=_attrs, ctx=ctx, name=name) 

3821 if _execute.must_record_gradient(): 

3822 _execute.record_gradient( 

3823 "ResizeBilinearGrad", _inputs_flat, _attrs, _result) 

3824 _result, = _result 

3825 return _result 

3826 

3827 

3828def resize_nearest_neighbor(images, size, align_corners=False, half_pixel_centers=False, name=None): 

3829 r"""Resize `images` to `size` using nearest neighbor interpolation. 

3830 

3831 Args: 

3832 images: A `Tensor`. Must be one of the following types: `int8`, `uint8`, `int16`, `uint16`, `int32`, `int64`, `half`, `float32`, `float64`, `bfloat16`. 

3833 4-D with shape `[batch, height, width, channels]`. 

3834 size: A 1-D int32 Tensor of 2 elements: `new_height, new_width`. The 

3835 new size for the images. 

3836 align_corners: An optional `bool`. Defaults to `False`. 

3837 If true, the centers of the 4 corner pixels of the input and output tensors are 

3838 aligned, preserving the values at the corner pixels. Defaults to false. 

3839 half_pixel_centers: An optional `bool`. Defaults to `False`. 

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

3841 

3842 Returns: 

3843 A `Tensor`. Has the same type as `images`. 

3844 """ 

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

3846 tld = _ctx._thread_local_data 

3847 if tld.is_eager: 

3848 try: 

3849 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

3850 _ctx, "ResizeNearestNeighbor", name, images, size, "align_corners", 

3851 align_corners, "half_pixel_centers", half_pixel_centers) 

3852 return _result 

3853 except _core._NotOkStatusException as e: 

3854 _ops.raise_from_not_ok_status(e, name) 

3855 except _core._FallbackException: 

3856 pass 

3857 try: 

3858 return resize_nearest_neighbor_eager_fallback( 

3859 images, size, align_corners=align_corners, 

3860 half_pixel_centers=half_pixel_centers, name=name, ctx=_ctx) 

3861 except _core._SymbolicException: 

3862 pass # Add nodes to the TensorFlow graph. 

3863 # Add nodes to the TensorFlow graph. 

3864 if align_corners is None: 

3865 align_corners = False 

3866 align_corners = _execute.make_bool(align_corners, "align_corners") 

3867 if half_pixel_centers is None: 

3868 half_pixel_centers = False 

3869 half_pixel_centers = _execute.make_bool(half_pixel_centers, "half_pixel_centers") 

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

3871 "ResizeNearestNeighbor", images=images, size=size, 

3872 align_corners=align_corners, 

3873 half_pixel_centers=half_pixel_centers, 

3874 name=name) 

3875 _result = _outputs[:] 

3876 if _execute.must_record_gradient(): 

3877 _attrs = ("T", _op._get_attr_type("T"), "align_corners", 

3878 _op._get_attr_bool("align_corners"), "half_pixel_centers", 

3879 _op._get_attr_bool("half_pixel_centers")) 

3880 _inputs_flat = _op.inputs 

3881 _execute.record_gradient( 

3882 "ResizeNearestNeighbor", _inputs_flat, _attrs, _result) 

3883 _result, = _result 

3884 return _result 

3885 

3886ResizeNearestNeighbor = tf_export("raw_ops.ResizeNearestNeighbor")(_ops.to_raw_op(resize_nearest_neighbor)) 

3887 

3888 

3889def resize_nearest_neighbor_eager_fallback(images, size, align_corners, half_pixel_centers, name, ctx): 

3890 if align_corners is None: 

3891 align_corners = False 

3892 align_corners = _execute.make_bool(align_corners, "align_corners") 

3893 if half_pixel_centers is None: 

3894 half_pixel_centers = False 

3895 half_pixel_centers = _execute.make_bool(half_pixel_centers, "half_pixel_centers") 

3896 _attr_T, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.int8, _dtypes.uint8, _dtypes.int16, _dtypes.uint16, _dtypes.int32, _dtypes.int64, _dtypes.half, _dtypes.float32, _dtypes.float64, _dtypes.bfloat16, ]) 

3897 size = _ops.convert_to_tensor(size, _dtypes.int32) 

3898 _inputs_flat = [images, size] 

3899 _attrs = ("T", _attr_T, "align_corners", align_corners, 

3900 "half_pixel_centers", half_pixel_centers) 

3901 _result = _execute.execute(b"ResizeNearestNeighbor", 1, inputs=_inputs_flat, 

3902 attrs=_attrs, ctx=ctx, name=name) 

3903 if _execute.must_record_gradient(): 

3904 _execute.record_gradient( 

3905 "ResizeNearestNeighbor", _inputs_flat, _attrs, _result) 

3906 _result, = _result 

3907 return _result 

3908 

3909 

3910def resize_nearest_neighbor_grad(grads, size, align_corners=False, half_pixel_centers=False, name=None): 

3911 r"""Computes the gradient of nearest neighbor interpolation. 

3912 

3913 Args: 

3914 grads: A `Tensor`. Must be one of the following types: `uint8`, `int8`, `int32`, `half`, `float32`, `float64`, `bfloat16`. 

3915 4-D with shape `[batch, height, width, channels]`. 

3916 size: A 1-D int32 Tensor of 2 elements: `orig_height, orig_width`. The 

3917 original input size. 

3918 align_corners: An optional `bool`. Defaults to `False`. 

3919 If true, the centers of the 4 corner pixels of the input and grad tensors are 

3920 aligned. Defaults to false. 

3921 half_pixel_centers: An optional `bool`. Defaults to `False`. 

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

3923 

3924 Returns: 

3925 A `Tensor`. Has the same type as `grads`. 

3926 """ 

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

3928 tld = _ctx._thread_local_data 

3929 if tld.is_eager: 

3930 try: 

3931 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

3932 _ctx, "ResizeNearestNeighborGrad", name, grads, size, "align_corners", 

3933 align_corners, "half_pixel_centers", half_pixel_centers) 

3934 return _result 

3935 except _core._NotOkStatusException as e: 

3936 _ops.raise_from_not_ok_status(e, name) 

3937 except _core._FallbackException: 

3938 pass 

3939 try: 

3940 return resize_nearest_neighbor_grad_eager_fallback( 

3941 grads, size, align_corners=align_corners, 

3942 half_pixel_centers=half_pixel_centers, name=name, ctx=_ctx) 

3943 except _core._SymbolicException: 

3944 pass # Add nodes to the TensorFlow graph. 

3945 # Add nodes to the TensorFlow graph. 

3946 if align_corners is None: 

3947 align_corners = False 

3948 align_corners = _execute.make_bool(align_corners, "align_corners") 

3949 if half_pixel_centers is None: 

3950 half_pixel_centers = False 

3951 half_pixel_centers = _execute.make_bool(half_pixel_centers, "half_pixel_centers") 

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

3953 "ResizeNearestNeighborGrad", grads=grads, size=size, 

3954 align_corners=align_corners, 

3955 half_pixel_centers=half_pixel_centers, 

3956 name=name) 

3957 _result = _outputs[:] 

3958 if _execute.must_record_gradient(): 

3959 _attrs = ("T", _op._get_attr_type("T"), "align_corners", 

3960 _op._get_attr_bool("align_corners"), "half_pixel_centers", 

3961 _op._get_attr_bool("half_pixel_centers")) 

3962 _inputs_flat = _op.inputs 

3963 _execute.record_gradient( 

3964 "ResizeNearestNeighborGrad", _inputs_flat, _attrs, _result) 

3965 _result, = _result 

3966 return _result 

3967 

3968ResizeNearestNeighborGrad = tf_export("raw_ops.ResizeNearestNeighborGrad")(_ops.to_raw_op(resize_nearest_neighbor_grad)) 

3969 

3970 

3971def resize_nearest_neighbor_grad_eager_fallback(grads, size, align_corners, half_pixel_centers, name, ctx): 

3972 if align_corners is None: 

3973 align_corners = False 

3974 align_corners = _execute.make_bool(align_corners, "align_corners") 

3975 if half_pixel_centers is None: 

3976 half_pixel_centers = False 

3977 half_pixel_centers = _execute.make_bool(half_pixel_centers, "half_pixel_centers") 

3978 _attr_T, (grads,) = _execute.args_to_matching_eager([grads], ctx, [_dtypes.uint8, _dtypes.int8, _dtypes.int32, _dtypes.half, _dtypes.float32, _dtypes.float64, _dtypes.bfloat16, ]) 

3979 size = _ops.convert_to_tensor(size, _dtypes.int32) 

3980 _inputs_flat = [grads, size] 

3981 _attrs = ("T", _attr_T, "align_corners", align_corners, 

3982 "half_pixel_centers", half_pixel_centers) 

3983 _result = _execute.execute(b"ResizeNearestNeighborGrad", 1, 

3984 inputs=_inputs_flat, attrs=_attrs, ctx=ctx, 

3985 name=name) 

3986 if _execute.must_record_gradient(): 

3987 _execute.record_gradient( 

3988 "ResizeNearestNeighborGrad", _inputs_flat, _attrs, _result) 

3989 _result, = _result 

3990 return _result 

3991 

3992_SampleDistortedBoundingBoxOutput = collections.namedtuple( 

3993 "SampleDistortedBoundingBox", 

3994 ["begin", "size", "bboxes"]) 

3995 

3996 

3997def sample_distorted_bounding_box(image_size, bounding_boxes, seed=0, seed2=0, min_object_covered=0.1, aspect_ratio_range=[0.75, 1.33], area_range=[0.05, 1], max_attempts=100, use_image_if_no_bounding_boxes=False, name=None): 

3998 r"""Generate a single randomly distorted bounding box for an image. 

3999 

4000 Bounding box annotations are often supplied in addition to ground-truth labels 

4001 in image recognition or object localization tasks. A common technique for 

4002 training such a system is to randomly distort an image while preserving 

4003 its content, i.e. *data augmentation*. This Op outputs a randomly distorted 

4004 localization of an object, i.e. bounding box, given an `image_size`, 

4005 `bounding_boxes` and a series of constraints. 

4006 

4007 The output of this Op is a single bounding box that may be used to crop the 

4008 original image. The output is returned as 3 tensors: `begin`, `size` and 

4009 `bboxes`. The first 2 tensors can be fed directly into `tf.slice` to crop the 

4010 image. The latter may be supplied to `tf.image.draw_bounding_boxes` to visualize 

4011 what the bounding box looks like. 

4012 

4013 Bounding boxes are supplied and returned as `[y_min, x_min, y_max, x_max]`. The 

4014 bounding box coordinates are floats in `[0.0, 1.0]` relative to the width and 

4015 height of the underlying image. 

4016 

4017 For example, 

4018 

4019 ```python 

4020 # Generate a single distorted bounding box. 

4021 begin, size, bbox_for_draw = tf.image.sample_distorted_bounding_box( 

4022 tf.shape(image), 

4023 bounding_boxes=bounding_boxes) 

4024 

4025 # Draw the bounding box in an image summary. 

4026 image_with_box = tf.image.draw_bounding_boxes(tf.expand_dims(image, 0), 

4027 bbox_for_draw) 

4028 tf.summary.image('images_with_box', image_with_box) 

4029 

4030 # Employ the bounding box to distort the image. 

4031 distorted_image = tf.slice(image, begin, size) 

4032 ``` 

4033 

4034 Note that if no bounding box information is available, setting 

4035 `use_image_if_no_bounding_boxes = true` will assume there is a single implicit 

4036 bounding box covering the whole image. If `use_image_if_no_bounding_boxes` is 

4037 false and no bounding boxes are supplied, an error is raised. 

4038 

4039 Args: 

4040 image_size: A `Tensor`. Must be one of the following types: `uint8`, `int8`, `int16`, `int32`, `int64`. 

4041 1-D, containing `[height, width, channels]`. 

4042 bounding_boxes: A `Tensor` of type `float32`. 

4043 3-D with shape `[batch, N, 4]` describing the N bounding boxes 

4044 associated with the image. 

4045 seed: An optional `int`. Defaults to `0`. 

4046 If either `seed` or `seed2` are set to non-zero, the random number 

4047 generator is seeded by the given `seed`. Otherwise, it is seeded by a random 

4048 seed. 

4049 seed2: An optional `int`. Defaults to `0`. 

4050 A second seed to avoid seed collision. 

4051 min_object_covered: An optional `float`. Defaults to `0.1`. 

4052 The cropped area of the image must contain at least this 

4053 fraction of any bounding box supplied. The value of this parameter should be 

4054 non-negative. In the case of 0, the cropped area does not need to overlap 

4055 any of the bounding boxes supplied. 

4056 aspect_ratio_range: An optional list of `floats`. Defaults to `[0.75, 1.33]`. 

4057 The cropped area of the image must have an aspect ratio = 

4058 width / height within this range. 

4059 area_range: An optional list of `floats`. Defaults to `[0.05, 1]`. 

4060 The cropped area of the image must contain a fraction of the 

4061 supplied image within this range. 

4062 max_attempts: An optional `int`. Defaults to `100`. 

4063 Number of attempts at generating a cropped region of the image 

4064 of the specified constraints. After `max_attempts` failures, return the entire 

4065 image. 

4066 use_image_if_no_bounding_boxes: An optional `bool`. Defaults to `False`. 

4067 Controls behavior if no bounding boxes supplied. 

4068 If true, assume an implicit bounding box covering the whole input. If false, 

4069 raise an error. 

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

4071 

4072 Returns: 

4073 A tuple of `Tensor` objects (begin, size, bboxes). 

4074 

4075 begin: A `Tensor`. Has the same type as `image_size`. 

4076 size: A `Tensor`. Has the same type as `image_size`. 

4077 bboxes: A `Tensor` of type `float32`. 

4078 """ 

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

4080 tld = _ctx._thread_local_data 

4081 if tld.is_eager: 

4082 try: 

4083 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

4084 _ctx, "SampleDistortedBoundingBox", name, image_size, bounding_boxes, 

4085 "seed", seed, "seed2", seed2, "min_object_covered", 

4086 min_object_covered, "aspect_ratio_range", aspect_ratio_range, 

4087 "area_range", area_range, "max_attempts", max_attempts, 

4088 "use_image_if_no_bounding_boxes", use_image_if_no_bounding_boxes) 

4089 _result = _SampleDistortedBoundingBoxOutput._make(_result) 

4090 return _result 

4091 except _core._NotOkStatusException as e: 

4092 _ops.raise_from_not_ok_status(e, name) 

4093 except _core._FallbackException: 

4094 pass 

4095 try: 

4096 return sample_distorted_bounding_box_eager_fallback( 

4097 image_size, bounding_boxes, seed=seed, seed2=seed2, 

4098 min_object_covered=min_object_covered, 

4099 aspect_ratio_range=aspect_ratio_range, area_range=area_range, 

4100 max_attempts=max_attempts, 

4101 use_image_if_no_bounding_boxes=use_image_if_no_bounding_boxes, 

4102 name=name, ctx=_ctx) 

4103 except _core._SymbolicException: 

4104 pass # Add nodes to the TensorFlow graph. 

4105 # Add nodes to the TensorFlow graph. 

4106 if seed is None: 

4107 seed = 0 

4108 seed = _execute.make_int(seed, "seed") 

4109 if seed2 is None: 

4110 seed2 = 0 

4111 seed2 = _execute.make_int(seed2, "seed2") 

4112 if min_object_covered is None: 

4113 min_object_covered = 0.1 

4114 min_object_covered = _execute.make_float(min_object_covered, "min_object_covered") 

4115 if aspect_ratio_range is None: 

4116 aspect_ratio_range = [0.75, 1.33] 

4117 if not isinstance(aspect_ratio_range, (list, tuple)): 

4118 raise TypeError( 

4119 "Expected list for 'aspect_ratio_range' argument to " 

4120 "'sample_distorted_bounding_box' Op, not %r." % aspect_ratio_range) 

4121 aspect_ratio_range = [_execute.make_float(_f, "aspect_ratio_range") for _f in aspect_ratio_range] 

4122 if area_range is None: 

4123 area_range = [0.05, 1] 

4124 if not isinstance(area_range, (list, tuple)): 

4125 raise TypeError( 

4126 "Expected list for 'area_range' argument to " 

4127 "'sample_distorted_bounding_box' Op, not %r." % area_range) 

4128 area_range = [_execute.make_float(_f, "area_range") for _f in area_range] 

4129 if max_attempts is None: 

4130 max_attempts = 100 

4131 max_attempts = _execute.make_int(max_attempts, "max_attempts") 

4132 if use_image_if_no_bounding_boxes is None: 

4133 use_image_if_no_bounding_boxes = False 

4134 use_image_if_no_bounding_boxes = _execute.make_bool(use_image_if_no_bounding_boxes, "use_image_if_no_bounding_boxes") 

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

4136 "SampleDistortedBoundingBox", image_size=image_size, 

4137 bounding_boxes=bounding_boxes, 

4138 seed=seed, seed2=seed2, 

4139 min_object_covered=min_object_covered, 

4140 aspect_ratio_range=aspect_ratio_range, 

4141 area_range=area_range, 

4142 max_attempts=max_attempts, 

4143 use_image_if_no_bounding_boxes=use_image_if_no_bounding_boxes, 

4144 name=name) 

4145 _result = _outputs[:] 

4146 if _execute.must_record_gradient(): 

4147 _attrs = ("T", _op._get_attr_type("T"), "seed", _op._get_attr_int("seed"), 

4148 "seed2", _op._get_attr_int("seed2"), "min_object_covered", 

4149 _op.get_attr("min_object_covered"), "aspect_ratio_range", 

4150 _op.get_attr("aspect_ratio_range"), "area_range", 

4151 _op.get_attr("area_range"), "max_attempts", 

4152 _op._get_attr_int("max_attempts"), 

4153 "use_image_if_no_bounding_boxes", 

4154 _op._get_attr_bool("use_image_if_no_bounding_boxes")) 

4155 _inputs_flat = _op.inputs 

4156 _execute.record_gradient( 

4157 "SampleDistortedBoundingBox", _inputs_flat, _attrs, _result) 

4158 _result = _SampleDistortedBoundingBoxOutput._make(_result) 

4159 return _result 

4160 

4161SampleDistortedBoundingBox = tf_export("raw_ops.SampleDistortedBoundingBox")(_ops.to_raw_op(sample_distorted_bounding_box)) 

4162 

4163 

4164def sample_distorted_bounding_box_eager_fallback(image_size, bounding_boxes, seed, seed2, min_object_covered, aspect_ratio_range, area_range, max_attempts, use_image_if_no_bounding_boxes, name, ctx): 

4165 if seed is None: 

4166 seed = 0 

4167 seed = _execute.make_int(seed, "seed") 

4168 if seed2 is None: 

4169 seed2 = 0 

4170 seed2 = _execute.make_int(seed2, "seed2") 

4171 if min_object_covered is None: 

4172 min_object_covered = 0.1 

4173 min_object_covered = _execute.make_float(min_object_covered, "min_object_covered") 

4174 if aspect_ratio_range is None: 

4175 aspect_ratio_range = [0.75, 1.33] 

4176 if not isinstance(aspect_ratio_range, (list, tuple)): 

4177 raise TypeError( 

4178 "Expected list for 'aspect_ratio_range' argument to " 

4179 "'sample_distorted_bounding_box' Op, not %r." % aspect_ratio_range) 

4180 aspect_ratio_range = [_execute.make_float(_f, "aspect_ratio_range") for _f in aspect_ratio_range] 

4181 if area_range is None: 

4182 area_range = [0.05, 1] 

4183 if not isinstance(area_range, (list, tuple)): 

4184 raise TypeError( 

4185 "Expected list for 'area_range' argument to " 

4186 "'sample_distorted_bounding_box' Op, not %r." % area_range) 

4187 area_range = [_execute.make_float(_f, "area_range") for _f in area_range] 

4188 if max_attempts is None: 

4189 max_attempts = 100 

4190 max_attempts = _execute.make_int(max_attempts, "max_attempts") 

4191 if use_image_if_no_bounding_boxes is None: 

4192 use_image_if_no_bounding_boxes = False 

4193 use_image_if_no_bounding_boxes = _execute.make_bool(use_image_if_no_bounding_boxes, "use_image_if_no_bounding_boxes") 

4194 _attr_T, (image_size,) = _execute.args_to_matching_eager([image_size], ctx, [_dtypes.uint8, _dtypes.int8, _dtypes.int16, _dtypes.int32, _dtypes.int64, ]) 

4195 bounding_boxes = _ops.convert_to_tensor(bounding_boxes, _dtypes.float32) 

4196 _inputs_flat = [image_size, bounding_boxes] 

4197 _attrs = ("T", _attr_T, "seed", seed, "seed2", seed2, "min_object_covered", 

4198 min_object_covered, "aspect_ratio_range", aspect_ratio_range, "area_range", 

4199 area_range, "max_attempts", max_attempts, "use_image_if_no_bounding_boxes", 

4200 use_image_if_no_bounding_boxes) 

4201 _result = _execute.execute(b"SampleDistortedBoundingBox", 3, 

4202 inputs=_inputs_flat, attrs=_attrs, ctx=ctx, 

4203 name=name) 

4204 if _execute.must_record_gradient(): 

4205 _execute.record_gradient( 

4206 "SampleDistortedBoundingBox", _inputs_flat, _attrs, _result) 

4207 _result = _SampleDistortedBoundingBoxOutput._make(_result) 

4208 return _result 

4209 

4210_SampleDistortedBoundingBoxV2Output = collections.namedtuple( 

4211 "SampleDistortedBoundingBoxV2", 

4212 ["begin", "size", "bboxes"]) 

4213 

4214 

4215def sample_distorted_bounding_box_v2(image_size, bounding_boxes, min_object_covered, seed=0, seed2=0, aspect_ratio_range=[0.75, 1.33], area_range=[0.05, 1], max_attempts=100, use_image_if_no_bounding_boxes=False, name=None): 

4216 r"""Generate a single randomly distorted bounding box for an image. 

4217 

4218 Bounding box annotations are often supplied in addition to ground-truth labels 

4219 in image recognition or object localization tasks. A common technique for 

4220 training such a system is to randomly distort an image while preserving 

4221 its content, i.e. *data augmentation*. This Op outputs a randomly distorted 

4222 localization of an object, i.e. bounding box, given an `image_size`, 

4223 `bounding_boxes` and a series of constraints. 

4224 

4225 The output of this Op is a single bounding box that may be used to crop the 

4226 original image. The output is returned as 3 tensors: `begin`, `size` and 

4227 `bboxes`. The first 2 tensors can be fed directly into `tf.slice` to crop the 

4228 image. The latter may be supplied to `tf.image.draw_bounding_boxes` to visualize 

4229 what the bounding box looks like. 

4230 

4231 Bounding boxes are supplied and returned as `[y_min, x_min, y_max, x_max]`. The 

4232 bounding box coordinates are floats in `[0.0, 1.0]` relative to the width and 

4233 height of the underlying image. 

4234 

4235 For example, 

4236 

4237 ```python 

4238 # Generate a single distorted bounding box. 

4239 begin, size, bbox_for_draw = tf.image.sample_distorted_bounding_box( 

4240 tf.shape(image), 

4241 bounding_boxes=bounding_boxes) 

4242 

4243 # Draw the bounding box in an image summary. 

4244 image_with_box = tf.image.draw_bounding_boxes(tf.expand_dims(image, 0), 

4245 bbox_for_draw) 

4246 tf.summary.image('images_with_box', image_with_box) 

4247 

4248 # Employ the bounding box to distort the image. 

4249 distorted_image = tf.slice(image, begin, size) 

4250 ``` 

4251 

4252 Note that if no bounding box information is available, setting 

4253 `use_image_if_no_bounding_boxes = true` will assume there is a single implicit 

4254 bounding box covering the whole image. If `use_image_if_no_bounding_boxes` is 

4255 false and no bounding boxes are supplied, an error is raised. 

4256 

4257 Args: 

4258 image_size: A `Tensor`. Must be one of the following types: `uint8`, `int8`, `int16`, `int32`, `int64`. 

4259 1-D, containing `[height, width, channels]`. 

4260 bounding_boxes: A `Tensor` of type `float32`. 

4261 3-D with shape `[batch, N, 4]` describing the N bounding boxes 

4262 associated with the image. 

4263 min_object_covered: A `Tensor` of type `float32`. 

4264 The cropped area of the image must contain at least this 

4265 fraction of any bounding box supplied. The value of this parameter should be 

4266 non-negative. In the case of 0, the cropped area does not need to overlap 

4267 any of the bounding boxes supplied. 

4268 seed: An optional `int`. Defaults to `0`. 

4269 If either `seed` or `seed2` are set to non-zero, the random number 

4270 generator is seeded by the given `seed`. Otherwise, it is seeded by a random 

4271 seed. 

4272 seed2: An optional `int`. Defaults to `0`. 

4273 A second seed to avoid seed collision. 

4274 aspect_ratio_range: An optional list of `floats`. Defaults to `[0.75, 1.33]`. 

4275 The cropped area of the image must have an aspect ratio = 

4276 width / height within this range. 

4277 area_range: An optional list of `floats`. Defaults to `[0.05, 1]`. 

4278 The cropped area of the image must contain a fraction of the 

4279 supplied image within this range. 

4280 max_attempts: An optional `int`. Defaults to `100`. 

4281 Number of attempts at generating a cropped region of the image 

4282 of the specified constraints. After `max_attempts` failures, return the entire 

4283 image. 

4284 use_image_if_no_bounding_boxes: An optional `bool`. Defaults to `False`. 

4285 Controls behavior if no bounding boxes supplied. 

4286 If true, assume an implicit bounding box covering the whole input. If false, 

4287 raise an error. 

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

4289 

4290 Returns: 

4291 A tuple of `Tensor` objects (begin, size, bboxes). 

4292 

4293 begin: A `Tensor`. Has the same type as `image_size`. 

4294 size: A `Tensor`. Has the same type as `image_size`. 

4295 bboxes: A `Tensor` of type `float32`. 

4296 """ 

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

4298 tld = _ctx._thread_local_data 

4299 if tld.is_eager: 

4300 try: 

4301 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

4302 _ctx, "SampleDistortedBoundingBoxV2", name, image_size, 

4303 bounding_boxes, min_object_covered, "seed", seed, "seed2", seed2, 

4304 "aspect_ratio_range", aspect_ratio_range, "area_range", area_range, 

4305 "max_attempts", max_attempts, "use_image_if_no_bounding_boxes", 

4306 use_image_if_no_bounding_boxes) 

4307 _result = _SampleDistortedBoundingBoxV2Output._make(_result) 

4308 return _result 

4309 except _core._NotOkStatusException as e: 

4310 _ops.raise_from_not_ok_status(e, name) 

4311 except _core._FallbackException: 

4312 pass 

4313 try: 

4314 return sample_distorted_bounding_box_v2_eager_fallback( 

4315 image_size, bounding_boxes, min_object_covered, seed=seed, 

4316 seed2=seed2, aspect_ratio_range=aspect_ratio_range, 

4317 area_range=area_range, max_attempts=max_attempts, 

4318 use_image_if_no_bounding_boxes=use_image_if_no_bounding_boxes, 

4319 name=name, ctx=_ctx) 

4320 except _core._SymbolicException: 

4321 pass # Add nodes to the TensorFlow graph. 

4322 # Add nodes to the TensorFlow graph. 

4323 if seed is None: 

4324 seed = 0 

4325 seed = _execute.make_int(seed, "seed") 

4326 if seed2 is None: 

4327 seed2 = 0 

4328 seed2 = _execute.make_int(seed2, "seed2") 

4329 if aspect_ratio_range is None: 

4330 aspect_ratio_range = [0.75, 1.33] 

4331 if not isinstance(aspect_ratio_range, (list, tuple)): 

4332 raise TypeError( 

4333 "Expected list for 'aspect_ratio_range' argument to " 

4334 "'sample_distorted_bounding_box_v2' Op, not %r." % aspect_ratio_range) 

4335 aspect_ratio_range = [_execute.make_float(_f, "aspect_ratio_range") for _f in aspect_ratio_range] 

4336 if area_range is None: 

4337 area_range = [0.05, 1] 

4338 if not isinstance(area_range, (list, tuple)): 

4339 raise TypeError( 

4340 "Expected list for 'area_range' argument to " 

4341 "'sample_distorted_bounding_box_v2' Op, not %r." % area_range) 

4342 area_range = [_execute.make_float(_f, "area_range") for _f in area_range] 

4343 if max_attempts is None: 

4344 max_attempts = 100 

4345 max_attempts = _execute.make_int(max_attempts, "max_attempts") 

4346 if use_image_if_no_bounding_boxes is None: 

4347 use_image_if_no_bounding_boxes = False 

4348 use_image_if_no_bounding_boxes = _execute.make_bool(use_image_if_no_bounding_boxes, "use_image_if_no_bounding_boxes") 

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

4350 "SampleDistortedBoundingBoxV2", image_size=image_size, 

4351 bounding_boxes=bounding_boxes, 

4352 min_object_covered=min_object_covered, 

4353 seed=seed, seed2=seed2, 

4354 aspect_ratio_range=aspect_ratio_range, 

4355 area_range=area_range, 

4356 max_attempts=max_attempts, 

4357 use_image_if_no_bounding_boxes=use_image_if_no_bounding_boxes, 

4358 name=name) 

4359 _result = _outputs[:] 

4360 if _execute.must_record_gradient(): 

4361 _attrs = ("T", _op._get_attr_type("T"), "seed", _op._get_attr_int("seed"), 

4362 "seed2", _op._get_attr_int("seed2"), "aspect_ratio_range", 

4363 _op.get_attr("aspect_ratio_range"), "area_range", 

4364 _op.get_attr("area_range"), "max_attempts", 

4365 _op._get_attr_int("max_attempts"), 

4366 "use_image_if_no_bounding_boxes", 

4367 _op._get_attr_bool("use_image_if_no_bounding_boxes")) 

4368 _inputs_flat = _op.inputs 

4369 _execute.record_gradient( 

4370 "SampleDistortedBoundingBoxV2", _inputs_flat, _attrs, _result) 

4371 _result = _SampleDistortedBoundingBoxV2Output._make(_result) 

4372 return _result 

4373 

4374SampleDistortedBoundingBoxV2 = tf_export("raw_ops.SampleDistortedBoundingBoxV2")(_ops.to_raw_op(sample_distorted_bounding_box_v2)) 

4375 

4376 

4377def sample_distorted_bounding_box_v2_eager_fallback(image_size, bounding_boxes, min_object_covered, seed, seed2, aspect_ratio_range, area_range, max_attempts, use_image_if_no_bounding_boxes, name, ctx): 

4378 if seed is None: 

4379 seed = 0 

4380 seed = _execute.make_int(seed, "seed") 

4381 if seed2 is None: 

4382 seed2 = 0 

4383 seed2 = _execute.make_int(seed2, "seed2") 

4384 if aspect_ratio_range is None: 

4385 aspect_ratio_range = [0.75, 1.33] 

4386 if not isinstance(aspect_ratio_range, (list, tuple)): 

4387 raise TypeError( 

4388 "Expected list for 'aspect_ratio_range' argument to " 

4389 "'sample_distorted_bounding_box_v2' Op, not %r." % aspect_ratio_range) 

4390 aspect_ratio_range = [_execute.make_float(_f, "aspect_ratio_range") for _f in aspect_ratio_range] 

4391 if area_range is None: 

4392 area_range = [0.05, 1] 

4393 if not isinstance(area_range, (list, tuple)): 

4394 raise TypeError( 

4395 "Expected list for 'area_range' argument to " 

4396 "'sample_distorted_bounding_box_v2' Op, not %r." % area_range) 

4397 area_range = [_execute.make_float(_f, "area_range") for _f in area_range] 

4398 if max_attempts is None: 

4399 max_attempts = 100 

4400 max_attempts = _execute.make_int(max_attempts, "max_attempts") 

4401 if use_image_if_no_bounding_boxes is None: 

4402 use_image_if_no_bounding_boxes = False 

4403 use_image_if_no_bounding_boxes = _execute.make_bool(use_image_if_no_bounding_boxes, "use_image_if_no_bounding_boxes") 

4404 _attr_T, (image_size,) = _execute.args_to_matching_eager([image_size], ctx, [_dtypes.uint8, _dtypes.int8, _dtypes.int16, _dtypes.int32, _dtypes.int64, ]) 

4405 bounding_boxes = _ops.convert_to_tensor(bounding_boxes, _dtypes.float32) 

4406 min_object_covered = _ops.convert_to_tensor(min_object_covered, _dtypes.float32) 

4407 _inputs_flat = [image_size, bounding_boxes, min_object_covered] 

4408 _attrs = ("T", _attr_T, "seed", seed, "seed2", seed2, "aspect_ratio_range", 

4409 aspect_ratio_range, "area_range", area_range, "max_attempts", max_attempts, 

4410 "use_image_if_no_bounding_boxes", use_image_if_no_bounding_boxes) 

4411 _result = _execute.execute(b"SampleDistortedBoundingBoxV2", 3, 

4412 inputs=_inputs_flat, attrs=_attrs, ctx=ctx, 

4413 name=name) 

4414 if _execute.must_record_gradient(): 

4415 _execute.record_gradient( 

4416 "SampleDistortedBoundingBoxV2", _inputs_flat, _attrs, _result) 

4417 _result = _SampleDistortedBoundingBoxV2Output._make(_result) 

4418 return _result 

4419 

4420 

4421def scale_and_translate(images, size, scale, translation, kernel_type="lanczos3", antialias=True, name=None): 

4422 r"""TODO: add doc. 

4423 

4424 Args: 

4425 images: A `Tensor`. Must be one of the following types: `int8`, `uint8`, `int16`, `uint16`, `int32`, `int64`, `bfloat16`, `half`, `float32`, `float64`. 

4426 size: A `Tensor` of type `int32`. 

4427 scale: A `Tensor` of type `float32`. 

4428 translation: A `Tensor` of type `float32`. 

4429 kernel_type: An optional `string`. Defaults to `"lanczos3"`. 

4430 antialias: An optional `bool`. Defaults to `True`. 

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

4432 

4433 Returns: 

4434 A `Tensor` of type `float32`. 

4435 """ 

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

4437 tld = _ctx._thread_local_data 

4438 if tld.is_eager: 

4439 try: 

4440 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

4441 _ctx, "ScaleAndTranslate", name, images, size, scale, translation, 

4442 "kernel_type", kernel_type, "antialias", antialias) 

4443 return _result 

4444 except _core._NotOkStatusException as e: 

4445 _ops.raise_from_not_ok_status(e, name) 

4446 except _core._FallbackException: 

4447 pass 

4448 try: 

4449 return scale_and_translate_eager_fallback( 

4450 images, size, scale, translation, kernel_type=kernel_type, 

4451 antialias=antialias, name=name, ctx=_ctx) 

4452 except _core._SymbolicException: 

4453 pass # Add nodes to the TensorFlow graph. 

4454 # Add nodes to the TensorFlow graph. 

4455 if kernel_type is None: 

4456 kernel_type = "lanczos3" 

4457 kernel_type = _execute.make_str(kernel_type, "kernel_type") 

4458 if antialias is None: 

4459 antialias = True 

4460 antialias = _execute.make_bool(antialias, "antialias") 

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

4462 "ScaleAndTranslate", images=images, size=size, scale=scale, 

4463 translation=translation, kernel_type=kernel_type, 

4464 antialias=antialias, name=name) 

4465 _result = _outputs[:] 

4466 if _execute.must_record_gradient(): 

4467 _attrs = ("T", _op._get_attr_type("T"), "kernel_type", 

4468 _op.get_attr("kernel_type"), "antialias", 

4469 _op._get_attr_bool("antialias")) 

4470 _inputs_flat = _op.inputs 

4471 _execute.record_gradient( 

4472 "ScaleAndTranslate", _inputs_flat, _attrs, _result) 

4473 _result, = _result 

4474 return _result 

4475 

4476ScaleAndTranslate = tf_export("raw_ops.ScaleAndTranslate")(_ops.to_raw_op(scale_and_translate)) 

4477 

4478 

4479def scale_and_translate_eager_fallback(images, size, scale, translation, kernel_type, antialias, name, ctx): 

4480 if kernel_type is None: 

4481 kernel_type = "lanczos3" 

4482 kernel_type = _execute.make_str(kernel_type, "kernel_type") 

4483 if antialias is None: 

4484 antialias = True 

4485 antialias = _execute.make_bool(antialias, "antialias") 

4486 _attr_T, (images,) = _execute.args_to_matching_eager([images], ctx, [_dtypes.int8, _dtypes.uint8, _dtypes.int16, _dtypes.uint16, _dtypes.int32, _dtypes.int64, _dtypes.bfloat16, _dtypes.half, _dtypes.float32, _dtypes.float64, ]) 

4487 size = _ops.convert_to_tensor(size, _dtypes.int32) 

4488 scale = _ops.convert_to_tensor(scale, _dtypes.float32) 

4489 translation = _ops.convert_to_tensor(translation, _dtypes.float32) 

4490 _inputs_flat = [images, size, scale, translation] 

4491 _attrs = ("T", _attr_T, "kernel_type", kernel_type, "antialias", antialias) 

4492 _result = _execute.execute(b"ScaleAndTranslate", 1, inputs=_inputs_flat, 

4493 attrs=_attrs, ctx=ctx, name=name) 

4494 if _execute.must_record_gradient(): 

4495 _execute.record_gradient( 

4496 "ScaleAndTranslate", _inputs_flat, _attrs, _result) 

4497 _result, = _result 

4498 return _result 

4499 

4500 

4501def scale_and_translate_grad(grads, original_image, scale, translation, kernel_type="lanczos3", antialias=True, name=None): 

4502 r"""TODO: add doc. 

4503 

4504 Args: 

4505 grads: A `Tensor`. Must be one of the following types: `float32`. 

4506 original_image: A `Tensor`. Must have the same type as `grads`. 

4507 scale: A `Tensor` of type `float32`. 

4508 translation: A `Tensor` of type `float32`. 

4509 kernel_type: An optional `string`. Defaults to `"lanczos3"`. 

4510 antialias: An optional `bool`. Defaults to `True`. 

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

4512 

4513 Returns: 

4514 A `Tensor`. Has the same type as `grads`. 

4515 """ 

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

4517 tld = _ctx._thread_local_data 

4518 if tld.is_eager: 

4519 try: 

4520 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

4521 _ctx, "ScaleAndTranslateGrad", name, grads, original_image, scale, 

4522 translation, "kernel_type", kernel_type, "antialias", antialias) 

4523 return _result 

4524 except _core._NotOkStatusException as e: 

4525 _ops.raise_from_not_ok_status(e, name) 

4526 except _core._FallbackException: 

4527 pass 

4528 try: 

4529 return scale_and_translate_grad_eager_fallback( 

4530 grads, original_image, scale, translation, kernel_type=kernel_type, 

4531 antialias=antialias, name=name, ctx=_ctx) 

4532 except _core._SymbolicException: 

4533 pass # Add nodes to the TensorFlow graph. 

4534 # Add nodes to the TensorFlow graph. 

4535 if kernel_type is None: 

4536 kernel_type = "lanczos3" 

4537 kernel_type = _execute.make_str(kernel_type, "kernel_type") 

4538 if antialias is None: 

4539 antialias = True 

4540 antialias = _execute.make_bool(antialias, "antialias") 

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

4542 "ScaleAndTranslateGrad", grads=grads, original_image=original_image, 

4543 scale=scale, translation=translation, 

4544 kernel_type=kernel_type, antialias=antialias, 

4545 name=name) 

4546 _result = _outputs[:] 

4547 if _execute.must_record_gradient(): 

4548 _attrs = ("T", _op._get_attr_type("T"), "kernel_type", 

4549 _op.get_attr("kernel_type"), "antialias", 

4550 _op._get_attr_bool("antialias")) 

4551 _inputs_flat = _op.inputs 

4552 _execute.record_gradient( 

4553 "ScaleAndTranslateGrad", _inputs_flat, _attrs, _result) 

4554 _result, = _result 

4555 return _result 

4556 

4557ScaleAndTranslateGrad = tf_export("raw_ops.ScaleAndTranslateGrad")(_ops.to_raw_op(scale_and_translate_grad)) 

4558 

4559 

4560def scale_and_translate_grad_eager_fallback(grads, original_image, scale, translation, kernel_type, antialias, name, ctx): 

4561 if kernel_type is None: 

4562 kernel_type = "lanczos3" 

4563 kernel_type = _execute.make_str(kernel_type, "kernel_type") 

4564 if antialias is None: 

4565 antialias = True 

4566 antialias = _execute.make_bool(antialias, "antialias") 

4567 _attr_T, _inputs_T = _execute.args_to_matching_eager([grads, original_image], ctx, [_dtypes.float32, ]) 

4568 (grads, original_image) = _inputs_T 

4569 scale = _ops.convert_to_tensor(scale, _dtypes.float32) 

4570 translation = _ops.convert_to_tensor(translation, _dtypes.float32) 

4571 _inputs_flat = [grads, original_image, scale, translation] 

4572 _attrs = ("T", _attr_T, "kernel_type", kernel_type, "antialias", antialias) 

4573 _result = _execute.execute(b"ScaleAndTranslateGrad", 1, inputs=_inputs_flat, 

4574 attrs=_attrs, ctx=ctx, name=name) 

4575 if _execute.must_record_gradient(): 

4576 _execute.record_gradient( 

4577 "ScaleAndTranslateGrad", _inputs_flat, _attrs, _result) 

4578 _result, = _result 

4579 return _result 

4580 

4581_StatelessSampleDistortedBoundingBoxOutput = collections.namedtuple( 

4582 "StatelessSampleDistortedBoundingBox", 

4583 ["begin", "size", "bboxes"]) 

4584 

4585 

4586def stateless_sample_distorted_bounding_box(image_size, bounding_boxes, min_object_covered, seed, aspect_ratio_range=[0.75, 1.33], area_range=[0.05, 1], max_attempts=100, use_image_if_no_bounding_boxes=False, name=None): 

4587 r"""Generate a randomly distorted bounding box for an image deterministically. 

4588 

4589 Bounding box annotations are often supplied in addition to ground-truth labels 

4590 in image recognition or object localization tasks. A common technique for 

4591 training such a system is to randomly distort an image while preserving its 

4592 content, i.e. *data augmentation*. This Op, given the same `seed`, 

4593 deterministically outputs a randomly distorted localization of an object, i.e. 

4594 bounding box, given an `image_size`, `bounding_boxes` and a series of 

4595 constraints. 

4596 

4597 The output of this Op is a single bounding box that may be used to crop the 

4598 original image. The output is returned as 3 tensors: `begin`, `size` and 

4599 `bboxes`. The first 2 tensors can be fed directly into `tf.slice` to crop the 

4600 image. The latter may be supplied to `tf.image.draw_bounding_boxes` to visualize 

4601 what the bounding box looks like. 

4602 

4603 Bounding boxes are supplied and returned as `[y_min, x_min, y_max, x_max]`. The 

4604 bounding box coordinates are floats in `[0.0, 1.0]` relative to the width and 

4605 the height of the underlying image. 

4606 

4607 The output of this Op is guaranteed to be the same given the same `seed` and is 

4608 independent of how many times the function is called, and independent of global 

4609 seed settings (e.g. `tf.random.set_seed`). 

4610 

4611 Example usage: 

4612 

4613 >>> image = np.array([[[1], [2], [3]], [[4], [5], [6]], [[7], [8], [9]]]) 

4614 >>> bbox = tf.constant( 

4615 ... [0.0, 0.0, 1.0, 1.0], dtype=tf.float32, shape=[1, 1, 4]) 

4616 >>> seed = (1, 2) 

4617 >>> # Generate a single distorted bounding box. 

4618 >>> bbox_begin, bbox_size, bbox_draw = ( 

4619 ... tf.image.stateless_sample_distorted_bounding_box( 

4620 ... tf.shape(image), bounding_boxes=bbox, seed=seed)) 

4621 >>> # Employ the bounding box to distort the image. 

4622 >>> tf.slice(image, bbox_begin, bbox_size) 

4623 <tf.Tensor: shape=(2, 2, 1), dtype=int64, numpy= 

4624 array([[[1], 

4625 [2]], 

4626 [[4], 

4627 [5]]])> 

4628 >>> # Draw the bounding box in an image summary. 

4629 >>> colors = np.array([[1.0, 0.0, 0.0], [0.0, 0.0, 1.0]]) 

4630 >>> tf.image.draw_bounding_boxes( 

4631 ... tf.expand_dims(tf.cast(image, tf.float32),0), bbox_draw, colors) 

4632 <tf.Tensor: shape=(1, 3, 3, 1), dtype=float32, numpy= 

4633 array([[[[1.], 

4634 [1.], 

4635 [3.]], 

4636 [[1.], 

4637 [1.], 

4638 [6.]], 

4639 [[7.], 

4640 [8.], 

4641 [9.]]]], dtype=float32)> 

4642 

4643 Note that if no bounding box information is available, setting 

4644 `use_image_if_no_bounding_boxes = true` will assume there is a single implicit 

4645 bounding box covering the whole image. If `use_image_if_no_bounding_boxes` is 

4646 false and no bounding boxes are supplied, an error is raised. 

4647 

4648 Args: 

4649 image_size: A `Tensor`. Must be one of the following types: `uint8`, `int8`, `int16`, `int32`, `int64`. 

4650 1-D, containing `[height, width, channels]`. 

4651 bounding_boxes: A `Tensor` of type `float32`. 

4652 3-D with shape `[batch, N, 4]` describing the N bounding boxes 

4653 associated with the image. 

4654 min_object_covered: A `Tensor` of type `float32`. 

4655 The cropped area of the image must contain at least this 

4656 fraction of any bounding box supplied. The value of this parameter should be 

4657 non-negative. In the case of 0, the cropped area does not need to overlap 

4658 any of the bounding boxes supplied. 

4659 seed: A `Tensor`. Must be one of the following types: `int32`, `int64`. 

4660 1-D with shape `[2]`. The seed to the random number generator. Must have dtype 

4661 `int32` or `int64`. (When using XLA, only `int32` is allowed.) 

4662 aspect_ratio_range: An optional list of `floats`. Defaults to `[0.75, 1.33]`. 

4663 The cropped area of the image must have an aspect ratio = 

4664 width / height within this range. 

4665 area_range: An optional list of `floats`. Defaults to `[0.05, 1]`. 

4666 The cropped area of the image must contain a fraction of the 

4667 supplied image within this range. 

4668 max_attempts: An optional `int`. Defaults to `100`. 

4669 Number of attempts at generating a cropped region of the image 

4670 of the specified constraints. After `max_attempts` failures, return the entire 

4671 image. 

4672 use_image_if_no_bounding_boxes: An optional `bool`. Defaults to `False`. 

4673 Controls behavior if no bounding boxes supplied. 

4674 If true, assume an implicit bounding box covering the whole input. If false, 

4675 raise an error. 

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

4677 

4678 Returns: 

4679 A tuple of `Tensor` objects (begin, size, bboxes). 

4680 

4681 begin: A `Tensor`. Has the same type as `image_size`. 

4682 size: A `Tensor`. Has the same type as `image_size`. 

4683 bboxes: A `Tensor` of type `float32`. 

4684 """ 

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

4686 tld = _ctx._thread_local_data 

4687 if tld.is_eager: 

4688 try: 

4689 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

4690 _ctx, "StatelessSampleDistortedBoundingBox", name, image_size, 

4691 bounding_boxes, min_object_covered, seed, "aspect_ratio_range", 

4692 aspect_ratio_range, "area_range", area_range, "max_attempts", 

4693 max_attempts, "use_image_if_no_bounding_boxes", 

4694 use_image_if_no_bounding_boxes) 

4695 _result = _StatelessSampleDistortedBoundingBoxOutput._make(_result) 

4696 return _result 

4697 except _core._NotOkStatusException as e: 

4698 _ops.raise_from_not_ok_status(e, name) 

4699 except _core._FallbackException: 

4700 pass 

4701 try: 

4702 return stateless_sample_distorted_bounding_box_eager_fallback( 

4703 image_size, bounding_boxes, min_object_covered, seed, 

4704 aspect_ratio_range=aspect_ratio_range, area_range=area_range, 

4705 max_attempts=max_attempts, 

4706 use_image_if_no_bounding_boxes=use_image_if_no_bounding_boxes, 

4707 name=name, ctx=_ctx) 

4708 except _core._SymbolicException: 

4709 pass # Add nodes to the TensorFlow graph. 

4710 # Add nodes to the TensorFlow graph. 

4711 if aspect_ratio_range is None: 

4712 aspect_ratio_range = [0.75, 1.33] 

4713 if not isinstance(aspect_ratio_range, (list, tuple)): 

4714 raise TypeError( 

4715 "Expected list for 'aspect_ratio_range' argument to " 

4716 "'stateless_sample_distorted_bounding_box' Op, not %r." % aspect_ratio_range) 

4717 aspect_ratio_range = [_execute.make_float(_f, "aspect_ratio_range") for _f in aspect_ratio_range] 

4718 if area_range is None: 

4719 area_range = [0.05, 1] 

4720 if not isinstance(area_range, (list, tuple)): 

4721 raise TypeError( 

4722 "Expected list for 'area_range' argument to " 

4723 "'stateless_sample_distorted_bounding_box' Op, not %r." % area_range) 

4724 area_range = [_execute.make_float(_f, "area_range") for _f in area_range] 

4725 if max_attempts is None: 

4726 max_attempts = 100 

4727 max_attempts = _execute.make_int(max_attempts, "max_attempts") 

4728 if use_image_if_no_bounding_boxes is None: 

4729 use_image_if_no_bounding_boxes = False 

4730 use_image_if_no_bounding_boxes = _execute.make_bool(use_image_if_no_bounding_boxes, "use_image_if_no_bounding_boxes") 

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

4732 "StatelessSampleDistortedBoundingBox", image_size=image_size, 

4733 bounding_boxes=bounding_boxes, 

4734 min_object_covered=min_object_covered, 

4735 seed=seed, 

4736 aspect_ratio_range=aspect_ratio_range, 

4737 area_range=area_range, 

4738 max_attempts=max_attempts, 

4739 use_image_if_no_bounding_boxes=use_image_if_no_bounding_boxes, 

4740 name=name) 

4741 _result = _outputs[:] 

4742 if _execute.must_record_gradient(): 

4743 _attrs = ("T", _op._get_attr_type("T"), "Tseed", 

4744 _op._get_attr_type("Tseed"), "aspect_ratio_range", 

4745 _op.get_attr("aspect_ratio_range"), "area_range", 

4746 _op.get_attr("area_range"), "max_attempts", 

4747 _op._get_attr_int("max_attempts"), 

4748 "use_image_if_no_bounding_boxes", 

4749 _op._get_attr_bool("use_image_if_no_bounding_boxes")) 

4750 _inputs_flat = _op.inputs 

4751 _execute.record_gradient( 

4752 "StatelessSampleDistortedBoundingBox", _inputs_flat, _attrs, _result) 

4753 _result = _StatelessSampleDistortedBoundingBoxOutput._make(_result) 

4754 return _result 

4755 

4756StatelessSampleDistortedBoundingBox = tf_export("raw_ops.StatelessSampleDistortedBoundingBox")(_ops.to_raw_op(stateless_sample_distorted_bounding_box)) 

4757 

4758 

4759def stateless_sample_distorted_bounding_box_eager_fallback(image_size, bounding_boxes, min_object_covered, seed, aspect_ratio_range, area_range, max_attempts, use_image_if_no_bounding_boxes, name, ctx): 

4760 if aspect_ratio_range is None: 

4761 aspect_ratio_range = [0.75, 1.33] 

4762 if not isinstance(aspect_ratio_range, (list, tuple)): 

4763 raise TypeError( 

4764 "Expected list for 'aspect_ratio_range' argument to " 

4765 "'stateless_sample_distorted_bounding_box' Op, not %r." % aspect_ratio_range) 

4766 aspect_ratio_range = [_execute.make_float(_f, "aspect_ratio_range") for _f in aspect_ratio_range] 

4767 if area_range is None: 

4768 area_range = [0.05, 1] 

4769 if not isinstance(area_range, (list, tuple)): 

4770 raise TypeError( 

4771 "Expected list for 'area_range' argument to " 

4772 "'stateless_sample_distorted_bounding_box' Op, not %r." % area_range) 

4773 area_range = [_execute.make_float(_f, "area_range") for _f in area_range] 

4774 if max_attempts is None: 

4775 max_attempts = 100 

4776 max_attempts = _execute.make_int(max_attempts, "max_attempts") 

4777 if use_image_if_no_bounding_boxes is None: 

4778 use_image_if_no_bounding_boxes = False 

4779 use_image_if_no_bounding_boxes = _execute.make_bool(use_image_if_no_bounding_boxes, "use_image_if_no_bounding_boxes") 

4780 _attr_T, (image_size,) = _execute.args_to_matching_eager([image_size], ctx, [_dtypes.uint8, _dtypes.int8, _dtypes.int16, _dtypes.int32, _dtypes.int64, ]) 

4781 _attr_Tseed, (seed,) = _execute.args_to_matching_eager([seed], ctx, [_dtypes.int32, _dtypes.int64, ]) 

4782 bounding_boxes = _ops.convert_to_tensor(bounding_boxes, _dtypes.float32) 

4783 min_object_covered = _ops.convert_to_tensor(min_object_covered, _dtypes.float32) 

4784 _inputs_flat = [image_size, bounding_boxes, min_object_covered, seed] 

4785 _attrs = ("T", _attr_T, "Tseed", _attr_Tseed, "aspect_ratio_range", 

4786 aspect_ratio_range, "area_range", area_range, "max_attempts", max_attempts, 

4787 "use_image_if_no_bounding_boxes", use_image_if_no_bounding_boxes) 

4788 _result = _execute.execute(b"StatelessSampleDistortedBoundingBox", 3, 

4789 inputs=_inputs_flat, attrs=_attrs, ctx=ctx, 

4790 name=name) 

4791 if _execute.must_record_gradient(): 

4792 _execute.record_gradient( 

4793 "StatelessSampleDistortedBoundingBox", _inputs_flat, _attrs, _result) 

4794 _result = _StatelessSampleDistortedBoundingBoxOutput._make(_result) 

4795 return _result 

4796