예제 #1
0
def VGG16(in_layer, num_classes, seed=1234, init=eddl.HeNormal, l2_reg=None, dropout=None):
    x = in_layer
    x = eddl.ReLu(init(eddl.Conv(x, 64, [3, 3]), seed))
    x = eddl.MaxPool(eddl.ReLu(init(eddl.Conv(x, 64, [3, 3]), seed)), [2, 2], [2, 2])
    x = eddl.ReLu(init(eddl.Conv(x, 128, [3, 3]), seed))
    x = eddl.MaxPool(eddl.ReLu(init(eddl.Conv(x, 128, [3, 3]), seed)), [2, 2], [2, 2])
    x = eddl.ReLu(init(eddl.Conv(x, 256, [3, 3]), seed))
    x = eddl.ReLu(init(eddl.Conv(x, 256, [3, 3]), seed))
    x = eddl.MaxPool(eddl.ReLu(init(eddl.Conv(x, 256, [3, 3]), seed)), [2, 2], [2, 2])
    x = eddl.ReLu(init(eddl.Conv(x, 512, [3, 3]), seed))
    x = eddl.ReLu(init(eddl.Conv(x, 512, [3, 3]), seed))
    x = eddl.MaxPool(eddl.ReLu(init(eddl.Conv(x, 512, [3, 3]), seed)), [2, 2], [2, 2])
    x = eddl.ReLu(init(eddl.Conv(x, 512, [3, 3]), seed))
    x = eddl.ReLu(init(eddl.Conv(x, 512, [3, 3]), seed))
    x = eddl.MaxPool(eddl.ReLu(init(eddl.Conv(x, 512, [3, 3]), seed)), [2, 2], [2, 2])
    x = eddl.Reshape(x, [-1])
    x = eddl.Dense(x, 4096)
    if dropout:
        x = eddl.Dropout(x, dropout, iw=False)
    if l2_reg:
        x = eddl.L2(x, l2_reg)
    x = eddl.ReLu(init(x,seed))
    x = eddl.Dense(x, 4096)
    if dropout:
        x = eddl.Dropout(x, dropout, iw=False)
    if l2_reg:
        x = eddl.L2(x, l2_reg)
    x = eddl.ReLu(init(x,seed))
    x = eddl.Softmax(eddl.Dense(x, num_classes))
    return x
예제 #2
0
def LeNet(in_layer, num_classes):
    x = in_layer
    x = eddl.MaxPool(eddl.ReLu(eddl.Conv(x, 20, [5, 5])), [2, 2], [2, 2])
    x = eddl.MaxPool(eddl.ReLu(eddl.Conv(x, 50, [5, 5])), [2, 2], [2, 2])
    x = eddl.Reshape(x, [-1])
    x = eddl.ReLu(eddl.Dense(x, 500))
    x = eddl.Softmax(eddl.Dense(x, num_classes))
    return x
예제 #3
0
def main(args):
    eddl.download_cifar10()

    num_classes = 10

    in_ = eddl.Input([3, 32, 32])

    layer = in_
    layer = eddl.MaxPool(eddl.ReLu(Normalization(
        eddl.Conv(layer, 32, [3, 3], [1, 1])
    )), [2, 2])
    layer = eddl.MaxPool(eddl.ReLu(Normalization(
        eddl.Conv(layer, 64, [3, 3], [1, 1])
    )), [2, 2])
    layer = eddl.MaxPool(eddl.ReLu(Normalization(
        eddl.Conv(layer, 128, [3, 3], [1, 1])
    )), [2, 2])
    layer = eddl.MaxPool(eddl.ReLu(Normalization(
        eddl.Conv(layer, 256, [3, 3], [1, 1])
    )), [2, 2])
    layer = eddl.GlobalMaxPool(layer)
    layer = eddl.Flatten(layer)
    layer = eddl.Activation(eddl.Dense(layer, 128), "relu")

    out = eddl.Softmax(eddl.Dense(layer, num_classes))
    net = eddl.Model([in_], [out])

    eddl.build(
        net,
        eddl.adam(0.001),
        ["soft_cross_entropy"],
        ["categorical_accuracy"],
        eddl.CS_GPU(mem=args.mem) if args.gpu else eddl.CS_CPU(mem=args.mem)
    )

    eddl.summary(net)
    eddl.plot(net, "model.pdf")

    x_train = Tensor.load("cifar_trX.bin")
    y_train = Tensor.load("cifar_trY.bin")
    x_train.div_(255.0)

    x_test = Tensor.load("cifar_tsX.bin")
    y_test = Tensor.load("cifar_tsY.bin")
    x_test.div_(255.0)

    if args.small:
        x_train = x_train.select([":5000"])
        y_train = y_train.select([":5000"])
        x_test = x_test.select([":1000"])
        y_test = y_test.select([":1000"])

    for i in range(args.epochs):
        eddl.fit(net, [x_train], [y_train], args.batch_size, 1)
        eddl.evaluate(net, [x_test], [y_test], bs=args.batch_size)
    print("All done")
예제 #4
0
def main(args):
    eddl.download_cifar10()

    num_classes = 10

    in_ = eddl.Input([3, 32, 32])

    layer = in_

    layer = eddl.RandomCropScale(layer, [0.8, 1.0])
    layer = eddl.RandomFlip(layer, 1)
    layer = eddl.RandomCutout(layer, [0.1, 0.3], [0.1, 0.3])

    layer = eddl.MaxPool(Block3_2(layer, 64))
    layer = eddl.MaxPool(Block3_2(layer, 128))
    layer = eddl.MaxPool(Block1(Block3_2(layer, 256), 256))
    layer = eddl.MaxPool(Block1(Block3_2(layer, 512), 512))
    layer = eddl.MaxPool(Block1(Block3_2(layer, 512), 512))
    layer = eddl.Reshape(layer, [-1])
    layer = eddl.Activation(eddl.Dense(layer, 512), "relu")

    out = eddl.Softmax(eddl.Dense(layer, num_classes))
    net = eddl.Model([in_], [out])

    eddl.build(
        net,
        eddl.sgd(0.001, 0.9),
        ["soft_cross_entropy"],
        ["categorical_accuracy"],
        eddl.CS_GPU(mem=args.mem) if args.gpu else eddl.CS_CPU(mem=args.mem)
    )

    eddl.setlogfile(net, "vgg16")
    eddl.summary(net)
    eddl.plot(net, "model.pdf")

    x_train = Tensor.load("cifar_trX.bin")
    y_train = Tensor.load("cifar_trY.bin")
    x_train.div_(255.0)

    x_test = Tensor.load("cifar_tsX.bin")
    y_test = Tensor.load("cifar_tsY.bin")
    x_test.div_(255.0)

    if args.small:
        x_train = x_train.select([":5000"])
        y_train = y_train.select([":5000"])
        x_test = x_test.select([":1000"])
        y_test = y_test.select([":1000"])

    for i in range(args.epochs):
        eddl.fit(net, [x_train], [y_train], args.batch_size, 1)
        eddl.evaluate(net, [x_test], [y_test], bs=args.batch_size)
    print("All done")
예제 #5
0
def UNetWithPadding(layer):
    x = layer
    depth = 32

    x = LBC(x, depth, [3, 3], [1, 1], "same")
    x = LBC(x, depth, [3, 3], [1, 1], "same")
    x2 = eddl.MaxPool(x, [2, 2], [2, 2])
    x2 = LBC(x2, 2*depth, [3, 3], [1, 1], "same")
    x2 = LBC(x2, 2*depth, [3, 3], [1, 1], "same")
    x3 = eddl.MaxPool(x2, [2, 2], [2, 2])
    x3 = LBC(x3, 4*depth, [3, 3], [1, 1], "same")
    x3 = LBC(x3, 4*depth, [3, 3], [1, 1], "same")
    x4 = eddl.MaxPool(x3, [2, 2], [2, 2])
    x4 = LBC(x4, 8*depth, [3, 3], [1, 1], "same")
    x4 = LBC(x4, 8*depth, [3, 3], [1, 1], "same")
    x5 = eddl.MaxPool(x4, [2, 2], [2, 2])
    x5 = LBC(x5, 8*depth, [3, 3], [1, 1], "same")
    x5 = LBC(x5, 8*depth, [3, 3], [1, 1], "same")
    x5 = eddl.BatchNormalization(eddl.Conv(
        eddl.UpSampling(x5, [2, 2]), 8*depth, [3, 3], [1, 1], "same"
    ), True)

    x4 = eddl.Concat([x4, x5]) if USE_CONCAT else eddl.Add([x4, x5])
    x4 = LBC(x4, 8*depth, [3, 3], [1, 1], "same")
    x4 = LBC(x4, 8*depth, [3, 3], [1, 1], "same")
    x4 = eddl.BatchNormalization(eddl.Conv(
        eddl.UpSampling(x4, [2, 2]), 4*depth, [3, 3], [1, 1], "same"
    ), True)

    x3 = eddl.Concat([x3, x4]) if USE_CONCAT else eddl.Add([x3, x4])
    x3 = LBC(x3, 4*depth, [3, 3], [1, 1], "same")
    x3 = LBC(x3, 4*depth, [3, 3], [1, 1], "same")
    x3 = eddl.Conv(
        eddl.UpSampling(x3, [2, 2]), 2*depth, [3, 3], [1, 1], "same"
    )

    x2 = eddl.Concat([x2, x3]) if USE_CONCAT else eddl.Add([x2, x3])
    x2 = LBC(x2, 2*depth, [3, 3], [1, 1], "same")
    x2 = LBC(x2, 2*depth, [3, 3], [1, 1], "same")
    x2 = eddl.BatchNormalization(eddl.Conv(
        eddl.UpSampling(x2, [2, 2]), depth, [3, 3], [1, 1], "same"
    ), True)

    x = eddl.Concat([x, x2]) if USE_CONCAT else eddl.Add([x, x2])
    x = LBC(x, depth, [3, 3], [1, 1], "same")
    x = LBC(x, depth, [3, 3], [1, 1], "same")
    x = eddl.BatchNormalization(eddl.Conv(x, 1, [1, 1]), True)

    return x
def defblock(l, bn, nf, reps, initializer):
    for i in range(reps):
        l = initializer(eddl.Conv(l, nf, [3, 3]))
        if bn:
            l = eddl.BatchNormalization(l, 0.99, 0.001, True, "")
        l = eddl.ReLu(l)
    l = eddl.MaxPool(l, [2, 2], [2, 2], "valid")
    return l
예제 #7
0
def main(args):
    eddl.download_cifar10()

    num_classes = 10

    in_ = eddl.Input([3, 32, 32])

    layer = in_
    layer = eddl.RandomCropScale(layer, [0.8, 1.0])
    layer = eddl.RandomHorizontalFlip(layer)
    layer = eddl.ReLu(BG(eddl.Conv(layer, 64, [3, 3], [1, 1], "same", False)))
    layer = eddl.Pad(layer, [0, 1, 1, 0])
    for i in range(3):
        layer = ResBlock(layer, 64, 0, i == 0)
    for i in range(4):
        layer = ResBlock(layer, 128, i == 0)
    for i in range(6):
        layer = ResBlock(layer, 256, i == 0)
    for i in range(3):
        layer = ResBlock(layer, 512, i == 0)
    layer = eddl.MaxPool(layer, [4, 4])
    layer = eddl.Reshape(layer, [-1])

    out = eddl.Softmax(eddl.Dense(layer, num_classes))
    net = eddl.Model([in_], [out])

    eddl.build(
        net, eddl.sgd(0.001, 0.9), ["soft_cross_entropy"],
        ["categorical_accuracy"],
        eddl.CS_GPU(mem=args.mem) if args.gpu else eddl.CS_CPU(mem=args.mem))

    eddl.summary(net)
    eddl.plot(net, "model.pdf", "TB")

    x_train = Tensor.load("cifar_trX.bin")
    y_train = Tensor.load("cifar_trY.bin")
    x_train.div_(255.0)

    x_test = Tensor.load("cifar_tsX.bin")
    y_test = Tensor.load("cifar_tsY.bin")
    x_test.div_(255.0)

    if args.small:
        # this is slow, make it really small
        x_train = x_train.select([":500"])
        y_train = y_train.select([":500"])
        x_test = x_test.select([":100"])
        y_test = y_test.select([":100"])

    lr = 0.01
    for j in range(3):
        lr /= 10.0
        eddl.setlr(net, [lr, 0.9])
        for i in range(args.epochs):
            eddl.fit(net, [x_train], [y_train], args.batch_size, 1)
            eddl.evaluate(net, [x_test], [y_test], bs=args.batch_size)
    print("All done")
예제 #8
0
def VGG16(in_layer, num_classes):
    x = in_layer
    x = eddl.ReLu(eddl.Conv(x, 64, [3, 3]))
    x = eddl.MaxPool(eddl.ReLu(eddl.Conv(x, 64, [3, 3])), [2, 2], [2, 2])
    x = eddl.ReLu(eddl.Conv(x, 128, [3, 3]))
    x = eddl.MaxPool(eddl.ReLu(eddl.Conv(x, 128, [3, 3])), [2, 2], [2, 2])
    x = eddl.ReLu(eddl.Conv(x, 256, [3, 3]))
    x = eddl.ReLu(eddl.Conv(x, 256, [3, 3]))
    x = eddl.MaxPool(eddl.ReLu(eddl.Conv(x, 256, [3, 3])), [2, 2], [2, 2])
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3]))
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3]))
    x = eddl.MaxPool(eddl.ReLu(eddl.Conv(x, 512, [3, 3])), [2, 2], [2, 2])
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3]))
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3]))
    x = eddl.MaxPool(eddl.ReLu(eddl.Conv(x, 512, [3, 3])), [2, 2], [2, 2])
    x = eddl.Reshape(x, [-1])
    x = eddl.ReLu(eddl.Dense(x, 256))
    x = eddl.Softmax(eddl.Dense(x, num_classes))
    return x
예제 #9
0
def main(args):
    eddl.download_mnist()

    num_classes = 10

    in_ = eddl.Input([784])
    layer = in_
    layer = eddl.Reshape(layer, [1, 28, 28])
    layer = eddl.MaxPool(eddl.ReLu(eddl.Conv(layer, 32, [3, 3], [1, 1])),
                         [3, 3], [1, 1], "same")
    layer = eddl.MaxPool(eddl.ReLu(eddl.Conv(layer, 64, [3, 3], [1, 1])),
                         [2, 2], [2, 2], "same")
    layer = eddl.MaxPool(eddl.ReLu(eddl.Conv(layer, 128, [3, 3], [1, 1])),
                         [3, 3], [2, 2], "none")
    layer = eddl.MaxPool(eddl.ReLu(eddl.Conv(layer, 256, [3, 3], [1, 1])),
                         [2, 2], [2, 2], "none")
    layer = eddl.Reshape(layer, [-1])
    out = eddl.Softmax(eddl.Dense(layer, num_classes))
    net = eddl.Model([in_], [out])

    eddl.build(
        net, eddl.rmsprop(0.01), ["soft_cross_entropy"],
        ["categorical_accuracy"],
        eddl.CS_GPU(mem=args.mem) if args.gpu else eddl.CS_CPU(mem=args.mem))

    eddl.summary(net)

    x_train = Tensor.load("mnist_trX.bin")
    y_train = Tensor.load("mnist_trY.bin")
    x_test = Tensor.load("mnist_tsX.bin")
    y_test = Tensor.load("mnist_tsY.bin")
    if args.small:
        x_train = x_train.select([":6000"])
        y_train = y_train.select([":6000"])
        x_test = x_test.select([":1000"])
        y_test = y_test.select([":1000"])
    x_train.div_(255.0)
    x_test.div_(255.0)

    eddl.fit(net, [x_train], [y_train], args.batch_size, args.epochs)
    eddl.evaluate(net, [x_test], [y_test], bs=args.batch_size)
    print("All done")
예제 #10
0
def SegNet(in_layer, num_classes):
    x = in_layer
    x = eddl.ReLu(eddl.Conv(x, 64, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 64, [3, 3], [1, 1], "same"))
    x = eddl.MaxPool(x, [2, 2], [2, 2])
    x = eddl.ReLu(eddl.Conv(x, 128, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 128, [3, 3], [1, 1], "same"))
    x = eddl.MaxPool(x, [2, 2], [2, 2])
    x = eddl.ReLu(eddl.Conv(x, 256, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 256, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 256, [3, 3], [1, 1], "same"))
    x = eddl.MaxPool(x, [2, 2], [2, 2])
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3], [1, 1], "same"))
    x = eddl.MaxPool(x, [2, 2], [2, 2])
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3], [1, 1], "same"))
    x = eddl.MaxPool(x, [2, 2], [2, 2])
    x = eddl.UpSampling(x, [2, 2])
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3], [1, 1], "same"))
    x = eddl.UpSampling(x, [2, 2])
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 512, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 256, [3, 3], [1, 1], "same"))
    x = eddl.UpSampling(x, [2, 2])
    x = eddl.ReLu(eddl.Conv(x, 256, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 256, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 128, [3, 3], [1, 1], "same"))
    x = eddl.UpSampling(x, [2, 2])
    x = eddl.ReLu(eddl.Conv(x, 128, [3, 3], [1, 1], "same"))
    x = eddl.ReLu(eddl.Conv(x, 64, [3, 3], [1, 1], "same"))
    x = eddl.UpSampling(x, [2, 2])
    x = eddl.ReLu(eddl.Conv(x, 64, [3, 3], [1, 1], "same"))
    x = eddl.Conv(x, num_classes, [3, 3], [1, 1], "same")
    return x
예제 #11
0
def main(args):
    eddl.download_cifar10()

    num_classes = 10

    in_ = eddl.Input([3, 32, 32])

    layer = in_

    layer = eddl.RandomHorizontalFlip(layer)
    layer = eddl.RandomCropScale(layer, [0.8, 1.0])
    layer = eddl.RandomCutout(layer, [0.1, 0.5], [0.1, 0.5])

    layer = eddl.MaxPool(eddl.ReLu(eddl.BatchNormalization(
        eddl.HeUniform(eddl.Conv(layer, 32, [3, 3], [1, 1], "same", False)),
        True)), [2, 2])
    layer = eddl.MaxPool(eddl.ReLu(eddl.BatchNormalization(
        eddl.HeUniform(eddl.Conv(layer, 64, [3, 3], [1, 1], "same", False)),
        True)), [2, 2])
    layer = eddl.MaxPool(eddl.ReLu(eddl.BatchNormalization(
        eddl.HeUniform(eddl.Conv(layer, 128, [3, 3], [1, 1], "same", False)),
        True)), [2, 2])
    layer = eddl.MaxPool(eddl.ReLu(eddl.BatchNormalization(
        eddl.HeUniform(eddl.Conv(layer, 256, [3, 3], [1, 1], "same", False)),
        True)), [2, 2])

    layer = eddl.Reshape(layer, [-1])
    layer = eddl.Activation(eddl.BatchNormalization(
        eddl.Dense(layer, 128), True
    ), "relu")
    out = eddl.Softmax(eddl.BatchNormalization(
        eddl.Dense(layer, num_classes), True
    ))
    net = eddl.Model([in_], [out])

    eddl.build(
        net,
        eddl.adam(0.001),
        ["softmax_cross_entropy"],
        ["categorical_accuracy"],
        eddl.CS_GPU(mem=args.mem) if args.gpu else eddl.CS_CPU(mem=args.mem)
    )
    eddl.summary(net)
    eddl.plot(net, "model.pdf")

    x_train = Tensor.load("cifar_trX.bin")
    y_train = Tensor.load("cifar_trY.bin")
    x_train.div_(255.0)

    x_test = Tensor.load("cifar_tsX.bin")
    y_test = Tensor.load("cifar_tsY.bin")
    x_test.div_(255.0)

    if args.small:
        x_train = x_train.select([":5000"])
        y_train = y_train.select([":5000"])
        x_test = x_test.select([":1000"])
        y_test = y_test.select([":1000"])

    for i in range(args.epochs):
        eddl.fit(net, [x_train], [y_train], args.batch_size, 1)
        eddl.evaluate(net, [x_test], [y_test], bs=args.batch_size)
    eddl.setlr(net, [0.0001])
    for i in range(args.epochs):
        eddl.fit(net, [x_train], [y_train], args.batch_size, 1)
        eddl.evaluate(net, [x_test], [y_test], bs=args.batch_size)

    print("All done")
예제 #12
0
def SegNetBN(x, num_classes):
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 64, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 64, [3, 3], [1, 1], "same")))
    x = eddl.MaxPool(x, [2, 2], [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 128, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 128, [3, 3], [1, 1], "same")))
    x = eddl.MaxPool(x, [2, 2], [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 256, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 256, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 256, [3, 3], [1, 1], "same")))
    x = eddl.MaxPool(x, [2, 2], [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same")))
    x = eddl.MaxPool(x, [2, 2], [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same")))
    x = eddl.MaxPool(x, [2, 2], [2, 2])

    x = eddl.UpSampling(x, [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same")))
    x = eddl.UpSampling(x, [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 256, [3, 3], [1, 1], "same")))
    x = eddl.UpSampling(x, [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 256, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 256, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 128, [3, 3], [1, 1], "same")))
    x = eddl.UpSampling(x, [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 128, [3, 3], [1, 1], "same")))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 64, [3, 3], [1, 1], "same")))
    x = eddl.UpSampling(x, [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 64, [3, 3], [1, 1], "same")))
    x = eddl.Conv(x, num_classes, [3, 3], [1, 1], "same")

    return x
예제 #13
0
    return l0


eddl.download_cifar10()
gpu = int(sys.argv[2]) == 1 if len(sys.argv) > 2 else True

epochs = 10 if gpu else 1
batch_size = 50
num_classes = 10

bn = int(sys.argv[1]) == 1

inp = eddl.Input([3, 32, 32])
l = inp
l = eddl.GlorotUniform(eddl.Conv(l, 64, [7, 7], [2, 2], "same", False))
l = eddl.MaxPool(l, [2, 2], [2, 2], "valid")
l = resnet_block(l, 64, bn, 2, False)
l = resnet_block(l, 128, bn, 2, True)
l = resnet_block(l, 256, bn, 2, True)
l = resnet_block(l, 512, bn, 2, True)
l = eddl.GlobalAveragePool(l)
l = eddl.Flatten(l)

out = eddl.Softmax(eddl.GlorotUniform(eddl.Dense(l, num_classes)))

net = eddl.Model([inp], [out])
eddl.plot(net, "model.pdf")

eddl.build(net, eddl.adam(0.0001), ["soft_cross_entropy"],
           ["categorical_accuracy"],
           eddl.CS_GPU() if gpu else eddl.CS_CPU())