Ejemplo n.º 1
0
def make_network(minibatch_size=64):
    patch_size = 32
    inp = DataProvider("data",
                       shape=(minibatch_size, 3, patch_size, patch_size))
    label = DataProvider("label", shape=(minibatch_size, ))

    k, l = 20, (40 - 4) // 3
    lay = bn_relu_conv(inp, 3, 1, 1, k, False, False)

    for i in range(3):
        lay = transition(dense_block(lay, k, l), i)

    #global average pooling
    print(lay.partial_shape)
    feature = lay.mean(axis=2).mean(axis=2)
    #feature = Pooling2D("glbpoling", lay, window = 8, stride = 8, mode = "AVERAGE")
    pred = Softmax(
        "pred",
        FullyConnected("fc0", feature, output_dim=10, nonlinearity=Identity()))

    network = Network(outputs=[pred])
    network.loss_var = CrossEntropyLoss(pred, label)

    info = CInfo()
    info.get_complexity(network.outputs).as_table().show()

    return network
Ejemplo n.º 2
0
def make_network(minibatch_size=128, debug=False):
    patch_size = 32
    inp = DataProvider("data",
                       shape=(minibatch_size, 3, patch_size, patch_size),
                       dtype=np.float32)
    label = DataProvider("label", shape=(minibatch_size, ), dtype=np.int32)

    lay = conv_bn(inp, 3, 1, 1, 16 * 4 * 2, True)

    n = 4 * 3
    group = 8
    lis = [16 * 4, 32 * 4, 64 * 4]
    for i in range(len(lis)):
        lay = res_block(lay, lis[i], i, n, group)

    #global average pooling
    #feature = lay.mean(axis = 2).mean(axis = 2)
    feature = Pooling2D("pooling",
                        lay,
                        window=8,
                        stride=8,
                        padding=0,
                        mode="AVERAGE")
    pred = Softmax(
        "pred",
        FullyConnected(
            "fc0",
            feature,
            output_dim=10,
            #W = G(mean = 0, std = (1 / 64)**0.5),
            #b = C(0),
            nonlinearity=Identity()))

    network = Network(outputs=[pred])
    network.loss_var = CrossEntropyLoss(pred, label)

    info = CInfo()
    info.get_complexity(network.outputs).as_table().show()
    """
	if debug:
		visitor = NetworkVisitor(network.loss_var)
		for i in visitor.all_oprs:
			print(i)
			print(i.partial_shape)
			print("input = ", i.inputs)
			print("output = ", i.outputs)
			print()
	"""

    return network