示例#1
0
    def forward(self, x):
        x = F.relu(self.conv1_1(x))
        x = F.relu(self.conv1_2(x))
        x = F.pooling(x, 2, 2)

        x = F.relu(self.conv2_1(x))
        x = F.relu(self.conv2_2(x))
        x = F.pooling(x, 2, 2)

        x = F.relu(self.conv3_1(x))
        x = F.relu(self.conv3_2(x))
        x = F.relu(self.conv3_3(x))
        x = F.pooling(x, 2, 2)

        x = F.relu(self.conv4_1(x))
        x = F.relu(self.conv4_2(x))
        x = F.relu(self.conv4_3(x))
        x = F.pooling(x, 2, 2)

        x = F.relu(self.conv5_1(x))
        x = F.relu(self.conv5_2(x))
        x = F.relu(self.conv5_3(x))
        x = F.pooling(x, 2, 2)

        x = F.reshape(x, (x.shape[0], -1))

        x = F.dropout(F.relu(self.fc6(x)))
        x = F.dropout(F.relu(self.fc7(x)))
        x = self.fc8(x)

        return x
示例#2
0
 def forward(self, x):
     x = F.relu(self.conv1(x))  # (OH, OW)=(28, 28)
     x = F.pooling(x, 2, 2)  # (OH, OW)=(14, 14)
     #x = F.relu(self.conv2(x))
     #x = F.pooling(x, 2, 2)
     x = F.reshape(x, (x.shape[0], -1))  # (14, 14)->(196, )
     x = F.dropout(F.relu(self.fc3(x)))
     #x = F.dropout(F.relu(self.fc4(x)))
     x = self.fc5(x)
     return x
示例#3
0
 def forward(self, x):
     x = F.relu(self.conv1_1(x))  # (OH, OW)=(28, 28)
     x = F.relu(self.conv1_2(x))  # (OH, OW)=(28, 28)
     x = F.pooling(x, 2, 2)  # (OH, OW)=(14, 14)
     x = F.relu(self.conv2_1(x))  # (OH, OW)=(14, 14)
     x = F.relu(self.conv2_2(x))  # (OH, OW)=(14, 14)
     x = F.pooling(x, 2, 2)  # (OH, OW)=(7, 7)
     x = F.reshape(x, (x.shape[0], -1))  # (7, 7)->(49, )
     x = F.dropout(F.relu(self.fc3(x)))
     x = self.fc4(x)
     return x
if "__file__" in globals():
    import os, sys

    sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
import numpy as np
from dezero import test_mode
import dezero.functions as F

x = np.ones(5)
print(x)

# When training
y = F.dropout(x)
print(y)

# When testing (predicting)
with test_mode():
    y = F.dropout(x)
    print(y)
示例#5
0
 def test_forward1(self):
     x = np.random.randn(100, 100)
     y = F.dropout(Variable(x), dropout_ratio=0.0)
     res = np.array_equal(y.data, x.data)
     self.assertTrue(res)
示例#6
0
 def f(x):
     np.random.seed(0)
     return F.dropout(x, 0.0)
示例#7
0
 def test_forward2(self):
     x = np.random.randn(100, 100)
     with dezero.test_mode():
         y = F.dropout(x)
     res = array_equal(y.data, x)
     self.assertTrue(res)
示例#8
0
 def test_backward_on_train(self):
     np.random.seed(2)
     x = Variable(np.array([[0., 1.], [2., 3.]]))
     y, = F.dropout(x)
     y.backward()
     assert_equal(x.grad.data, [[0., 0.], [2., 0.]])
示例#9
0
 def test_forward_on_infer(self):
     np.random.seed(2)
     x = np.array([[0., 1.], [2., 3.]])
     with dezero.config.test_mode():
         y, = F.dropout(x)
         assert_equal(y.data, x)
示例#10
0
 def test_forward_on_train(self):
     np.random.seed(2)
     x = np.array([[0., 1.], [2., 3.]])
     mask = np.array([[False, False], [True, False]])
     y, = F.dropout(x)
     assert_equal(y.data, x * mask / 0.5)