learnergy/visual/tensor.py
def save_tensor(tensor, output_path):
    """Saves a tensor in grayscale mode using Matplotlib.

    Args:
        tensor (Tensor): An input tensor to be saved.
        output_path (str): An outputh path to save the tensor.

    """

    # Creates a matplotlib figure
    plt.figure()

    # Checks if tensor has 3 channels
    if tensor.size(0) == 3:
        # If yes, permutes the tensor
        tensor = tensor.permute(1, 2, 0)

        # Plots without a color map
        plt.imshow(tensor.cpu().detach().numpy())

    # If the tensor is grayscale
    else:
        # Plots the numpy version of the tensor (grayscale)
        plt.imshow(tensor.cpu().detach().numpy(), cmap=plt.cm.get_cmap('gray'))

    # Disables all axis' ticks
    plt.xticks([])
    plt.yticks([])

    # Shows the plot
    plt.savefig(output_path)
Saves a tensor in grayscale mode using Matplotlib.

    Args:
        tensor (Tensor): An input tensor to be saved.
        output_path (str): An outputh path to save the tensor.

    
Saves a tensor in grayscale mode using Matplotlib.
Saves a tensor in grayscale mode using Matplotlib .
def save_tensor(tensor, output_path):
    plt.figure()
    if tensor.size(0) == 3:
        tensor = tensor.permute(1, 2, 0)
        plt.imshow(tensor.cpu().detach().numpy())
    else:
        plt.imshow(tensor.cpu().detach().numpy(), cmap=plt.cm.get_cmap('gray'))
    plt.xticks([])
    plt.yticks([])
    plt.savefig(output_path)
def save_tensor ( tensor , output_path ) : plt . figure ( ) if tensor . size ( 0 ) == 3 : tensor = tensor . permute ( 1 , 2 , 0 ) plt . imshow ( tensor . cpu ( ) . detach ( ) . numpy ( ) ) else : plt . imshow ( tensor . cpu ( ) . detach ( ) . numpy ( ) , cmap = plt . cm . get_cmap ( 'gray' ) ) plt . xticks ( [ ] ) plt . yticks ( [ ] ) plt . savefig ( output_path )
Saves a tensor in grayscale mode using Matplotlib.
Saves a tensor in grayscale mode using Matplotlib .
"""Saves a tensor in grayscale mode using Matplotlib.

    Args:
        tensor (Tensor): An input tensor to be saved.
        output_path (str): An outputh path to save the tensor.

    """ # Creates a matplotlib figure # Checks if tensor has 3 channels # If yes, permutes the tensor # Plots without a color map # If the tensor is grayscale # Plots the numpy version of the tensor (grayscale) # Disables all axis' ticks # Shows the plot
tensor
An input tensor to be saved.
An input tensor to be saved .
output_path
An outputh path to save the tensor.
An outputh path to save the tensor .