optimizer=opt,
                  metrics=['accuracy'])
# 否则从磁盘中加载checkpoints模型
else:
    print("[INFO] loading {}...".format(args['model']))
    model = load_model(args['model'])
    # 更新学习率
    print("[INFO] old learning rate: {}".format(K.get_value(
        model.optimizer.lr)))
    K.set_value(model.optimizer.lr, 1e-5)
    print("[INFO] new learning rate: {}".format(K.get_value(
        model.optimizer.lr)))
# 回调函数列表
callbacks = [
    # checkpoint
    EPO.EpochCheckpoint(args['checkpoints'],
                        every=5,
                        startAt=args['start_epoch']),
    # 监控训练过程
    TM.TrainingMonitor("output/resnet56_cifar10.png",
                       jsonPath="output/resnet56_cifar10.json",
                       startAt=args['start_epoch'])
]
# 训练网络
print("[INFO] training network.....")
model.fit_generator(aug.flow(trainX, trainY, batch_size=128),
                    validation_data=(testX, testY),
                    steps_per_epoch=len(trainX) // 128,
                    epochs=10,
                    callbacks=callbacks,
                    verbose=1)
Example #2
0
        opt = SGD(lr=experiment_learning_rate,momentum=0.9)



    model.compile(loss='categorical_crossentropy', optimizer=opt, metrics=['accuracy'])
else:
    print("[INFO] loading {}...".format(args["model"]))
    model = load_model(args["model"])
    # update the learning rate
    print("[INFO] old learning rate: {}".format(K.get_value(model.optimizer.lr)))
    K.set_value(model.optimizer.lr, experiment_learning_rate)
    print("[INFO] new learning rate: {}".format(K.get_value(model.optimizer.lr)))

# construct the set of callbacks
callbacks = [
    ECP.EpochCheckpoint(args["checkpoints"], every=5, startAt=args["start_epoch"]),
    TM.TrainingMonitor(config.FIG_PATH, jsonPath=config.JSON_PATH,startAt=args["start_epoch"])]

# train the network
model.fit_generator(
    trainGen.generator(),
    steps_per_epoch=trainGen.numImages // 64,
    validation_data=valGen.generator(),
    validation_steps=valGen.numImages // 64,
    epochs=experiment_epoch,
    max_queue_size=64 * 2,
    callbacks=callbacks, 
    verbose=1)

# close the databases
trainGen.close()