├── __init__.py ├── .gitignore ├── requirements.txt ├── README.md ├── download_single_item.py ├── download_archive.py └── LICENSE /__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Data/* 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests 2 | Pillow 3 | tqdm 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Note 2 | Kaggle now offers a [competition](https://www.kaggle.com/c/siim-isic-melanoma-classification) regarding the isic archive, and it appears to have a larger dataset than the one provided in the isic archive website. 3 | In addition the discussion threads hold useful information about the data itself (e.g about existing duplicate images). 4 | 5 | # ISIC Archive Downloader 6 | The ISIC Archive contains over 23k images of skin lesions, labeled as 'benign' or 'malignant'. 7 | The archive can be found here: 8 | https://www.isic-archive.com/#!/onlyHeaderTop/gallery 9 | 10 | The current ways to download the archive, provided by the ISIC foundation and which are known to me, are the following: 11 | 1. Download the entire archive via the direct download button on their website. 12 | 2. Download all the partitions of the archive, called 'datasets' one by one 13 | 3. Downloading the images one by one via the Grider API provided in the site 14 | 15 | The first option (which is the easiest and most comfortable way) doesn't always finish successfully for some reason. 16 | We suspect this is happening due to the large file size. 17 | 18 | The second option seems rather good if you plan to download the archive only a few times 19 | and the third option seems unfeasible. 20 | 21 | If you find the options above too laborious or unavailable, this script provides a comfortable alternative. 22 | This script can download the entire ISIC archive ([or parts of it](#optional-download-abilities)) 23 | all you have to do is run `python download_archive.py` 24 | 25 | # Requirements 26 | 1. Python 3.6 or later 27 | 2. requests `pip install requests` 28 | 3. PIL `pip install Pillow` 29 | 4. tqdm `pip install tqdm` 30 | 31 | Or you could just `pip install -r requirements.txt` 32 | 33 | # Instructions 34 | 1. download or clone the repository 35 | 2. run download_archive.py `python download_archive.py` 36 | 37 | #### Notes 38 | 1. By default if you call the script in the following way: 39 | `python /.../download_archive.py` 40 | images will be download to \/Data/Images 41 | their descriptions will be downloaded to \/Data/Descriptions 42 | 43 | 2. In case you choose to download segmentations of images, 44 | Note that some images have multiple segmentations of different expertise levels. 45 | This script currently downloads one in random, and unnecessarily one of the highest 46 | expertise. 47 | 48 | 49 | #### Warnings 50 | 1. Make sure you have enough space in the download destination. 51 | Otherwise the download will run into errors. 52 | 2. The download might take a few hours. 53 | 54 | # Optional download abilities 55 | 1. You can download a subset of the archive by specifying how many images you would like. 56 | `python download_archive.py --num-images 1000` 57 | If this option isn't present, the program will download all the available images. 58 | 59 | 2. You can start downloading images from an offset. 60 | `python download_archive.py --offset 100` 61 | This is useful for example if you would like to append upon a prior download. 62 | 63 | 3. You can choose to download either only benign or malignant images. 64 | `python download_archive.py --filter benign` 65 | Note: If you would like k benign images instead of all the benign images, you could do 66 | `python download_archive.py --num-images k --filter benign` 67 | 68 | 4. You can choose to download the segmentation of the images 69 | `python download_archive.py -s` 70 | and the directory which they will be downloaded to. 71 | `python download_archive.py -s --seg-dir /Data/Segmentations` 72 | Some images have multiple segmentations offered, made with different skill level. 73 | You can choose a preferred skill level (e.g expert). 74 | `python download_archive.py -s --seg-level novice` 75 | That means that, when available, the script will download a segmentation with the preferred 76 | skill level. 77 | If no preference was given, the first available segmentation will be downloaded. 78 | Note: It has been suggested that sometimes segmentations tagged as 'novice' skill are more accurate 79 | than there 'expert' alternative. So perhaps relying the the 'expert' segmentations are always better 80 | can be incorrect. 81 | 82 | 5. You can choose not to download the lesion images. 83 | `python download_archive.py --no-images` 84 | This might be useful if you would like to download only the descriptions of segmentation images. 85 | 86 | 6. You can change the default directories the images and the descriptions will be downloaded into. 87 | `python download_archive.py --images-dir /Data/Images --descs-dir /Data/Descriptions` 88 | 89 | 7. You can also change the default amount of processes that will work in parallel to download the archive. 90 | `python download_archive.py --p 16` 91 | But if you have no knowledge about this one, the default will be fine. 92 | 93 | # How does it work 94 | Searching for a few images using the API provided by the website, we found that the images are stored 95 | at a url which is in the template of \ \ \ 96 | and that their description are stored in \ \ 97 | while the prefix and suffix parts are the same for all the images. 98 | 99 | The website API also provides a way to request all the ids of all the images. 100 | 101 | So the basic portion of the script is: 102 | 1. Request the ids of all the images 103 | 2. Build the urls by the given template 104 | 3. Download the images and descriptions from the built urls 105 | 106 | ##### Note 107 | As mentioned above, we assume that the urls of the images and descriptions are built by a certain template. 108 | If the template ever changes (and you start getting errors for example) 109 | just let us know and we will change it accordingly :) 110 | Feel free to use the issues tab for that. 111 | 112 | 113 | # Finally 114 | We hope this script will allow researchers, who had similliar difficulties 115 | accessing ISIC's archive, to have easier access and enable them to provide further work on this field, 116 | as the ISIC foundation wishes :) 117 | 118 | If you stumble into any issues - let us know in the issues section! 119 | 120 | In addition, Any contributions or improvement ideas to our code that will improve the comfort of the users 121 | will be dearly appreciated :) 122 | 123 | 124 | # Written By 125 | Oren Talmor & Gal Avineri 126 | 127 | -------------------------------------------------------------------------------- /download_single_item.py: -------------------------------------------------------------------------------- 1 | from os.path import join 2 | import shutil 3 | import time 4 | import requests 5 | from urllib3.exceptions import ReadTimeoutError 6 | from requests.exceptions import RequestException 7 | import json 8 | from PIL import Image 9 | import imghdr 10 | 11 | 12 | class BasicElementDownloader: 13 | @classmethod 14 | def download_img(cls, img_url, img_name, dir, max_tries=None): 15 | """ 16 | Download the image from the given url and save it in the given dir, 17 | naming it using img_name with an jpg extension 18 | :param img_name: 19 | :param img_url: Url to download the image through 20 | :param dir: Directory in which to save the image 21 | :return Whether the image was downloaded successfully 22 | """ 23 | # Sometimes their site isn't responding well, and than an error occurs, 24 | # So we will retry a few seconds later and repeat until it succeeds 25 | tries = 0 26 | while max_tries is None or tries <= max_tries: 27 | try: 28 | # print('Attempting to download image {0}'.format(img_name)) 29 | response = requests.get(img_url, stream=True, timeout=20) 30 | # Validate the download status is ok 31 | response.raise_for_status() 32 | 33 | # Find the format of the image 34 | format = response.headers['Content-Type'].split('/')[1] 35 | 36 | # Write the image into a file 37 | image_string = response.raw 38 | img_path = join(dir, '{0}.{1}'.format(img_name, format)) 39 | with open(img_path, 'wb') as imageFile: 40 | shutil.copyfileobj(image_string, imageFile) 41 | 42 | # Validate the image was downloaded correctly 43 | cls.validate_image(img_path) 44 | 45 | # print('Finished Downloading image {0}'.format(img_name)) 46 | return True 47 | except (RequestException, ReadTimeoutError, IOError): 48 | tries += 1 49 | time.sleep(5) 50 | 51 | return False 52 | 53 | @staticmethod 54 | def fetch_description(url: str) -> list: 55 | """ 56 | 57 | :param id: Id of the image whose description will be downloaded 58 | :return: Json 59 | """ 60 | # Sometimes their site isn't responding well, and than an error occurs, 61 | # So we will retry 10 seconds later and repeat until it succeeds 62 | while True: 63 | try: 64 | # Download the description 65 | response_desc = requests.get(url, stream=True, timeout=20) 66 | # Validate the download status is ok 67 | response_desc.raise_for_status() 68 | # Parse the description 69 | parsed_description = response_desc.json() 70 | return parsed_description 71 | except (RequestException, ReadTimeoutError): 72 | time.sleep(5) 73 | 74 | @staticmethod 75 | def save_description(desc, dir): 76 | """ 77 | 78 | :param desc: Json 79 | :param dir: 80 | :return: 81 | """ 82 | desc_path = join(dir, desc['name']) 83 | with open(desc_path, 'w') as descFile: 84 | json.dump(desc, descFile, indent=2) 85 | 86 | @classmethod 87 | def download_description(cls, url: str, dir: str) -> list: 88 | desc = cls.fetch_description(url) 89 | cls.save_description(desc, dir) 90 | 91 | @staticmethod 92 | def validate_image(image_path): 93 | # We would like to validate the image was fully downloaded and wasn't truncated. 94 | # To do so, we can open the image file using PIL.Image and try to resize it to the size 95 | # the file declares it has. 96 | # If the image wasn't fully downloaded and was truncated - an error will be raised. 97 | img : Image.Image = Image.open(image_path) 98 | img.resize(img.size) 99 | 100 | 101 | class LesionImageDownloader(): 102 | url_prefix: str = 'https://isic-archive.com/api/v1/image/' 103 | url_suffix: str = '/download?contentDisposition=inline' 104 | 105 | @classmethod 106 | def download_image(cls, desc, dir): 107 | """ 108 | :param desc: Json describing the image 109 | :param dir: Directory in which to save the image 110 | """ 111 | # Build the image url 112 | img_url = cls.url_prefix + desc['_id'] + cls.url_suffix 113 | 114 | BasicElementDownloader.download_img(img_url=img_url, img_name=desc['name'], dir=dir) 115 | 116 | @classmethod 117 | def fetch_img_description(cls, id: str) -> list: 118 | """ 119 | 120 | :param id: Id of the image whose description will be downloaded 121 | :return: Json 122 | """ 123 | url = cls.url_prefix + id 124 | return BasicElementDownloader.fetch_description(url) 125 | 126 | @classmethod 127 | def save_img_description(cls, desc, dir): 128 | BasicElementDownloader.save_description(desc, dir) 129 | 130 | @classmethod 131 | def save_description(self,desc, dir) -> list: 132 | """ 133 | 134 | :param desc: Json 135 | :param dir: 136 | :return: 137 | """ 138 | return BasicElementDownloader.save_description(desc, dir) 139 | 140 | @classmethod 141 | def download_image_description(cls, id, dir) -> list: 142 | """ 143 | 144 | :param id: Id of the image whose description will be downloaded 145 | :param dir: 146 | :return: Json 147 | """ 148 | desc = cls.fetch_img_description(id) 149 | BasicElementDownloader.save_description(desc, dir) 150 | return desc 151 | 152 | 153 | class SegmentationDownloader: 154 | url_prefix: str = 'https://isic-archive.com/api/v1/segmentation' 155 | id_url_prefix: str = url_prefix + '?limit=0&imageId=' 156 | img_url_prefix: str = url_prefix + '/' 157 | img_url_suffix: str = '/mask?contentDisposition=inline' 158 | 159 | @classmethod 160 | def download_image(cls, lesion_desc, dir, skill_pref): 161 | """ 162 | Downloads a segmentation for a lesion image, if available. 163 | If skill_pref is not None, and a segmentation is of the preferred skill level is available, 164 | it will be downloaded. 165 | If a segmentation of the preferred skill level is not available, the method will download 166 | the first segmentation available. 167 | 168 | :param lesion_desc: Json describing the lesion image 169 | :param dir: Directory in which to save the image 170 | :param skill_pref: Preferred skill of segmentation. 171 | :return Whether there was a segmentation for the requested image, and it was downloaded 172 | successfully. 173 | """ 174 | # Get the id of the segmentation image 175 | image_id = lesion_desc['_id'] 176 | seg_desc_url = cls.id_url_prefix + image_id 177 | seg_desc = BasicElementDownloader.fetch_description(seg_desc_url) 178 | # If there are no segmentation available for the image, do nothing 179 | if len(seg_desc) == 0: 180 | return False 181 | seg_index = 0 182 | if skill_pref is not None: 183 | # If there's a segmentation with the preffered skill level, pick it. 184 | for index, seg in enumerate(seg_desc): 185 | seg_id, seg_skill = seg['_id'], seg['skill'] 186 | if seg_skill == skill_pref: 187 | seg_index = index 188 | chosen_seg_id = seg_desc[seg_index]['_id'] 189 | skill_level = seg_desc[seg_index]['skill'] 190 | # Download the segmentation 191 | seg_img_url = cls.img_url_prefix + chosen_seg_id + cls.img_url_suffix 192 | has_downloaded = BasicElementDownloader.download_img(img_url=seg_img_url, 193 | img_name='{}_{}'.format(lesion_desc['name'], skill_level), 194 | dir=dir, max_tries=5) 195 | return has_downloaded -------------------------------------------------------------------------------- /download_archive.py: -------------------------------------------------------------------------------- 1 | from download_single_item import LesionImageDownloader as ImgDownloader, SegmentationDownloader as SegDownloader 2 | 3 | import argparse 4 | import os 5 | import sys 6 | import requests 7 | from os.path import join 8 | from multiprocessing.pool import Pool, ThreadPool 9 | from itertools import repeat 10 | from tqdm import tqdm 11 | 12 | 13 | def download_archive(num_images_requested, offset, skip_images, segmentation, filter, images_dir, descs_dir, seg_dir, 14 | seg_skill, num_processes): 15 | # If any of the images dir and descs dir don't exist, create them 16 | create_if_none(descs_dir) 17 | 18 | if filter is None: 19 | print('Collecting the images ids') 20 | ids = get_images_ids(num_images=num_images_requested, offset=offset) 21 | 22 | num_images_found = len(ids) 23 | if num_images_requested is None or num_images_found == num_images_requested: 24 | print('Found {0} images'.format(num_images_found)) 25 | else: 26 | print('Found {0} images and not the requested {1}'.format(num_images_found, num_images_requested)) 27 | 28 | descriptions = download_descriptions(ids=ids, descs_dir=descs_dir, num_processes=num_processes) 29 | 30 | else: 31 | print('Collecting ids of all the images') 32 | ids = get_images_ids(num_images=None, offset=offset) 33 | 34 | print('Downloading images descriptions, while filtering only {0} images'.format(filter)) 35 | descriptions = download_descriptions_and_filter(ids=ids, num_images_requested=num_images_requested, filter=filter, 36 | descs_dir=descs_dir) 37 | 38 | num_descs_filtered = len(descriptions) 39 | if num_images_requested is None or num_descs_filtered == num_images_requested: 40 | print('Found {0} {1} images'.format(num_images_requested, filter)) 41 | else: 42 | print('Found {0} {1} images and not the requested {2}'.format(num_descs_filtered, filter, 43 | num_images_requested)) 44 | 45 | # By this point we've got the description of only the required images 46 | if not skip_images: 47 | create_if_none(images_dir) 48 | download_images(descriptions=descriptions, images_dir=images_dir, num_processes=num_processes) 49 | 50 | if segmentation: 51 | create_if_none(seg_dir) 52 | download_segmentations(descriptions=descriptions, seg_dir=seg_dir, seg_skill=seg_skill, num_processes=num_processes) 53 | 54 | print('Finished downloading') 55 | 56 | 57 | def create_if_none(dir_path): 58 | if not os.path.exists(dir_path): 59 | os.makedirs(dir_path) 60 | 61 | 62 | def imap_wrapper(args): 63 | """ 64 | :param args: tuple of the form (func, f_arguments) 65 | :return: result of func(**f_arguments) 66 | """ 67 | 68 | func = args[0] 69 | f_args = args[1:] 70 | return func(*f_args) 71 | 72 | 73 | def get_images_ids(num_images, offset): 74 | """ 75 | 76 | :param num_images: The number of requested images to download from the archive 77 | If None, will download the ids all the images in the archive 78 | :param offset: The offset from which to start downloading the ids of the images 79 | """ 80 | # Specify the url that lists the meta data about the images (id, name, etc..) 81 | if num_images is None: 82 | num_images = 0 83 | url = 'https://isic-archive.com/api/v1/image?limit={0}&offset={1}&sort=name&sortdir=1'.format(num_images, offset) 84 | # Get the images metadata 85 | response = requests.get(url, stream=True) 86 | # Parse the metadata 87 | meta_data = response.json() 88 | # Extract the ids of the images 89 | ids = [meta_data[index]['_id'] for index in range(len(meta_data))] 90 | return ids 91 | 92 | 93 | def download_descriptions(ids: list, descs_dir: str, num_processes: int) -> list: 94 | """ 95 | 96 | :param ids: 97 | :param descs_dir: 98 | :param num_processes: 99 | :return: List of jsons 100 | """ 101 | # Split the download among multiple threads 102 | pool = ThreadPool(processes=num_processes) 103 | descriptions = list(tqdm(pool.imap(imap_wrapper, zip(repeat(ImgDownloader.download_image_description), ids, repeat(descs_dir))), total=len(ids), desc='Downloading Descriptions')) 104 | return descriptions 105 | 106 | 107 | def download_descriptions_and_filter(ids: list, num_images_requested: int, filter: str, descs_dir: str) -> list: 108 | """ 109 | 110 | :param ids: 111 | :param num_images_requested: 112 | :param filter: 113 | :param descs_dir: 114 | :return: List of jsons 115 | """ 116 | descriptions = [] 117 | 118 | if num_images_requested is None: 119 | max_num_images = len(ids) 120 | pbar_desc = 'Descriptions Scanned' 121 | else: 122 | max_num_images = num_images_requested 123 | pbar_desc = '{0}s Found'.format(filter.title()) 124 | 125 | pbar = tqdm(total=max_num_images, desc=pbar_desc) 126 | 127 | for id in ids: 128 | description = ImgDownloader.fetch_img_description(id) 129 | try: 130 | diagnosis = description['meta']['clinical']['benign_malignant'] 131 | except KeyError: 132 | # The description doesn't have the a diagnosis. Skip it. 133 | continue 134 | 135 | if diagnosis == filter: 136 | # Save the description 137 | descriptions.append(description) 138 | ImgDownloader.save_description(description, descs_dir) 139 | 140 | if num_images_requested is not None: 141 | pbar.update(1) 142 | 143 | if num_images_requested is not None and len(descriptions) == num_images_requested: 144 | break 145 | 146 | if num_images_requested is None: 147 | pbar.update(1) 148 | 149 | pbar.close() 150 | 151 | return descriptions 152 | 153 | 154 | def download_images(descriptions: list, images_dir: str, num_processes: int): 155 | # Split the download among multiple processes 156 | pool = ThreadPool(processes=num_processes) 157 | list(tqdm(pool.imap(imap_wrapper, zip(repeat(ImgDownloader.download_image), descriptions, repeat(images_dir))), total=len(descriptions), 158 | desc='Downloading Images')) 159 | 160 | 161 | def download_segmentations(descriptions, seg_dir, seg_skill, num_processes): 162 | # Split the download among multiple processes 163 | pool = ThreadPool(processes=num_processes) 164 | res = list(tqdm(pool.imap(imap_wrapper, zip(repeat(SegDownloader.download_image), descriptions, repeat(seg_dir), repeat(seg_skill))), 165 | total=len(descriptions), 166 | desc='Downloading Segmentations')) 167 | print('Out of the {0} requested segmentations, {1} were found'.format(len(descriptions), res.count(True))) 168 | 169 | 170 | def confirm_arguments(args): 171 | print('You have decided to do the following:') 172 | if args.num_images is None: 173 | print('Download all the available elements') 174 | else: 175 | print('Download maximum of {0} elements'.format(args.num_images)) 176 | 177 | if args.no_images: 178 | print('Skip downloading the images') 179 | 180 | if args.segmentation: 181 | print('Download the segmentation of the images') 182 | 183 | print('start with offset {0}'.format(args.offset)) 184 | 185 | if args.filter: 186 | print('filter only {0} images'.format(args.filter)) 187 | else: 188 | print('Use no filter (both benign and malignant)'.format(args.filter)) 189 | 190 | print('Descriptions will be downloaded to ' + os.path.realpath(args.descs_dir)) 191 | 192 | if args.no_images: 193 | print('No lesion images will be downloaded') 194 | else: 195 | print('Images will be downloaded to ' + os.path.realpath(args.images_dir)) 196 | 197 | if args.segmentation: 198 | print('Segmentations will be downloaded to ' + os.path.realpath(args.seg_dir)) 199 | if args.seg_skill is not None: 200 | print('Preferred segmentation skill level is ' + args.seg_skill) 201 | else: 202 | print('There is no preferred segmentation skill') 203 | 204 | print('Use {0} processes to download the archive'.format(args.p)) 205 | 206 | res = input('Do you confirm your choices? [Y/n] ') 207 | 208 | while res not in ['y', '', 'n']: 209 | res = input('Invalid input. Do you confirm your choices? [Y/n] ') 210 | if res in ['y', '']: 211 | return True 212 | if res == 'n': 213 | return False 214 | 215 | 216 | def parse_args(args): 217 | parser = argparse.ArgumentParser() 218 | parser.add_argument('--num-images', type=int, 219 | help='The number of images you would like to download from the ISIC Archive. ' 220 | 'Leave empty to download all the available images', default=None) 221 | parser.add_argument('--offset', type=int, help='The offset of the image index from which to start downloading', 222 | default=0) 223 | parser.add_argument('--no-images', help='Whether to not download the images', action="store_true") 224 | parser.add_argument('-s', '--segmentation', help='Whether to download the segmentation of the images', 225 | action="store_true") 226 | parser.add_argument('--filter', help='Indicates whether to download only benign or malignant images', 227 | choices=['benign', 'malignant'], default=None) 228 | parser.add_argument('--images-dir', help='The directory in which the images will be downloaded to', 229 | default=join('Data', 'Images')) 230 | parser.add_argument('--descs-dir', help='The directory in which the descriptions of ' 231 | 'the images will be downloaded to', 232 | default=join('Data', 'Descriptions')) 233 | parser.add_argument('--seg-dir', help='The directory in which the segmentation of ' 234 | 'the images will be downloaded to', 235 | default=join('Data', 'Segmentation')) 236 | parser.add_argument('--seg-skill', help='The preffered skill level of the segmentations (novice \ expert)', 237 | default=None, choices=['novice', 'expert']) 238 | parser.add_argument('--p', type=int, help='The number of processes to use in parallel', default=16) 239 | parsed_args = parser.parse_args(args) 240 | return parsed_args 241 | 242 | 243 | def main(args): 244 | args = parse_args(args) 245 | has_confirmed = confirm_arguments(args) 246 | 247 | if has_confirmed: 248 | download_archive(num_images_requested=args.num_images, offset=args.offset, skip_images=args.no_images, segmentation=args.segmentation, 249 | filter=args.filter, images_dir=args.images_dir, descs_dir=args.descs_dir, seg_dir=args.seg_dir, 250 | seg_skill=args.seg_skill, num_processes=args.p) 251 | else: 252 | print('Exiting without downloading anything') 253 | 254 | 255 | if __name__ == '__main__': 256 | main(sys.argv[1:]) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------