import torch
import torchvision.datasets
from torch import nn
#
# m = nn.ReLU()
# nput = torch.randn(2)
# utput = m(input)
#An implementation of CReLU - https://arxiv.org/abs/1603.05201
# m = nn.ReLU()
# input = torch.randn(2).unsqueeze(0)
# output = torch.cat((m(input), m(-input)))
# print(input)
# print(output)
from torch.nn import Sigmoid,Tanh,Softmax
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
input=torch.tensor([[1,-0.5],
[-1,3]])
input=torch.reshape(input,(-1,1,2,2))
print(input.shape)
dataset=torchvision.datasets.CIFAR10("../data",train=False,download=True,transform=torchvision.transforms.ToTensor())
dataloader=DataLoader(dataset,batch_size=64)
class Aoxiang(nn.Module):
def __init__(self):
super(Aoxiang, self).__init__()
self.relu1=torch.nn.ReLU(inplace=False)#inplace=False是否对变量进行一次替换
self.sigmoid1=Sigmoid()
self.tanh1=Tanh()
def forward(self,input):
output=self.sigmoid1(input)
return output
def forward1(self,input):
output=self.tanh1(input)
return output
writer=SummaryWriter("../logs_Tanh")
aoxiang =Aoxiang()
step=0
for data in dataloader:
imgs,target=data
writer.add_images("input",imgs,global_step=step)
output=aoxiang.forward1(imgs)
writer.add_images("output", output, global_step=step)
step=step+1
sigmoid
relu
Tanh