使用ReLU进行数组的输出

阅读 68

2022-04-02

import torch
from torch import nn
from torch.nn import ReLU

input = torch.tensor([[1,-0.5],
                      [-1,3]])
input = torch.reshape(input,(-1,1,2,2))
class Tudui(nn.Module):
    def __init__(self):
        super(Tudui, self).__init__()
        self.relu1 = ReLU()
    def forward(self,input):
        output = self.relu1(input)
        return output
tudui = Tudui()
output = tudui(input)
print(output)

输入,发现负数都变成0了。

tensor([[[[1., 0.],
          [0., 3.]]]])

精彩评论(0)

0 0 举报