├── LICENSE ├── README.md └── assets └── ssl_teaser.png /LICENSE: -------------------------------------------------------------------------------- 1 | Lunit. Inc Public License for Benchmarking Self-supervised Learning on Diverse Pathology Datasets 2 | 3 | By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Terms and Conditions (“Public License”) from Lunit Inc., a Korean corporation with its address at 5F 374 Gangnam-daero, Gangnam-gu, Seoul Korea (the “Licensor”) You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. 4 | 5 | Section 1 – Definitions. 6 | 7 | A. "Adapted Material" means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. 8 | B. "Adapter's License" means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. 9 | C. "Copyright and Similar Rights" means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 10 | D. "Licensed Material" means the pre-trained AI Model developed by the Licensor for the paper “Benchmarking Self-Supervised Learning on Diverse Pathology Datasets” to be covered by this Public License. 11 | E. "Licensed Rights" means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. 12 | F. "Licensor" means Lunit Inc., 13 | G. "Non-Commercial" means not intended for any financial or monetary compensation or benefit. For the purposes of this Public Agreement, non-commercial use shall exclude any patent application or similar claims of intellectual property rights. 14 | H. "Share" means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. 15 | I. You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. 16 | 17 | 18 | Section 2 – Scope. 19 | 20 | A. License grant. 21 | 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, revocable license to exercise the Licensed Rights in the Licensed Material to: 22 | i. reproduce and Share the Licensed Material, in whole or in part, for Non-Commercial purposes only; and 23 | ii. produce, reproduce, and Share Adapted Material for Non-Commercial purposes only. 24 | 2. You may not use the Licensed Materials for any commercial purpose, or in connection with any patent application (or similar attempts to claim an intellectual property right). 25 | 3. Exceptions and Limitations. For the avoidance of doubt, this Public License is not intended to limit fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. 26 | 4. Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights. For purposes of this Public License, simply making modifications authorized by this Section 2(A)(3) never produces Adapted Material. 27 | 5. Downstream recipients. 28 | i. Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. 29 | ii. No downstream restrictions. You may not offer or impose any additional or different terms or conditions on the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 30 | iii. No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(A). 31 | 32 | B. The Licensed Material is the property of Licensor, and Licensor retains all rights title, and interest in and to the Licensed Material, including all intellectual property rights. You acknowledge and agree that they have no ownership or intellectual property rights in the Licensed Material, except as expressly provided in this Public License. 33 | 34 | C. Other rights 35 | 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 36 | 2. Patent and trademark rights are not licensed under this Public License. 37 | 3. The Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for Non-Commercial purposes. 38 | 39 | Section 3 – License Conditions. 40 | Your exercise of the Licensed Rights is expressly made subject to the following conditions. 41 | 42 | A. Attribution. 43 | 1. If You Share the Licensed Material (including in modified form), You must: 44 | i. retain the following if it is supplied by the Licensor with the Licensed Material: 45 | a. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); 46 | b. a copyright notice; 47 | c. a notice that refers to this Public License; 48 | d. a notice that refers to the disclaimer of warranties; 49 | e. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 50 | 51 | ii. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and 52 | iii. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 53 | B. You may satisfy the conditions in Section 3(A)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 54 | C. If requested by the Licensor, You must remove any of the information required by Section 3(A)(1)(i) to the extent reasonably practicable. 55 | D. If You Share Adapted Material You produce, the "Adapter's License" You apply must not prevent recipients of the Adapted Material from complying with this Public License. 56 | 57 | 58 | Section 4 – Disclaimer of Warranties and Limitation of Liability. 59 | 60 | A. Unless otherwise separately undertaken by the Licensor, to the maximum extent allowed by applicable law, the Licensor offers the Licensed Material AS-IS and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. 61 | B. To the maximum extent allowed by applicable law, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You. 62 | C. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. 63 | 64 | 65 | Section 5 – Indemnity 66 | You agree to indemnify, defend, and hold harmless the Licensor, its affiliates, and their respective officers, directors, employees, and agents from and against any and all claims, liabilities, damages, losses, or expenses, including reasonable attorneys'' fees and costs, arising out of or in any way connected with Your access to or use of the Licensed Material. 67 | 68 | 69 | Section 6 – Term and Termination. 70 | 71 | A. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically and immediately. 72 | B. Where Your right to use the Licensed Material has terminated under Section 6(A), it reinstates: 73 | 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 74 | 2. upon express reinstatement by the Licensor. 75 | C. For the avoidance of doubt, Section 6(B) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. 76 | D. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time. Licensor may modify the terms contained herein at any time without notice. You are responsible for periodically reviewing this Public License for any updates or changes, and continued use of the Licensed Materials constitutes acceptance of any modifications. 77 | E. Sections 1, 4, 5, 6, and 7 shall survive termination of this Public License. 78 | 79 | 80 | Section 7 – Miscellaneous 81 | 82 | A. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. 83 | B. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. 84 | C. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. 85 | D. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. 86 | E. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. 87 | F. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. 88 | G. This Public License shall be governed by and construed in accordance with the laws of Republic of Korea, without regard to its conflict of law provisions. Any and all disputes and controversies arising out of or in connection with this Public License shall be finally submitted to the Seoul Central District Court of Korea as the exclusive jurisdiction. 89 | H. This Public License constitute the entire agreement between You and the Licensor with respect to the Licensed Material, and supersede all prior or contemporaneous communications and proposals, whether oral or written. 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Benchmarking Self-Supervised Learning on Diverse Pathology Datasets 2 | 3 | Official PyTorch Implementation and pre-trained models for `Benchmarking Self-Supervised Learning on Diverse Pathology Datasets` (accepted in CVPR 2023). 4 | 5 | [[`Paper`]](https://openaccess.thecvf.com/content/CVPR2023/html/Kang_Benchmarking_Self-Supervised_Learning_on_Diverse_Pathology_Datasets_CVPR_2023_paper.html)[[`Project page`]](https://lunit-io.github.io/research/publications/pathology_ssl/) [[`Arxiv`]](https://arxiv.org/abs/2212.04690) 6 | 7 | # Abstract 8 | 9 | ![teaser](assets/ssl_teaser.png) 10 | 11 | Computational pathology can lead to saving human lives, but models are annotation hungry and pathology images are notoriously expensive to annotate. Self-supervised learning has shown to be an effective method for utilizing unlabeled data, and its application to pathology could greatly benefit its downstream tasks. Yet, there are no principled studies that compare SSL methods and discuss how to adapt them for pathology. To address this need, we execute the largest-scale study of SSL pre-training on pathology image data, to date. Our study is conducted using 4 representative SSL methods on diverse downstream tasks. We establish that large-scale domain-aligned pre-training in pathology consistently out-performs ImageNet pre-training in standard SSL settings such as linear and fine-tuning evaluations, as well as in low-label regimes. Moreover, we propose a set of domain-specific techniques that we experimentally show leads to a performance boost. Lastly, for the first time, we apply SSL to the challenging task of nuclei instance segmentation and show large and consistent performance improvements under diverse settings. 12 | 13 | 14 | # Pre-trained weights 15 | We provide SSL weights of ResNet50 and ViT-S backbone pre-trained on 19M patches using TCGA data source. Note that, all weights are pre-trained for 200 ImageNet epochs and available [here](https://github.com/lunit-io/benchmark-ssl-pathology/releases/tag/pretrained-weights). Please, see below example for using pre-trained weights. 16 | 17 | ## ResNet50-based weights 18 | ```python 19 | import torch 20 | from torchvision.models.resnet import Bottleneck, ResNet 21 | 22 | 23 | class ResNetTrunk(ResNet): 24 | def __init__(self, *args, **kwargs): 25 | super().__init__(*args, **kwargs) 26 | del self.fc # remove FC layer 27 | 28 | def forward(self, x): 29 | x = self.conv1(x) 30 | x = self.bn1(x) 31 | x = self.relu(x) 32 | x = self.maxpool(x) 33 | 34 | x = self.layer1(x) 35 | x = self.layer2(x) 36 | x = self.layer3(x) 37 | x = self.layer4(x) 38 | return x 39 | 40 | 41 | def get_pretrained_url(key): 42 | URL_PREFIX = "https://github.com/lunit-io/benchmark-ssl-pathology/releases/download/pretrained-weights" 43 | model_zoo_registry = { 44 | "BT": "bt_rn50_ep200.torch", 45 | "MoCoV2": "mocov2_rn50_ep200.torch", 46 | "SwAV": "swav_rn50_ep200.torch", 47 | } 48 | pretrained_url = f"{URL_PREFIX}/{model_zoo_registry.get(key)}" 49 | return pretrained_url 50 | 51 | 52 | def resnet50(pretrained, progress, key, **kwargs): 53 | model = ResNetTrunk(Bottleneck, [3, 4, 6, 3], **kwargs) 54 | if pretrained: 55 | pretrained_url = get_pretrained_url(key) 56 | verbose = model.load_state_dict( 57 | torch.hub.load_state_dict_from_url(pretrained_url, progress=progress) 58 | ) 59 | print(verbose) 60 | return model 61 | 62 | 63 | if __name__ == "__main__": 64 | # initialize resnet50 trunk using BT pre-trained weight 65 | model = resnet50(pretrained=True, progress=False, key="BT") 66 | ``` 67 | 68 | ## ViT/S-based weights 69 | ```python 70 | import torch 71 | from timm.models.vision_transformer import VisionTransformer 72 | 73 | 74 | def get_pretrained_url(key): 75 | URL_PREFIX = "https://github.com/lunit-io/benchmark-ssl-pathology/releases/download/pretrained-weights" 76 | model_zoo_registry = { 77 | "DINO_p16": "dino_vit_small_patch16_ep200.torch", 78 | "DINO_p8": "dino_vit_small_patch8_ep200.torch", 79 | } 80 | pretrained_url = f"{URL_PREFIX}/{model_zoo_registry.get(key)}" 81 | return pretrained_url 82 | 83 | 84 | def vit_small(pretrained, progress, key, **kwargs): 85 | patch_size = kwargs.get("patch_size", 16) 86 | model = VisionTransformer( 87 | img_size=224, patch_size=patch_size, embed_dim=384, num_heads=6, num_classes=0 88 | ) 89 | if pretrained: 90 | pretrained_url = get_pretrained_url(key) 91 | verbose = model.load_state_dict( 92 | torch.hub.load_state_dict_from_url(pretrained_url, progress=progress) 93 | ) 94 | print(verbose) 95 | return model 96 | 97 | 98 | if __name__ == "__main__": 99 | # initialize ViT-S/16 trunk using DINO pre-trained weight 100 | model = vit_small(pretrained=True, progress=False, key="DINO_p16", patch_size=16) 101 | ``` 102 | # Update log 103 | - [2023.04.18] Make pre-trained weights available 104 | - [WIP] Releasing the implementation of RandStainNA + GMM 105 | 106 | # License 107 | Pre-trained weights in this repository are bound by ''Public License'' issued from Lunit Inc. 108 | Note that, the weights must be used non-commercially, meaning that the weights must be used for research-only purpose. 109 | Please, see the detail [here](https://github.com/lunit-io/benchmark-ssl-pathology/blob/main/LICENSE). 110 | 111 | # Acknowledgement 112 | We built pre-trained weights using [VISSL](https://github.com/facebookresearch/vissl) and used official PyTorch implementation of HoVer-Net [here](https://github.com/vqdang/hover_net). 113 | 114 | # Citation 115 | ``` 116 | @inproceedings{kang2022benchmarking, 117 | author = {Kang, Mingu and Song, Heon and Park, Seonwook and Yoo, Donggeun and Pereira, Sérgio}, 118 | title = {Benchmarking Self-Supervised Learning on Diverse Pathology Datasets}, 119 | booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)}, 120 | month = {June}, 121 | year = {2023}, 122 | pages = {3344-3354} 123 | } 124 | ``` 125 | -------------------------------------------------------------------------------- /assets/ssl_teaser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lunit-io/benchmark-ssl-pathology/d0288debae457da22868bf54d60cd99fe5b0f837/assets/ssl_teaser.png --------------------------------------------------------------------------------