Пример #1
0
def resnet_block(l0, nf, bn, reps, downsample):
    for i in range(reps):
        stri = 2 if (downsample and i == 0) else 1

        l1 = eddl.GlorotUniform(
            eddl.Conv(l0, nf, [1, 1], [stri, stri], "same", False))
        if (bn):
            l1 = eddl.BatchNormalization(l1, 0.99, 0.001, True, "")
        l1 = eddl.ReLu(l1)

        l1 = eddl.GlorotUniform(
            eddl.Conv(l1, nf, [3, 3], [1, 1], "same", False))
        if (bn):
            l1 = eddl.BatchNormalization(l1, 0.99, 0.001, True, "")
        l1 = eddl.ReLu(l1)

        l1 = eddl.GlorotUniform(
            eddl.Conv(l1, nf * 4, [1, 1], [1, 1], "same", False))
        if (bn):
            l1 = eddl.BatchNormalization(l1, 0.99, 0.001, True, "")

        if (i == 0):
            l0 = eddl.GlorotUniform(
                eddl.Conv(l0, nf * 4, [1, 1], [stri, stri], "same", False))

        l0 = eddl.Add([l0, l1])
        l0 = eddl.ReLu(l0)

    return l0
Пример #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 Block3_2(layer, filters):
    layer = eddl.ReLu(Normalization(eddl.Conv(
        layer, filters, [3, 3], [1, 1], "same", False
    )))
    layer = eddl.ReLu(Normalization(eddl.Conv(
        layer, filters, [3, 3], [1, 1], "same", False
    )))
    return layer
Пример #4
0
def Block3_2(layer, filters):
    layer = eddl.ReLu(eddl.BatchNormalization(
        eddl.Conv(layer, filters, [3, 3], [1, 1]), True
    ))
    layer = eddl.ReLu(eddl.BatchNormalization(
        eddl.Conv(layer, filters, [3, 3], [1, 1]), True
    ))
    return layer
Пример #5
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")
Пример #6
0
def ResBlock(layer, filters, nconv, half):
    in_ = layer
    strides = [2, 2] if half else [1, 1]
    layer = eddl.ReLu(BG(eddl.Conv(layer, filters, [3, 3], strides)))
    for i in range(nconv - 1):
        layer = eddl.ReLu(BG(eddl.Conv(layer, filters, [3, 3], [1, 1])))
    if (half):
        return eddl.Add(BG(eddl.Conv(in_, filters, [1, 1], [2, 2])), layer)
    else:
        return eddl.Add(layer, in_)
Пример #7
0
def main(args):
    eddl.download_mnist()

    in_ = eddl.Input([784])
    target = eddl.Reshape(in_, [1, 28, 28])
    layer = in_
    layer = eddl.Reshape(layer, [1, 28, 28])
    layer = eddl.ReLu(eddl.Conv(layer, 8, [3, 3]))
    layer = eddl.ReLu(eddl.Conv(layer, 16, [3, 3]))
    layer = eddl.ReLu(eddl.Conv(layer, 8, [3, 3]))
    out = eddl.Sigmoid(eddl.Conv(layer, 1, [3, 3]))
    net = eddl.Model([in_], [])

    eddl.build(
        net,
        eddl.adam(0.001),
        [],
        [],
        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")
    if args.small:
        x_train = x_train.select([":6000"])
    x_train.div_(255.0)

    mse = eddl.newloss(mse_loss, [out, target], "mse_loss")
    dicei = eddl.newloss(dice_loss_img, [out, target], "dice_loss_img")
    dicep = eddl.newloss(dice_loss_pixel, [out, target], "dice_loss_pixel")

    batch = Tensor([args.batch_size, 784])
    num_batches = x_train.shape[0] // args.batch_size
    for i in range(args.epochs):
        print("Epoch %d/%d (%d batches)" % (i + 1, args.epochs, num_batches))
        diceploss = 0.0
        diceiloss = 0.0
        mseloss = 0
        for j in range(num_batches):
            print("Batch %d " % j, end="", flush=True)
            eddl.next_batch([x_train], [batch])
            eddl.zeroGrads(net)
            eddl.forward(net, [batch])
            diceploss += eddl.compute_loss(dicep) / args.batch_size
            print("diceploss = %.6f " % (diceploss / (j + 1)), end="")
            diceiloss += eddl.compute_loss(dicei) / args.batch_size
            print("diceiloss = %.6f " % (diceiloss / (j + 1)), end="")
            mseloss += eddl.compute_loss(mse) / args.batch_size
            print("mseloss = %.6f\r" % (mseloss / (j + 1)), end="")
            eddl.optimize(dicep)
            eddl.update(net)
        print()
    print("All done")
Пример #8
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
Пример #10
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")
Пример #11
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.ReLu(BG(eddl.Conv(layer, 64, [3, 3], [1, 1])))
    layer = eddl.Pad(layer, [0, 1, 1, 0])
    layer = ResBlock(layer, 64, 2, True)
    layer = ResBlock(layer, 64, 2, False)
    layer = ResBlock(layer, 128, 2, True)
    layer = ResBlock(layer, 128, 2, False)
    layer = ResBlock(layer, 256, 2, True)
    layer = ResBlock(layer, 256, 2, False)
    layer = ResBlock(layer, 256, 2, True)
    layer = ResBlock(layer, 256, 2, False)
    layer = eddl.Reshape(layer, [-1])
    layer = eddl.ReLu(BG(eddl.Dense(layer, 512)))

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

    eddl.build(
        net,
        eddl.sgd(0.01, 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:
        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")
Пример #12
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")
Пример #13
0
def ResBlock(layer, filters, half, expand=0):
    in_ = layer
    layer = eddl.ReLu(
        BG(eddl.Conv(layer, filters, [1, 1], [1, 1], "same", False)))
    strides = [2, 2] if half else [1, 1]
    layer = eddl.ReLu(
        BG(eddl.Conv(layer, filters, [3, 3], strides, "same", False)))
    layer = eddl.ReLu(
        BG(eddl.Conv(layer, 4 * filters, [1, 1], [1, 1], "same", False)))
    if (half):
        return eddl.ReLu(
            eddl.Add(
                BG(eddl.Conv(in_, 4 * filters, [1, 1], [2, 2], "same", False)),
                layer))
    else:
        if expand:
            return eddl.ReLu(
                eddl.Add(
                    BG(
                        eddl.Conv(in_, 4 * filters, [1, 1], [1, 1], "same",
                                  False)), layer))
        else:
            return eddl.ReLu(eddl.Add(in_, layer))
Пример #14
0
def SegNet(x, num_classes):
    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
Пример #15
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")
Пример #16
0
def LBC(layer, *args, **kwargs):
    return eddl.LeakyReLu(eddl.BatchNormalization(eddl.Conv(
        layer, *args, **kwargs
    ), True))
Пример #17
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
Пример #18
0
def Block1(layer, filters):
    return eddl.ReLu(
        eddl.GroupNormalization(eddl.Conv(layer, filters, [1, 1], [1, 1]), 4))
Пример #19
0
def Block3_2(layer, filters):
    layer = eddl.ReLu(
        eddl.GroupNormalization(eddl.Conv(layer, filters, [3, 3], [1, 1]), 4))
    layer = eddl.ReLu(
        eddl.GroupNormalization(eddl.Conv(layer, filters, [3, 3], [1, 1]), 4))
    return layer
Пример #20
0
def Block1(layer, filters):
    return eddl.ReLu(eddl.BatchNormalization(
        eddl.Conv(layer, filters, [1, 1], [1, 1]), True
    ))
Пример #21
0
def Block1(layer, filters):
    return eddl.ReLu(Normalization(eddl.Conv(
        layer, filters, [1, 1], [1, 1], "same", False
    )))
Пример #22
0
def SegNetBN(x, num_classes):
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 64, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 64, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.MaxPool(x, [2, 2], [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 128, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 128, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.MaxPool(x, [2, 2], [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 256, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 256, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 256, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.MaxPool(x, [2, 2], [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.MaxPool(x, [2, 2], [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same"),
                                True))
    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"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.UpSampling(x, [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 512, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 256, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.UpSampling(x, [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 256, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 256, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 128, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.UpSampling(x, [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 128, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 64, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.UpSampling(x, [2, 2])
    x = eddl.ReLu(
        eddl.BatchNormalization(eddl.Conv(x, 64, [3, 3], [1, 1], "same"),
                                True))
    x = eddl.Conv(x, num_classes, [3, 3], [1, 1], "same")

    return x
Пример #23
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, 4096))
    x = eddl.ReLu(eddl.Dense(x, 4096))
    x = eddl.Softmax(eddl.Dense(x, num_classes))
    return x
Пример #24
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"],