コード例 #1
0
from tensorflow import keras

logdir = "./folder" + datetime.now().strftime("%Y%m%d-%H%M%S")
tensorboard_callback = keras.callbacks.TensorBoard(log_dir=logdir)

from get_image_generator import train_generator, validation_generator, test_generator
from model import model

from meta_parameters import EPOCHS, STEPS_PER_EPOCH, VALIDATION_STEPS, BATCH_SIZE

model.fit_generator(
    train_generator,
    steps_per_epoch=STEPS_PER_EPOCH,
    epochs=EPOCHS,
    validation_data=validation_generator,
    validation_steps=VALIDATION_STEPS,
    use_multiprocessing=True,
    callbacks=[tensorboard_callback],
)

model.save_weights('my_model_weights.h5')
print("evaluate", model.metrics_names)
print(model.evaluate_generator(
    test_generator,
    use_multiprocessing=True,
))

model.count_params()
model.summary()
#TODO numbe of parameters
# https://stackoverflow.com/questions/35792278/how-to-find-number-of-parameters-of-a-keras-model
コード例 #2
0
from model import model, preprocess_input, smodel
from keras.optimizers import SGD
from keras.callbacks import ReduceLROnPlateau
from generator import Generator
import json

if __name__ == '__main__':
    model = smodel()
    opt = SGD(lr=0.01, momentum=0.9)
    model.compile(optimizer=opt,
                  loss='categorical_crossentropy',
                  metrics=['acc'])
    print(model.summary())
    model.load_weights('weights/classifier.h5')

    listsss = json.load(open('list_withbndbx.json', 'r'))
    train_gen = Generator(
        listsss[:7211],
        '/home/palm/PycharmProjects/DATA/Tanisorn/imgCarResize/',
        preprocess_function=preprocess_input)
    test_gen = Generator(
        listsss[7211:],
        '/home/palm/PycharmProjects/DATA/Tanisorn/imgCarResize/',
        preprocess_function=preprocess_input)
    reduce_lr_01 = ReduceLROnPlateau(monitor='val_1st_acc',
                                     factor=0.2,
                                     patience=5,
                                     min_lr=0,
                                     mode='max')
    reduce_lr_02 = ReduceLROnPlateau(monitor='val_2nd_acc',
                                     factor=0.2,