nets.nn.utils — nets 0.1 documentation

Table of Contents
Shortcuts

# Source code for nets.nn.utils

    import nets

    def one_hot(Y, num_classes):
        r"""Perform one-hot encoding on input Y.

        .. math::

            \text{Y'}_{i, j} =
                        \begin{cases}
                          1, &\quad if \quad Y_i = 0 \\
                          0, &\quad else
                        \end{cases}

        Args:
            Y (Tensor): 1D tensor of classes indices of length :math:`N`
            num_classes (int): number of classes :math:`c`

        Returns:
            Tensor: one hot encoded tensor of shape :math:`(N, c)`
        """
        batch_size = len(Y)
        Y_tilde = nets.zeros((batch_size, num_classes))
        Y_tilde[nets.arange(batch_size), Y] = 1
        return Y_tilde.astype(int)

## Docs

Access comprehensive developer documentation for Nets

View Docs

## Tutorials

Get beginners tutorials and create state-of-the-art models

View Tutorials

## Resources

Check the GitHub page and contribute to the project

View GitHub

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.