Ejemplo n.º 1
0
 def __call__(self, x):
     x = F.relu(self.linear(x))
     x = F.reshape(x, (-1,) + self.to_shape)  # reshape to (-1, C, H, W)
     x = F.relu(self.deconv(x))
     x = self.conv(x)
     x = F.sigmoid(x)
     return x
Ejemplo n.º 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
Ejemplo n.º 3
0
 def __call__(self, x):
     x = F.relu(self.conv1(x))
     x = F.relu(self.conv2(x))
     x = F.relu(self.conv3(x))
     x = F.relu(self.conv4(x))
     x = F.flatten(x)
     x = F.relu(self.linear1(x))
     z_mean = self.linear2(x)
     z_log_var = self.linear3(x)
     return z_mean, z_log_var
Ejemplo n.º 4
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
Ejemplo n.º 5
0
 def forward(self, x):
     x = F.relu(self.bn1(self.conv1(x)))
     x = F.pooling(x, kernel_size=3, stride=2)
     x = self.res2(x)
     x = self.res3(x)
     x = self.res4(x)
     x = self.res5(x)
     x = _global_average_pooling_2d(x)
     x = self.fc6(x)
     return x
 def forward(self, x):
     x = F.relu(self.l1(x))
     x = F.relu(self.l2(x))
     x = self.l3(x)
     return x
Ejemplo n.º 7
0
 def __call__(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
Ejemplo n.º 8
0
 def forward(self, x):
     h = F.relu(self.bn1(self.conv1(x)))
     h = F.relu(self.bn2(self.conv2(h)))
     h = self.bn3(self.conv3(h))
     return F.relu(h + x)
Ejemplo n.º 9
0
 def forward(self, x):
     h1 = F.relu(self.bn1(self.conv1(x)))
     h1 = F.relu(self.bn2(self.conv2(h1)))
     h1 = self.bn3(self.conv3(h1))
     h2 = self.bn4(self.conv4(x))
     return F.relu(h1 + h2)
 def forward(self, x):
     x = F.relu(self.l1(x))
     x = F.softmax(self.l2(x))
     return x
Ejemplo n.º 11
0
 def test_backward(self):
     x = Variable(np.array([[1, 0, -1, 5], [-1, -2, 5, 0]]))
     y = F.relu(x)
     y.backward()
     assert_equal(x.grad.data, [[1, 0, 0, 1], [0, 0, 1, 0]])
Ejemplo n.º 12
0
 def test_forward(self):
     x = np.array([[1, 0, -1, 5], [-1, -2, 5, 0]])
     y = F.relu(x)
     assert_equal(y.data, [[1, 0, 0, 5], [0, 0, 5, 0]])
Ejemplo n.º 13
0
 def forward(self, x):
     x = F.relu(self.conv1_1)
     x = F.relu(self.conv1_2)
     x = F.pooling(x, 2, 2)
     x = F.relu(self.conv2_1)
     x = F.relu(self.conv2_2)
     x = F.pooling(x, 2, 2)
     x = F.relu(self.conv3_1)
     x = F.relu(self.conv3_2)
     x = F.relu(self.conv3_3)
     x = F.pooling(x, 2, 2)
     x = F.relu(self.conv4_1)
     x = F.relu(self.conv4_2)
     x = F.relu(self.conv4_3)
     x = F.pooling(x, 2, 2)
     x = F.relu(self.conv5_1)
     x = F.relu(self.conv5_2)
     x = F.relu(self.conv5_3)
     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
Ejemplo n.º 14
0
 def test_forward1(self):
     x = np.array([[-1, 0], [2, -3], [-2, 1]], np.float32)
     res = F.relu(x)
     ans = np.array([[0, 0], [2, 0], [0, 1]], np.float32)
     self.assertTrue(array_allclose(res, ans))
Ejemplo n.º 15
0
 def extract(self, x):
     c1_1 = F.relu(self.conv1_1(x))
     c1_2 = F.relu(self.conv1_2(c1_1))
     p1 = F.average_pooling(c1_2, 2, 2)
     c2_1 = F.relu(self.conv2_1(p1))
     c2_2 = F.relu(self.conv2_2(c2_1))
     p2 = F.average_pooling(c2_2, 2, 2)
     c3_1 = F.relu(self.conv3_1(p2))
     c3_2 = F.relu(self.conv3_2(c3_1))
     c3_3 = F.relu(self.conv3_3(c3_2))
     p3 = F.average_pooling(c3_3, 2, 2)
     c4_1 = F.relu(self.conv4_1(p3))
     c4_2 = F.relu(self.conv4_2(c4_1))
     c4_3 = F.relu(self.conv4_3(c4_2))
     p4 = F.average_pooling(c4_3, 2, 2)
     c5_1 = F.relu(self.conv5_1(p4))
     c5_2 = F.relu(self.conv5_2(c5_1))
     c5_3 = F.relu(self.conv5_3(c5_2))
     return {
         'conv1_1': c1_1,
         'conv1_2': c1_2,
         'conv2_1': c2_1,
         'conv2_2': c2_2,
         'conv3_1': c3_1,
         'conv3_2': c3_2,
         'conv3_3': c3_3,
         'conv4_1': c4_1,
         'conv5_1': c5_1,
         'conv5_2': c5_2,
         'conv5_3': c5_3
     }