def preprocessing_manager(cfg): if cfg["dataset"]["encoding"] == "inception": img_model = InceptionV3(weights='imagenet') dataset_preprocessor = PreProcessing(cfg, "inception", (299, 299)) dataset_preprocessor.run_one_time_encoding(img_model) # Load train, validation sets from the pre-processor return dataset_preprocessor.get_encoding_keras_generators("inception") elif cfg["dataset"]["encoding"] == "resnet50": img_model = ResNet50(weights='imagenet') dataset_preprocessor = PreProcessing(cfg, "resnet50", (224, 224)) dataset_preprocessor.run_one_time_encoding(img_model) # Load train, validation sets from the pre-processor return dataset_preprocessor.get_encoding_keras_generators("resnet50") elif cfg["dataset"]["encoding"] == "simple": dataset_preprocessor = PreProcessing(cfg, None, (299, 299)) return dataset_preprocessor.get_image_keras_generators() else: RuntimeError("Unsupported encoding type!")
args = parser.parse_args() with open(args.config) as fp: cfg = yaml.load(fp) dataset_cfg = get_dataset_metadata_cfg() model_workspace_dir = os.path.join(cfg["workspace"]["directory"], cfg["dataset"]["name"], cfg["model"]["arch"]) utils.make_directories(model_workspace_dir) img_model = ResNet50(weights='imagenet') dataset_preprocessor = PreProcessing(cfg, "resnet50", False, False) dataset_preprocessor.run_one_time_encoding(img_model) # Load train, validation sets from the pre-processor training_generator, validation_generator, test_generator = dataset_preprocessor.get_keras_generators( "resnet50") MAX_LEN = 40 EMBEDDING_DIM = 300 IMAGE_ENC_DIM = 300 vocab_size = get_line_count( os.path.join(cfg["workspace"]["directory"], cfg["dataset"]["name"], "word_dictionary.txt")) img_input = Input(shape=(2048, )) img_enc = Dense(300, activation="relu")(img_input) images = RepeatVector(MAX_LEN)(img_enc)