Ejemplo n.º 1
0
    with open(os.path.join(args.output, 'model.json'), 'w') as f:
        f.write(model.to_json())

    try:
        if args.weights:
            print('Loading weights from file ...')
            model.load_weights(args.weights)
    except IOError:
        print("No model found")
    checkpointer = ModelCheckpoint(os.path.join(args.output, 'weights.{epoch:02d}-{val_loss:.3f}.hdf5'))
    early_stop = EarlyStopping(monitor='val_loss', patience=100, verbose=0, mode='auto')
    logger = CSVLogger(filename=os.path.join(args.output, 'history.csv'))
    board = TensorBoard(log_dir=args.output, histogram_freq=0, write_graph=True, write_images=True)

    history = model.fit_generator(
        generate_thunderhill_batches(df_train, args),
        nb_epoch=args.epoch,
        samples_per_epoch=args.batch*50,
        validation_data=generate_thunderhill_batches(df_val, args),
        nb_val_samples=args.batch*10,
        callbacks=[
            checkpointer,
            ModelCheckpoint(os.path.join(args.output, 'model.h5'), monitor='val_loss', save_best_only=True),
            early_stop,
            logger,
            board
        ]
    )

    # for X, y in generate_thunderhill_batches(df_train, args):
    #     print(X.shape, y.shape)
Ejemplo n.º 2
0
            print('Loading weights from file ...')
            model.load_weights(args.weights)
    except IOError:
        print("No model found")

    checkpointer = ModelCheckpoint(os.path.join(
        args.output, 'weights.{epoch:04d}-{val_loss:.3f}.hdf5'),
                                   monitor='val_loss',
                                   verbose=0,
                                   save_best_only=True,
                                   save_weights_only=False,
                                   mode='auto',
                                   period=1)
    # early_stop = EarlyStopping(monitor='val_loss', patience=50, verbose=0, mode='auto')
    logger = CSVLogger(filename=os.path.join(args.output, 'history.csv'))

    board = TensorBoard(log_dir=args.output,
                        histogram_freq=0,
                        write_graph=True,
                        write_images=True)

    history = model.fit_generator(
        generate_thunderhill_batches(genAll(args.dataset), args.batch),
        nb_epoch=args.epoch,
        samples_per_epoch=50 * args.batch,
        validation_data=generate_thunderhill_batches(genSim001(args.dataset),
                                                     args.batch),
        nb_val_samples=5 * args.batch,
        callbacks=[checkpointer, logger, board]  #, early_stop]
    )