Ejemplo n.º 1
0
    logging.basicConfig(level=logging.DEBUG)

    if IS_TRAINING:
        logger.info("Preprocess...")
        preprocessor = ImagePreprocessor(preprocessor_config)
        logger.info("Making dataset...")
        data_loader_config = ImageSetDataLoaderConfig(
            image_dict=preprocessor.get_image_dict(),
            image_shape=INPUT_SHAPE_REVERSE,
            shuffle_buffer_size=100000,
            batch_size=100
        )
        data_loader = ImageSetDataLoader(data_loader_config)

        model = CNNModel(model_config)
        trainer = UniversalTrainer(model.get_model(), data_loader.get_dataset(), trainer_config)

        logger.info("Training...")
        trainer.train()
        trainer.save("log/test.h5")
    else:
        model = CNNModel(model_config)
        trainer = UniversalTrainer(model.get_model(), None, trainer_config)
        trainer.load("log/test.h5")

        valid_image_list = os.listdir(VALIDATION_IMAGE_ROOT)
        logger.debug("Validation image list: %s", valid_image_list)

        for image_file_name in valid_image_list:
            image_file = os.path.join(VALIDATION_IMAGE_ROOT, image_file_name)
            image = cv2.imread(image_file, flags=cv2.IMREAD_COLOR)
Ejemplo n.º 2
0
            image_shape=INPUT_SHAPE_REVERSE,
            shuffle_buffer_size=100000,
            batch_size=100)
        data_loader_province_config = ImageSetDataLoaderConfig(
            image_dict=preprocessor_province.get_image_dict(),
            image_shape=INPUT_SHAPE_REVERSE,
            shuffle_buffer_size=100000,
            batch_size=100)

        data_loader_char = ImageSetDataLoader(data_loader_char_config)
        data_loader_province = ImageSetDataLoader(data_loader_province_config)

        model_char = CNNModel(model_char_config)
        model_province = CNNModel(model_province_config)

        trainer_char = UniversalTrainer(model_char.get_model(),
                                        data_loader_char.get_dataset(),
                                        trainer_config)
        trainer_province = UniversalTrainer(model_province.get_model(),
                                            data_loader_province.get_dataset(),
                                            trainer_config)

        logger.info("Training...")
        trainer_char.train()
        trainer_province.train()
        trainer_char.save("log/test_split_char.h5")
        trainer_province.save("log/test_split_province.h5")
    else:
        model_char = CNNModel(model_char_config)
        trainer_char = UniversalTrainer(model_char.get_model(), None,
                                        trainer_config)