Add an operation to compute softmax on a tensor. That operation computes the softmax on the input tensor in the dimension 'dim' if specified. Otherwise, it is applied on the last dimension. It inserts a ISoftmaxLayer to the TensorRT graph. Parameters: input : Tensor
(input: Tensor, dim: Optional[int] = None)
| 2637 | |
| 2638 | |
| 2639 | def softmax(input: Tensor, dim: Optional[int] = None) -> Tensor: |
| 2640 | ''' |
| 2641 | Add an operation to compute softmax on a tensor. |
| 2642 | |
| 2643 | That operation computes the softmax on the input tensor in the dimension |
| 2644 | 'dim' if specified. Otherwise, it is applied on the last dimension. |
| 2645 | |
| 2646 | It inserts a ISoftmaxLayer to the TensorRT graph. |
| 2647 | |
| 2648 | Parameters: |
| 2649 | input : Tensor |
| 2650 | The input tensor on which to apply softmax. |
| 2651 | |
| 2652 | dim : Optional[int] |
| 2653 | The dimension used to apply softmax. |
| 2654 | |
| 2655 | Returns: |
| 2656 | The output tensor of the softmax layer. |
| 2657 | ''' |
| 2658 | if dim is None: |
| 2659 | dim = input.ndim() - 1 |
| 2660 | if dim < 0: |
| 2661 | dim = input.ndim() + dim |
| 2662 | axes = dim_to_trt_axes(dim) |
| 2663 | |
| 2664 | layer = default_trtnet().add_softmax(input.trt_tensor) |
| 2665 | layer.axes = axes |
| 2666 | |
| 2667 | return _create_tensor(layer.get_output(0), layer) |
| 2668 | |
| 2669 | |
| 2670 | def _lookup_plugin(input: Tensor, weight: Tensor, rank: int, |
no test coverage detected