Suppose I have the following code I want to add sparsity :
import torch.nn as nn
class autoencoder(nn.Module):
def init(self):
super(autoencoder, self).init()
self.encoder = nn.Sequential(
nn.Conv2d(1, 3, 3, stride=1, padding=1),  # b, 16, 10, 10
nn.ReLU(True))
self.decoder = nn.Sequential(
nn.ConvTranspose2d(3, 1, 3, stride=1, padding=1),  # b, 8, 15, 15
nn.ReLU(True),
)
def forward(self, x):
    x = self.encoder(x)
    x = self.decoder(x)
    return x

;