Ejemplo n.º 1
0
 def __init__(self):
     super(spiral_model, self).__init__()
     self.fc1 = nn.linear(2, 16)
     self.fc2 = nn.linear(16, 16)
     self.fc3 = nn.linear(16, 2)
     self.tanh1 = nn.tanh()
     self.tanh2 = nn.tanh()
     self.sig = nn.relu()
Ejemplo n.º 2
0
 def __init__(self):
     super(cnn_mnist_model, self).__init__()
     self.conv1 = nn.conv2d(1, 32, 3, padding=1)
     self.pool = nn.maxpool2d(2, 2)
     self.conv2 = nn.conv2d(32, 48, 3)
     self.fc1 = nn.linear(48 * 2 * 2, 120) # (599, 192)
     self.fc2 = nn.linear(120, 84)
     self.fc3 = nn.linear(84, 10)
     self.relu1 = nn.relu()
     self.relu2 = nn.relu()
     self.relu3 = nn.relu()
     self.relu4 = nn.relu()
Ejemplo n.º 3
0
def test_linear():
    a = np.random.ranf([3, 5]).astype(np.float32)
    t1 = madml.tensor(a)
    module = nn.linear(5, 5, use_gpu=True)

    t2 = module._forward_cpu(t1)
    y = t2.host_data

    t3 = module._forward_gpu(t1)
    y_hat = t3.download()

    t1.gradient.host_data = a

    print(y_hat == y)

    input()
Ejemplo n.º 4
0
    def test_linear(self):
        import madml
        import madml.nn as nn
        a = np.random.ranf([3, 5]).astype(np.float32)

        t1 = madml.tensor(a)
        self.assertTrue((t1.host_data == a).all())

        module = nn.linear(5, 5)

        t2 = module.forward(t1)
        y = t2.host_data
        module.to(0)
        t3 = module.forward(t1)
        y_hat = t3.download()
        self.assertTrue((y == y_hat).all())
        t2.gradient.host_data = a
        t2.gradient.upload()
        dx = module.backward()
        dx_hat = dx.download()
        print(dx_hat)
        self.assertTrue((dx_hat != 0.0).all())
Ejemplo n.º 5
0
 def __init__(self):
     super(identity_model, self).__init__()
     self.fc1 = nn.linear(32, 32)
     self.fc2 = nn.linear(32, 32)
Ejemplo n.º 6
0
 def __init__(self):
     super(dnn_mnist_model, self).__init__()
     self.fc1 = nn.linear(8 * 8, 256)
     self.fc2 = nn.linear(256, 10)
     self.relu1 = nn.relu()
     self.relu2 = nn.relu()