예제 #1
0
def get_preprocessing_tfrecord_file(target_directory_path_or_file,
                                    split_name=None):
    try:
        return determine_file_path(target_directory_path_or_file,
                                   get_tfrecord_filename(split_name),
                                   to_read=True)
    except Exception:
        return None
예제 #2
0
def store_numpy_to(data, target_directory_path_or_file, lookup_file_name=None):
    """
        @param directory_or_file: to look for the source file
        @param lookup_filename: the filename to look for when a directory is given
    """
    file_path = determine_file_path(target_directory_path_or_file, lookup_file_name, to_read=False)    
    
    with open(file_path, "wb") as f:
        np.save(f, data)
    return file_path
예제 #3
0
def load_numpy_from(directory_or_file, lookup_filename=None):
    """
        @param directory_or_file: to look for the source file
        @param lookup_filename: the filename to look for when a directory is given
    """
    file_path = determine_file_path(directory_or_file, lookup_filename)
    
    with open(file_path, "rb") as f:
        data = np.load(f)
    return data
예제 #4
0
def get_prepared_captions_file_path(config, split_name=None, flat=True):
    lookup_filename = DEFAULT_PREPARED_CAPTIONS_FILE_NAME
    if split_name and not flat:
        raise Exception("Only flat vocabulary path supported for now")
    if split_name and flat:
        lookup_filename = DEFAULT_PREPARED_CAPTIONS_SPLIT_FILE_NAME_PATTERN.format(split_name)
        # print("No support for split specific vocabulary loading. Please just name the file to use to " + lookup_filename)
    try:
        return determine_file_path(config.getDatasetTextDirectoryPath(), lookup_filename, to_read=True)
    except Exception:
        print("No vocabulary file found with name " + lookup_filename)
        return None
예제 #5
0
def get_vocabulary_file_path(config, split_name=None, flat=True):
    lookup_filename = DEFAULT_VOCABULARY_FILE_NAME
    if split_name and not flat:
        raise Exception("Only flat vocabulary path supported for now")
    if split_name and flat:
        lookup_filename = "mscoco_vocabulary_{}.json".format(split_name)
        # print("No support for split specific vocabulary loading. Please just name the file to use to " + lookup_filename)
    try:
        return determine_file_path(config.getDatasetTextDirectoryPath(), lookup_filename, to_read=True)
    except Exception:
        print("No vocabulary file found with name " + lookup_filename)
        return None