Helper class for _with_space_to_batch.
(self,
input_shape,
dilation_rate,
padding,
build_op,
filter_shape=None,
spatial_dims=None,
data_format=None,
fused=False)
| 516 | """ |
| 517 | |
| 518 | def __init__(self, |
| 519 | input_shape, |
| 520 | dilation_rate, |
| 521 | padding, |
| 522 | build_op, |
| 523 | filter_shape=None, |
| 524 | spatial_dims=None, |
| 525 | data_format=None, |
| 526 | fused=False): |
| 527 | """Helper class for _with_space_to_batch.""" |
| 528 | dilation_rate = ops.convert_to_tensor( |
| 529 | dilation_rate, dtypes.int32, name="dilation_rate") |
| 530 | try: |
| 531 | rate_shape = dilation_rate.get_shape().with_rank(1) |
| 532 | except ValueError: |
| 533 | raise ValueError("rate must be rank 1") |
| 534 | |
| 535 | if not dilation_rate.get_shape().is_fully_defined(): |
| 536 | raise ValueError("rate must have known shape") |
| 537 | |
| 538 | num_spatial_dims = rate_shape.dims[0].value |
| 539 | |
| 540 | if data_format is not None and data_format.startswith("NC"): |
| 541 | starting_spatial_dim = 2 |
| 542 | else: |
| 543 | starting_spatial_dim = 1 |
| 544 | |
| 545 | if spatial_dims is None: |
| 546 | spatial_dims = range(starting_spatial_dim, |
| 547 | num_spatial_dims + starting_spatial_dim) |
| 548 | orig_spatial_dims = list(spatial_dims) |
| 549 | spatial_dims = sorted(set(int(x) for x in orig_spatial_dims)) |
| 550 | if spatial_dims != orig_spatial_dims or any(x < 1 for x in spatial_dims): |
| 551 | raise ValueError( |
| 552 | "spatial_dims must be a montonically increasing sequence of positive " |
| 553 | "integers") |
| 554 | |
| 555 | if data_format is not None and data_format.startswith("NC"): |
| 556 | expected_input_rank = spatial_dims[-1] |
| 557 | else: |
| 558 | expected_input_rank = spatial_dims[-1] + 1 |
| 559 | |
| 560 | try: |
| 561 | input_shape.with_rank_at_least(expected_input_rank) |
| 562 | except ValueError: |
| 563 | raise ValueError( |
| 564 | "input tensor must have rank %d at least" % (expected_input_rank)) |
| 565 | |
| 566 | const_rate = tensor_util.constant_value(dilation_rate) |
| 567 | rate_or_const_rate = dilation_rate |
| 568 | can_use_fused = False |
| 569 | if input_shape.ndims is not None: |
| 570 | conv_dims = input_shape.ndims - 2 |
| 571 | can_use_fused = fused and conv_dims <= 2 |
| 572 | if const_rate is not None: |
| 573 | rate_or_const_rate = const_rate |
| 574 | if np.any(const_rate < 1): |
| 575 | raise ValueError("dilation_rate must be positive") |
nothing calls this directly
no test coverage detected