def create_many_feature_map_files_from_config(config, split_name): """ Reads the image files from the sub-directories given as split names. Creates the according feature map files in the top directory. """ run_opts = config.run_opts print("Run opts: " + str(run_opts)) batch_size = __get_batch_size(config, run_opts) expected_num_images = __get_expected_num_images(config, run_opts, split_name) is_dryrun = __is_dryrun(run_opts) images_top_directory = config.getDatasetImagesDirectoryPath() target_shape = config.getImageInputShape() image_features_size = config.getImageFeaturesSize() image_infix = get_infix_from_config(config, split_name) image_prefix = "COCO_" + image_infix output_layer = config.getImageOutputLayer() return create_many_feature_map_files(images_top_directory, output_layer, image_prefix, image_features_size, target_shape, batch_size, split_name, expected_num_images, is_dryrun)
def visualize_images_with_caption_by_image_ids(config, sample_image_ids, sample_results, image_rows, image_cols, split_name): directory_path = "/".join([config.getDatasetImagesDirectoryPath(), split_name]) image_infix = get_infix_from_config(config, split_name) captions = to_caption_listing_by_image_id(load_prepared_captions_json_from_config(config, split_name)) provider = MscocoFileSystemImageProvider(directory_path, prefix="COCO_" + image_infix, vgg_like=False, target_size=(448, 448)) sample_images = provider.get_images_for_image_ids(sample_image_ids) sample_images = sample_images.astype('uint8') titles = ["{:d}: {}".format(image_id, captions[image_id][0]) for image_id in sample_image_ids] titles = ["\n".join([titles[idx], r]) for idx, r in enumerate(sample_results)] show_many(sample_images, image_rows, image_cols, figsize=(4, 3), titles=titles)
def create_single_split_provider_from_config(config, split_name): directory_path = "/".join( [config.getDatasetImagesDirectoryPath(), split_name]) image_infix = get_infix_from_config(config, split_name) if config.getByPassImageFeaturesComputation(): return MscocoFileSystemFeatureMapProvider(directory_path, prefix="COCO_" + image_infix) else: return MscocoFileSystemImageProvider( directory_path, prefix="COCO_" + image_infix, vgg_like=True, target_size=config.getImageInputShape())
def create_from_config(config, split_name): directory_path = "/".join([config.getDatasetImagesDirectoryPath(), split_name]) image_prefix = "COCO_" + get_infix_from_config(config, split_name) print("Image prefix:", image_prefix) caption_max_length = config.getCaptionMaximalLength() print("Caption max length:", caption_max_length) by_pass = config.getByPassImageFeaturesComputation() print("Bypass image feature compuration:", by_pass) target_shape = config.getImageInputShape() print("Target image shape:", target_shape) feature_size = config.getImageFeaturesSize() print("Image feature size:", feature_size) return ExternAttentionExperimentSequence(directory_path, image_prefix, caption_max_length, by_pass, target_shape, feature_size)
def create_many_attention_map_files_from_config(config, split_name): """ Reads the image files from the sub-directories given as split names. Creates the according feature map files in the top directory. """ target_shape = config.getImageInputShape() image_feature_size = config.getImageFeaturesSize() image_infix = get_infix_from_config(config, split_name) image_prefix = "COCO_" + image_infix bounding_boxes = load_prepared_boxes_json_from_config(config, split_name) boxes = calculate_metrics(bounding_boxes) boxes_by_id = collections.defaultdict(list) [boxes_by_id[box["image_id"]].append(box) for box in boxes] images_top_directory = config.getDatasetImagesDirectoryPath() image_paths = get_image_paths(to_split_dir(images_top_directory, split_name)) processables = to_processables(image_paths, boxes_by_id, target_shape, image_prefix, image_feature_size) preprocess_bounding_boxes(processables)