Load Flickr25K dataset. Returns a list of images by a given tag from Flick25k dataset, it will download Flickr25k from `the official website `__ at the first time you use it. Parameters ------------ tag : str or None
(tag='sky', path="data", n_threads=50, printable=False)
| 1045 | |
| 1046 | |
| 1047 | def load_flickr25k_dataset(tag='sky', path="data", n_threads=50, printable=False): |
| 1048 | """Load Flickr25K dataset. |
| 1049 | |
| 1050 | Returns a list of images by a given tag from Flick25k dataset, |
| 1051 | it will download Flickr25k from `the official website <http://press.liacs.nl/mirflickr/mirdownload.html>`__ |
| 1052 | at the first time you use it. |
| 1053 | |
| 1054 | Parameters |
| 1055 | ------------ |
| 1056 | tag : str or None |
| 1057 | What images to return. |
| 1058 | - If you want to get images with tag, use string like 'dog', 'red', see `Flickr Search <https://www.flickr.com/search/>`__. |
| 1059 | - If you want to get all images, set to ``None``. |
| 1060 | |
| 1061 | path : str |
| 1062 | The path that the data is downloaded to, defaults is ``data/flickr25k/``. |
| 1063 | n_threads : int |
| 1064 | The number of thread to read image. |
| 1065 | printable : boolean |
| 1066 | Whether to print infomation when reading images, default is ``False``. |
| 1067 | |
| 1068 | Examples |
| 1069 | ----------- |
| 1070 | Get images with tag of sky |
| 1071 | |
| 1072 | >>> images = tl.files.load_flickr25k_dataset(tag='sky') |
| 1073 | |
| 1074 | Get all images |
| 1075 | |
| 1076 | >>> images = tl.files.load_flickr25k_dataset(tag=None, n_threads=100, printable=True) |
| 1077 | |
| 1078 | """ |
| 1079 | path = os.path.join(path, 'flickr25k') |
| 1080 | |
| 1081 | filename = 'mirflickr25k.zip' |
| 1082 | url = 'http://press.liacs.nl/mirflickr/mirflickr25k/' |
| 1083 | |
| 1084 | # download dataset |
| 1085 | if folder_exists(os.path.join(path, "mirflickr")) is False: |
| 1086 | logging.info("[*] Flickr25k is nonexistent in {}".format(path)) |
| 1087 | maybe_download_and_extract(filename, path, url, extract=True) |
| 1088 | del_file(os.path.join(path, filename)) |
| 1089 | |
| 1090 | # return images by the given tag. |
| 1091 | # 1. image path list |
| 1092 | folder_imgs = os.path.join(path, "mirflickr") |
| 1093 | path_imgs = load_file_list(path=folder_imgs, regx='\\.jpg', printable=False) |
| 1094 | path_imgs.sort(key=natural_keys) |
| 1095 | |
| 1096 | # 2. tag path list |
| 1097 | folder_tags = os.path.join(path, "mirflickr", "meta", "tags") |
| 1098 | path_tags = load_file_list(path=folder_tags, regx='\\.txt', printable=False) |
| 1099 | path_tags.sort(key=natural_keys) |
| 1100 | |
| 1101 | # 3. select images |
| 1102 | if tag is None: |
| 1103 | logging.info("[Flickr25k] reading all images") |
| 1104 | else: |
nothing calls this directly
no test coverage detected
searching dependent graphs…