From 59487ef2b4c05156562b63b631092ca8985459b7 Mon Sep 17 00:00:00 2001 From: keineahnung2345 Date: Wed, 7 Nov 2018 16:11:19 +0800 Subject: [PATCH] update to torch 0.4 Warning message from old version: /opt/conda/lib/python3.6/site-packages/torch/nn/functional.py:1047: UserWarning: nn.functional.sigmoid is deprecated. Use torch.sigmoid instead. warnings.warn("nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.") --- tutorial-contents/203_activation.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tutorial-contents/203_activation.py b/tutorial-contents/203_activation.py index 079c624..62fb778 100644 --- a/tutorial-contents/203_activation.py +++ b/tutorial-contents/203_activation.py @@ -3,7 +3,7 @@ View more, visit my tutorial page: https://morvanzhou.github.io/tutorials/ My Youtube Channel: https://www.youtube.com/user/MorvanZhou Dependencies: -torch: 0.1.11 +torch: 0.4 matplotlib """ import torch @@ -17,12 +17,11 @@ x = Variable(x) x_np = x.data.numpy() # numpy array for plotting # following are popular activation functions -y_relu = F.relu(x).data.numpy() -y_sigmoid = F.sigmoid(x).data.numpy() -y_tanh = F.tanh(x).data.numpy() -y_softplus = F.softplus(x).data.numpy() -# y_softmax = F.softmax(x) softmax is a special kind of activation function, it is about probability - +y_relu = torch.relu(x).data.numpy() +y_sigmoid = torch.sigmoid(x).data.numpy() +y_tanh = torch.tanh(x).data.numpy() +y_softplus = F.softplus(x).data.numpy() # there's no softplus in torch +# y_softmax = torch.softmax(x, dim=0).data.numpy() softmax is a special kind of activation function, it is about probability # plt to visualize these activation function plt.figure(1, figsize=(8, 6)) @@ -46,4 +45,4 @@ plt.plot(x_np, y_softplus, c='red', label='softplus') plt.ylim((-0.2, 6)) plt.legend(loc='best') -plt.show() \ No newline at end of file +plt.show()