예제 #1
0
def train(opts):
    opts.cfg['pretrained'] = root + opts.cfg['pretrained']

    now = datetime.datetime.now().strftime('%Y_%m_%d-%H_%M_%S')
    opts.cfg['utc_time'] = now

    opts.out = get_log_dir(opts.cfg['output_dir'], 1, opts.cfg, root)

    #print(opts.cfg)

    kwargs = {'num_workers': opts.cfg['n_workers']} if cuda else {}
    train_loader = torch.utils.data.DataLoader(
        Cloud_Data(class_names,
                   root,
                   args.image_type,
                   image_set='train',
                   backbone=opts.cfg['backbone'],
                   transform=True),
        batch_size=opts.cfg['batch_size'],
        shuffle=True,
        **kwargs)

    val_loader = torch.utils.data.DataLoader(Cloud_Data(
        class_names,
        root,
        args.image_type,
        image_set='val',
        backbone=opts.cfg['backbone'],
        transform=True),
                                             batch_size=opts.cfg['batch_size'],
                                             shuffle=False,
                                             **kwargs)
    data_loader = [train_loader, val_loader]

    trainer = Trainer(data_loader, opts)

    start_epoch = 0
    start_iteration = 0
    '''
    if opts.cfg['pretrained']:
        checkpoint = torch.load(opts.cfg['pretrained'])
        start_epoch = checkpoint['epoch']
        start_iteration = checkpoint['iteration']
    '''

    trainer.epoch = start_epoch
    trainer.iteration = start_iteration
    trainer.Train()
예제 #2
0
    val_loader = torch.utils.data.DataLoader(
        Cloud_Data(
            class_names,
            root,
            args.image_type,
            image_set='val',
            backbone=opts.cfg['backbone'],
            transform=True),
        batch_size=opts.cfg['batch_size'],
        shuffle=False,
        **kwargs
    )
    data_loader=[train_loader,val_loader]

    trainer = Trainer(data_loader, opts)

    start_epoch = 0
    start_iteration = 0

    '''
    if opts.cfg['pretrained']:
        checkpoint = torch.load(opts.cfg['pretrained'])
        start_epoch = checkpoint['epoch']
        start_iteration = checkpoint['iteration']
    '''

    trainer.epoch = start_epoch
    trainer.iteration = start_iteration
    trainer.Train()
예제 #3
0
from neuralnetwork import NeuralNetwork
from trainer import Trainer
import matplotlib.pyplot as plt
import pickle

network = pickle.load(open("test.boi", "rb"))
ashketchum = Trainer(4, "adadelta", learningRate=0.05, delta=0.9)

ashketchum.addData(np.matrix([[0], [0]]), np.matrix([[0]]))
ashketchum.addData(np.matrix([[0], [1]]), np.matrix([[0]]))
ashketchum.addData(np.matrix([[1], [0]]), np.matrix([[0]]))
ashketchum.addData(np.matrix([[1], [1]]), np.matrix([[1]]))

errors = []

ashketchum.Train(network)
errors.append(ashketchum.error)

plt.show()
axes = plt.gca()
axes.set_xlim(0, len(errors))
axes.set_ylim(0, errors[0])
line, = axes.plot(range(len(errors)), errors)

while ashketchum.error > 0.025:
    ashketchum.Train(network)
    errors.append(ashketchum.error)
    #print ashketchum.error
    axes.set_xlim(0, len(errors))
    axes.set_ylim(0, max(errors))
    line.set_xdata(range(len(errors)))