Esempio n. 1
0
def main(args):
    print(args)
    parser = argparse.ArgumentParser(description='train')
    parser.add_argument('-p', '--parallel', action='store_true')
    parser.add_argument('-m', '--mnist', action='store_true')
    parser.add_argument('--L1', type=float)
    parser.add_argument('--L2', type=float)
    parser.add_argument('-e', '--early_stopping', action='store_true')
    parser.add_argument('-d', '--dropout', action='store_true')
    parser.add_argument('-j', '--jobid')
    parser.add_argument('-s', '--small', action='store_true')
    parser.add_argument('-u', '--update', choices=["rmsprop"])
    parser.add_argument('-f', '--finish', type=int)
    parser.add_argument('-t', '--duration', type=int)
    parser.add_argument('-a', '--augmentation', action='store_true')
    parser.add_argument('--port', default= 5557, type=int)
    args = parser.parse_args(args)

    image_size = (128,128)

    if args.mnist:
        train, test = get_mnist()
        net = net_mnist()
    else:
        net = net_dvc(image_size)
        if args.parallel:
            sources = ('image_features','targets')
            train = ServerDataStream(sources, True, port=args.port)
            valid = ServerDataStream(sources, True, port=args.port+1)
            test = ServerDataStream(sources, True, port=args.port+2)
        else:
            train, valid , test = get_dvc(image_size, shortcut = args.small, augmentation = args.augmentation)

    train_net(net, train, test, **vars(args))
Esempio n. 2
0
def main(args):
    print(args)
    parser = argparse.ArgumentParser(description='train')
    parser.add_argument('-p', '--parallel', action='store_true')
    parser.add_argument('-m', '--mnist', action='store_true')
    parser.add_argument('--L1', type=float)
    parser.add_argument('--L2', type=float)
    parser.add_argument('-e', '--early_stopping', action='store_true')
    parser.add_argument('-d', '--dropout', action='store_true')
    parser.add_argument('-j', '--jobid')
    parser.add_argument('-s', '--small', action='store_true')
    parser.add_argument('-u', '--update', choices=["rmsprop"])
    parser.add_argument('-f', '--finish', type=int)
    parser.add_argument('-t', '--duration', type=int)
    parser.add_argument('-a', '--augmentation', action='store_true')
    parser.add_argument('--port', default=5557, type=int)
    args = parser.parse_args(args)

    image_size = (128, 128)

    if args.mnist:
        train, test = get_mnist()
        net = net_mnist()
    else:
        net = net_dvc(image_size)
        if args.parallel:
            sources = ('image_features', 'targets')
            train = ServerDataStream(sources, True, port=args.port)
            valid = ServerDataStream(sources, True, port=args.port + 1)
            test = ServerDataStream(sources, True, port=args.port + 2)
        else:
            train, valid, test = get_dvc(image_size,
                                         shortcut=args.small,
                                         augmentation=args.augmentation)

    train_net(net, train, test, **vars(args))
Esempio n. 3
0
def main(argv):
    name = argv[1]
    files = map(lambda p: join(folder, p), listdir(folder))

    file = next(filter(lambda n: name in n, files))
    print(file)

    p = load_parameter_values(file)

    net = net_dvc((128,128))

    x = tensor.tensor4('image_features')
    y_hat = net.apply(x)

    g = Model(y_hat)

    for k,v in p.items():
        p[k] = v.astype('float32')

    g.set_parameter_values(p)

    a,t,v = get_dvc((128,128),trainning=False, shortcut=False)
    run = function([x], y_hat)

    def run_test(data):
        res = []
        for i in  data.get_epoch_iterator():
            res.extend(run(i[0]))
        return res

    def max_index(l):
        if l[0] > l[1]:
            return 0
        else:
            return 1

    def write_kaggle(f, l):
        f.write("id,label\n")
        for i,e in enumerate(l,start=1):
            f.write(str(i)+","+str(e)+"\n")

    def kaggle(file, data):
        write_kaggle(file,map(max_index, run_test(data)))

    def accuracy(data):
        res = []
        true = []
        for i in data.get_epoch_iterator():
            res.extend(run(i[0]))
            true.extend(i[1])
        res = map(max_index, res)

        total = 0
        equal = 0
        for r,t in zip(res,true):
            total += 1
            equal += 1 if r == t else 0

        return equal/total

    print("Training accuracy: ", accuracy(a))
    print("Test accuracy: ", accuracy(v))
    kaggle_file = join(result_folder, name+".kaggle")
    print(kaggle_file)
    with open(kaggle_file,'w') as f:
            kaggle(f, t)
Esempio n. 4
0
def main(argv):
    name = argv[1]
    files = map(lambda p: join(folder, p), listdir(folder))

    file = next(filter(lambda n: name in n, files))
    print(file)

    p = load_parameter_values(file)

    net = net_dvc((128, 128))

    x = tensor.tensor4('image_features')
    y_hat = net.apply(x)

    g = Model(y_hat)

    for k, v in p.items():
        p[k] = v.astype('float32')

    g.set_parameter_values(p)

    a, t, v = get_dvc((128, 128), trainning=False, shortcut=False)
    run = function([x], y_hat)

    def run_test(data):
        res = []
        for i in data.get_epoch_iterator():
            res.extend(run(i[0]))
        return res

    def max_index(l):
        if l[0] > l[1]:
            return 0
        else:
            return 1

    def write_kaggle(f, l):
        f.write("id,label\n")
        for i, e in enumerate(l, start=1):
            f.write(str(i) + "," + str(e) + "\n")

    def kaggle(file, data):
        write_kaggle(file, map(max_index, run_test(data)))

    def accuracy(data):
        res = []
        true = []
        for i in data.get_epoch_iterator():
            res.extend(run(i[0]))
            true.extend(i[1])
        res = map(max_index, res)

        total = 0
        equal = 0
        for r, t in zip(res, true):
            total += 1
            equal += 1 if r == t else 0

        return equal / total

    print("Training accuracy: ", accuracy(a))
    print("Test accuracy: ", accuracy(v))
    kaggle_file = join(result_folder, name + ".kaggle")
    print(kaggle_file)
    with open(kaggle_file, 'w') as f:
        kaggle(f, t)
Esempio n. 5
0
def tuple_parse(string):
    try:
        x, y = map(int, string.split(','))
        return x, y
    except:
        raise argparse.ArgumentTypeError("Need a width and height")


def start_server(i, stream):
    port = 5557 + i
    print("starting server ", port)
    fuel_start_server(stream, port)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description='Open a datastream for the cat and dog dataset')
    parser.add_argument('--image_size',
                        type=tuple_parse,
                        help='(width, height) for the resize')
    parser.add_argument('--batch_size',
                        type=int,
                        help='Set the number of exemple per batch')

    args = vars(parser.parse_args())
    args = {k: v for k, v in args.items() if v is not None}

    streams = get_dvc(**args)
    for t in enumerate(streams):
        Thread(target=start_server, args=t).start()
Esempio n. 6
0
from datastream import get_dvc
import argparse
from threading import Thread
from fuel.server import start_server as fuel_start_server

def tuple_parse(string):
    try:
        x, y = map(int, string.split(','))
        return x, y
    except:
        raise argparse.ArgumentTypeError("Need a width and height")

def start_server(i,stream):
    port = 5557 + i
    print("starting server " , port)
    fuel_start_server(stream, port)


if __name__=="__main__":
    parser = argparse.ArgumentParser(description='Open a datastream for the cat and dog dataset')
    parser.add_argument('--image_size', type=tuple_parse, help='(width, height) for the resize')
    parser.add_argument('--batch_size', type=int, help='Set the number of exemple per batch')

    args = vars(parser.parse_args())
    args= {k:v for k,v in args.items() if v is not None}

    streams = get_dvc(**args)
    for t in enumerate(streams):
        Thread(target=start_server, args = t).start()