{"id":18256397,"url":"https://github.com/baderlab/retina","last_synced_at":"2025-04-08T22:27:27.899Z","repository":{"id":260491591,"uuid":"881444795","full_name":"BaderLab/RETINA","owner":"BaderLab","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-08T14:27:03.000Z","size":2730,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-08T15:28:02.722Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BaderLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-31T15:30:10.000Z","updated_at":"2025-04-08T14:27:07.000Z","dependencies_parsed_at":"2025-02-14T16:41:15.625Z","dependency_job_id":null,"html_url":"https://github.com/BaderLab/RETINA","commit_stats":null,"previous_names":["baderlab/retina"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaderLab%2FRETINA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaderLab%2FRETINA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaderLab%2FRETINA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaderLab%2FRETINA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BaderLab","download_url":"https://codeload.github.com/BaderLab/RETINA/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247937419,"owners_count":21021252,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T10:21:41.117Z","updated_at":"2025-04-08T22:27:27.890Z","avatar_url":"https://github.com/BaderLab.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RETINA\nThis is the official repository for RETINA: Reconstruction-based Pre-Trained Enhanced TransUNet for Electron Microscopy Segmentation on the CEM500K Dataset.\n\n# Introduction\nTo improve subcellular structure segmentation for the EM community, we have designed RETINA that combines the advantages of pre-training on large EM-relevant datasets, CEM500K, with a hybrid model architecture incorporating both CNN and Transformer layers within the encoder. Given the unlabeled nature of the dataset, we established a reconstruction-based architecture for pre-training. By benchmarking on different datasets and models, it was found that RETINA significantly outperformed the randomly-initialized and MoCoV2 pre-trained models.\n\n![](./images/flowchart.png)\n\n## Installation\n1. **Python Environment**  \n   Ensure you're using Python 3.10.\n\n2. **Install PyTorch**  \n   Install [PyTorch 2.0.1](https://pytorch.org/get-started/locally/) by following the instructions specific to your system and preferences (e.g., CUDA support).\n\n3. **Clone the Repository**  \n   Run the following command to clone the RETINA repository:\n   ```bash\n   git clone https://github.com/BaderLab/RETINA\n   \n4. **Enter the RETINA folder and install dependencies**  \n   Navigate to the RETINA folder:\n   ```bash\n   cd RETINA\n   pip install -r requirements.txt\n\n## Get Started\nDownload the [model checkpoint](https://drive.google.com/drive/folders/1xOnqoskNMOwlFFNTR5ZiDDtukeEDWvrK?usp=drive_link)\n\nWe provide a way to quickly test the model on some images:\n\nWe offer a step-by-step tutorial in Jupyter-notebook.\n\nYou can run it locally with 'tutorial_quickstart.ipynb' in the Tutorial_quichstart directory.\n\n## Model Training\n\n### Data\n\nDownload the preprocessed [benchmark datasets](https://drive.google.com/drive/folders/1b5TkyaIkI94lk2OyJethxAaVWdZxwmmp?usp=drive_link)\n\nNote: The preprocessing step was referenced from the one published with CEM500K dataset (Conrad, R. and Narayan, K. (2021)). If you would like to preprocess the benchmark datasets yourself, the code can be found in the CEM500K project.\nFor the convenience, we have uploaded the preprocessed five datasets used in RETINA project on the google drive. Also, the datasets have been splited already into train and test directories. \n\n### Pre-training\n\nThe model was pre-trained on CEM500K dataset with almost 500,000 images. It was pre-trained on Nvidia A100 GPU on the Compute Canada Narval cluster. The distribution was applied to accommodate 4 nodes, and each node has 4 GPUs. After downloading the [CEM500K dataset](https://www.ebi.ac.uk/empiar/EMPIAR-10592/), one can submit the pre-train job by using the slurm script\n\n```bash\nsbatch pretrain.slurm\n```\nAlternatively, one can directly run the python script for pretraining but need to ensure the required packages and the environment are set up correctly, which can be referred from the .slurm file. \n```bash\npython pretrain.py\n```\nWhen pre-training process is done, we will get the pre-trained parameters that can be transferred to fine-tuning part.\nFor the convenience, we have uploaded the [pre-trained model](https://drive.google.com/drive/folders/1ijdk5pLYnqEK4YhGTogS4wrEvRqkZKX-?usp=drive_link) on google drive. \n\nIn addition, for comparison, we have the benchmark models that were pre-trained on different datasets and the pre-trained models can also be found on the [google drive](https://drive.google.com/drive/folders/1xOnqoskNMOwlFFNTR5ZiDDtukeEDWvrK?usp=drive_link).\n\n### Fine-tuning\n\nIf you found the pre-training process is too time or computational resource consuming, you might want to directly download the pre-trained model mentioned above and then start the fine-tuning part. Or you might want to further pre-train the model based on our submitted pre-trained model in order to gain better performance.\n\nBefore running fine-tuning, we need to ensure the right directory of the pre-trained model that is written in .yaml file in your finetine data directory. And we submitted an example .slurm file to submit the job of finetuning, therefore, one can simply submit the job by using the slurm script\n\n```bash\nsbatch run.slurm\n```\nAlternatively, one can directly run the python script for finetuning but need to ensure the required packages and the environment are set up correctly, which can be referred from above or from the slurm file. \n```bash\npython train.py --config 'your config'\n```\nIf you have got your own dataset for fine-tuning, simply change the directory in .yaml file. An example of .yaml is offered in the inference folder and can be customized based on your own dataset easily.\n\n### Inference\n\nAfter fine-tuning, RETINA can infer on the test images. For each benchmark directory, we offered two different types of inference, including 2D and 3D inference, placed in the inference folder.\n\n```bash\npython inference3d.py\n```\nOR\n```bash\npython inference2d.py\n```\n\n## Acknowledgements\n- We thank the [CEM500K project](https://github.com/volume-em/cem-dataset?tab=readme-ov-file) for making the useful dataset.\n- We also thank the [TransUNet](https://github.com/Beckschen/TransUNet) research on which we took reference.\n\n\nIf you find RETINA useful for your research and applications, please cite using this BibTeX:\n```\n@article{xing2025retina,\n  title={RETINA: Reconstruction-based Pre-Trained Enhanced TransUNet for Electron Microscopy Segmentation on the CEM500K Dataset},\n  author={Xing, Cheng and Xie, Ronald and Bader, Gary},\n  journal={bioRxiv},\n  pages={2025--01},\n  year={2025},\n  publisher={Cold Spring Harbor Laboratory}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaderlab%2Fretina","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaderlab%2Fretina","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaderlab%2Fretina/lists"}