Exemplo n.º 1
0
 def test_globalpooling_forward(self):
     x = np.asarray(rng.uniform(low=-1, high=1, size=(500, 10, 14, 14)))
     x = theano.shared(x, borrow=True)
     gp = N.GlobalPooling()
     y = gp.forward([x])
     y_shape = y[0].eval().shape
     self.assertEqual(y_shape, (500, 10))
Exemplo n.º 2
0
def test_maxout():
    network = N.Network()

    network.setInput(N.RawInput((1, 28, 28)))
    network.append(N.Conv2d(filter_size=(3, 3), feature_map_multiplier=128))
    network.append(N.FeaturePooling(4))
    network.append(N.Pooling((2, 2)))
    network.append(N.Conv2d(filter_size=(3, 3), feature_map_multiplier=8))
    network.append(N.FeaturePooling(4))
    network.append(N.Pooling((2, 2)))
    network.append(N.Conv2d(filter_size=(3, 3), feature_map_multiplier=8))
    network.append(N.FeaturePooling(4))
    network.append(N.GlobalPooling())
    network.append(N.FullConn(input_feature=128, output_feature=10))
    network.append(N.SoftMax())

    network.build()

    trX, trY, teX, teY = l.load_mnist()

    for i in range(5000):
        print(i)
        network.train(trX, trY)
        print(1 - np.mean(
            np.argmax(teY, axis=1) == np.argmax(network.predict(teX), axis=1)))
Exemplo n.º 3
0
def test():
    network = N.Network()
    network.debug = True

    network.setInput(N.RawInput((1, 28, 28)))
    network.append(N.Conv2d(feature_map_multiplier=32))
    network.append(ResLayer())
    network.append(ResLayer())
    network.append(ResLayer())
    network.append(ResLayer(increase_dim=True))
    network.append(ResLayer())
    network.append(ResLayer())
    network.append(ResLayer())
    network.append(ResLayer(increase_dim=True))
    network.append(ResLayer())
    network.append(ResLayer())
    network.append(ResLayer())
    network.append(N.GlobalPooling())
    network.append(N.FullConn(input_feature=128, output_feature=10))
    network.append(N.SoftMax())

    network.build()

    f = h5py.File('/hdd/home/yueguan/workspace/data/mnist/mnist.hdf5', 'r')

    trX = f['x_train'][:, :].reshape(-1, 1, 28, 28)
    teX = f['x_test'][:, :].reshape(-1, 1, 28, 28)

    trY = np.zeros((f['t_train'].shape[0], 10))
    trY[np.arange(len(f['t_train'])), f['t_train']] = 1
    teY = np.zeros((f['t_test'].shape[0], 10))
    teY[np.arange(len(f['t_test'])), f['t_test']] = 1

    for i in range(5000):
        print(i)
        network.train(trX, trY)
        print(1 - np.mean(
            np.argmax(teY, axis=1) == np.argmax(network.predict(teX), axis=1)))
Exemplo n.º 4
0
 def test_globalpooling(self):
     x = np.random.randn(256, 32, 28, 28)
     gp = N.GlobalPooling()
     # TODO
     self.assertEqual(1, 1)
Exemplo n.º 5
0
 def test_globalpooling_forwardSize(self):
     x = [(256, 32, 28, 28)]
     gp = N.GlobalPooling()
     y = gp.forwardSize(x)
     self.assertEqual(y, [(256, 32)])