Validate logits args, and create `logits` if necessary. Exactly one of `logits_input` and `logits` must be provided. Args: logits_input: `Tensor` input to `logits`. logits: `Tensor` output. logits_dimension: Integer, last dimension of `logits`. This is used to create `logits`
(logits_input, logits, logits_dimension)
| 590 | |
| 591 | |
| 592 | def _logits(logits_input, logits, logits_dimension): |
| 593 | """Validate logits args, and create `logits` if necessary. |
| 594 | |
| 595 | Exactly one of `logits_input` and `logits` must be provided. |
| 596 | |
| 597 | Args: |
| 598 | logits_input: `Tensor` input to `logits`. |
| 599 | logits: `Tensor` output. |
| 600 | logits_dimension: Integer, last dimension of `logits`. This is used to |
| 601 | create `logits` from `logits_input` if `logits` is `None`; otherwise, it's |
| 602 | used to validate `logits`. |
| 603 | |
| 604 | Returns: |
| 605 | `logits` `Tensor`. |
| 606 | |
| 607 | Raises: |
| 608 | ValueError: if neither or both of `logits` and `logits_input` are supplied. |
| 609 | """ |
| 610 | if (logits_dimension is None) or (logits_dimension < 1): |
| 611 | raise ValueError("Invalid logits_dimension %s." % logits_dimension) |
| 612 | |
| 613 | # If not provided, create logits. |
| 614 | if logits is None: |
| 615 | if logits_input is None: |
| 616 | raise ValueError("Neither logits nor logits_input supplied.") |
| 617 | return layers_lib.linear(logits_input, logits_dimension, scope="logits") |
| 618 | |
| 619 | if logits_input is not None: |
| 620 | raise ValueError("Both logits and logits_input supplied.") |
| 621 | |
| 622 | logits = ops.convert_to_tensor(logits, name="logits") |
| 623 | logits_dims = logits.get_shape().dims |
| 624 | if logits_dims is not None: |
| 625 | logits_dims[-1].assert_is_compatible_with(logits_dimension) |
| 626 | |
| 627 | return logits |
| 628 | |
| 629 | |
| 630 | def _create_model_fn_ops(features, |
no test coverage detected