Torch.tanh Vs Torch.nn.functional.tanh - PyTorch Forums

Torch.tanh vs torch.nn.functional.tanh April 3, 2018, 7:49pm 1

A little confusing that both exist. Is any of these deprecated?

2 Likes April 3, 2018, 8:13pm 2

we should now deprecate torch.nn.functional.tanh on master, as tensors and variables are now merged.

7 Likes April 4, 2018, 9:24am 4

If I use nn.Tanh I have to declare it in my_model.init(), e.g.

self.tanh = nn.Tanh()

Whereas I can use nn.functional.tanh directly in my_model.forward(), e.g.

output = nn.functional.tanh(input)

If you deprecate nn.functional.tanh I could do

output = nn.Tanh()(input)

where ever I need the functional form, but it would be slower because of the class instantiation.

What has this to do with Variables and Tensors? I am confused.

2 Likes April 4, 2018, 2:08pm 5 jpeg729:

If you deprecate nn.functional.tanh I could do

output = nn.Tanh()(input)

Or you could still use torch.tanh():

output = input.tanh() 5 Likes February 5, 2020, 9:57pm 6

I am expecting output having both positive and negative values. So,

output = torch.tanh(model(input)) in the final output of network should be fine?

Or are any other variants available?

July 7, 2020, 2:13pm 7

There are only few activations like torch.tanh in torch. But for torch.nn.functional , i found alot of functional activations. Why is that?

November 25, 2020, 8:15pm 8

Same confusion here :thinking:

Unfortunately, your browser is unsupported. Please switch to a supported browser to view rich content, log in and reply.

Từ khóa » F.tanh Pytorch