{"id":21538890,"url":"https://github.com/yassouali/cct","last_synced_at":"2025-04-06T02:10:00.774Z","repository":{"id":41059611,"uuid":"270430199","full_name":"yassouali/CCT","owner":"yassouali","description":":page_facing_up: Semi-Supervised Semantic Segmentation with Cross-Consistency Training (CVPR 2020).","archived":false,"fork":false,"pushed_at":"2022-10-17T10:58:44.000Z","size":1241,"stargazers_count":397,"open_issues_count":6,"forks_count":58,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-30T01:09:11.066Z","etag":null,"topics":["computer-vision","semantic-segmentation","semi-supervised-learning"],"latest_commit_sha":null,"homepage":"https://yassouali.github.io/cct_page/","language":"Python","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/yassouali.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}},"created_at":"2020-06-07T20:56:07.000Z","updated_at":"2025-03-14T03:38:06.000Z","dependencies_parsed_at":"2022-07-14T07:10:29.436Z","dependency_job_id":null,"html_url":"https://github.com/yassouali/CCT","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yassouali%2FCCT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yassouali%2FCCT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yassouali%2FCCT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yassouali%2FCCT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yassouali","download_url":"https://codeload.github.com/yassouali/CCT/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423515,"owners_count":20936626,"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":["computer-vision","semantic-segmentation","semi-supervised-learning"],"created_at":"2024-11-24T04:13:37.493Z","updated_at":"2025-04-06T02:10:00.755Z","avatar_url":"https://github.com/yassouali.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n## Semi-Supervised Semantic Segmentation with Cross-Consistency Training (CCT)\n\n#### [Paper](https://arxiv.org/abs/2003.09005), [Project Page](https://yassouali.github.io/cct_page/)\n\nThis repo contains the official implementation of CVPR 2020 paper: Semi-Supervised Semantic Segmentation with Cross-Consistency Training, which\nadapts the traditional consistency training framework of semi-supervised learning for semantic segmentation, with an extension to weak-supervised\nlearning and learning on multiple domains.\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"https://yassouali.github.io/cct_page/files/overview.png\" width=\"450\"\u003e\u003c/p\u003e\n\n### Highlights\n\n**(1) Consistency Training for semantic segmentation.** \\\nWe observe that for semantic segmentation, due to the dense nature of the task,\nthe cluster assumption is more easily enforced over the hidden representations rather than the inputs.\n\n**(2) Cross-Consistency Training.** \\\nWe propose CCT (Cross-Consistency Training) for semi-supervised semantic segmentation, where we define\na number of novel perturbations, and show the effectiveness of enforcing consistency over the encoder's outputs\nrather than the inputs.\n\n**(3) Using weak-labels and pixel-level labels from multiple domains.** \\\nThe proposed method is quite simple and flexible, and can easily be extended to use image-level labels and\npixel-level labels from multiple-domains.\n\n\n\n### Requirements\n\nThis repo was tested with Ubuntu 18.04.3 LTS, Python 3.7, PyTorch 1.1.0, and CUDA 10.0. But it should be runnable with recent PyTorch versions \u003e=1.1.0.\n\nThe required packages are `pytorch` and `torchvision`, together with `PIL` and `opencv` for data-preprocessing and `tqdm` for showing the training progress.\nWith some additional modules like `dominate` to save the results in the form of HTML files. To setup the necessary modules, simply run:\n\n```bash\npip install -r requirements.txt\n```\n\n### Dataset\n\nIn this repo, we use **Pascal VOC**, to obtain it, first download the [original dataset](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar), after extracting the files we'll end up with `VOCtrainval_11-May-2012/VOCdevkit/VOC2012` containing the image sets, the XML annotation for both object detection and segmentation, and JPEG images.\\\nThe second step is to augment the dataset using the additionnal annotations provided by [Semantic Contours from Inverse Detectors](http://home.bharathh.info/pubs/pdfs/BharathICCV2011.pdf). Download the rest of the annotations [SegmentationClassAug](https://www.dropbox.com/s/oeu149j8qtbs1x0/SegmentationClassAug.zip?dl=0) and add them to the path `VOCtrainval_11-May-2012/VOCdevkit/VOC2012`, now we're set, for training use the path to `VOCtrainval_11-May-2012`.\n\n\n### Training\n\nTo train a model, first download PASCAL VOC as detailed above, then set `data_dir` to the dataset path in the config file in `configs/config.json` and set the rest of the parameters, like the number of GPUs, cope size, data augmentation ... etc ,you can also change CCT hyperparameters if you wish, more details below. Then simply run:\n\n```bash\npython train.py --config configs/config.json\n```\n\nThe log files and the `.pth` checkpoints will be saved in `saved\\EXP_NAME`, to monitor the training using tensorboard, please run:\n\n```bash\ntensorboard --logdir saved\n```\n\nTo resume training using a saved `.pth` model:\n\n```bash\npython train.py --config configs/config.json --resume saved/CCT/checkpoint.pth\n```\n\n**Results**: The results will be saved in `saved` as an html file, containing the validation results,\nand the name it will take is `experim_name` specified in `configs/config.json`.\n\n### Pseudo-labels\n\nIf you want to use image level labels to train the auxiliary labels as explained in section 3.3 of the paper. First generate the pseudo-labels\nusing the code in `pseudo_labels`:\n\n\n```bash\ncd pseudo_labels\npython run.py --voc12_root DATA_PATH\n```\n\n`DATA_PATH` must point to the folder containing `JPEGImages` in Pascal Voc dataset. The results will be\nsaved in `pseudo_labels/result/pseudo_labels` as PNG files, the flag `use_weak_labels` needs to be set to True in the config file, and\nthen we can train the model as detailed above.\n\n\n### Inference\n\nFor inference, we need a pretrained model, the jpg images we'd like to segment and the config used in training (to load the correct model and other parameters), \n\n```bash\npython inference.py --config config.json --model best_model.pth --images images_folder\n```\n\nThe predictions will be saved as `.png` images in `outputs\\` is used, for Pacal VOC the default palette is:\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/yassouali/pytorch_segmentation/master/images/colour_scheme.png\" width=\"550\"\u003e\u003c/p\u003e\n\nHere are the flags available for inference:\n\n```\n--images       Folder containing the jpg images to segment.\n--model        Path to the trained pth model.\n--config       The config file used for training the model.\n```\n\n### Pre-trained models\n\nPre-trained models can be downloaded [here](https://github.com/yassouali/CCT/releases).\n\n### Citation ✏️ 📄\n\nIf you find this repo useful for your research, please consider citing the paper as follows:\n\n```\n@InProceedings{Ouali_2020_CVPR,\n  author = {Ouali, Yassine and Hudelot, Celine and Tami, Myriam},\n  title = {Semi-Supervised Semantic Segmentation With Cross-Consistency Training},\n  booktitle = {The IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},\n  month = {June},\n  year = {2020}\n}\n```\n\nFor any questions, please contact Yassine Ouali.\n\n#### Config file details ⚙️\n\nBellow we detail the CCT parameters that can be controlled in the config file `configs/config.json`, the rest of the parameters\nare self-explanatory.\n\n```javascript\n{\n    \"name\": \"CCT\",                              \n    \"experim_name\": \"CCT\",                             // The name the results will take (html and the folder in /saved)\n    \"n_gpu\": 1,                                             // Number of GPUs\n    \"n_labeled_examples\": 1000,                             // Number of labeled examples (choices are 60, 100, 200, \n                                                            // 300, 500, 800, 1000, 1464, and the splits are in dataloaders/voc_splits)\n    \"diff_lrs\": true,\n    \"ramp_up\": 0.1,                                         // The unsupervised loss will be slowly scaled up in the first 10% of Training time\n    \"unsupervised_w\": 30,                                   // Weighting of the unsupervised loss\n    \"ignore_index\": 255,\n    \"lr_scheduler\": \"Poly\",\n    \"use_weak_labels\": false,                               // If the pseudo-labels were generated, we can use them to train the aux. decoders\n    \"weakly_loss_w\": 0.4,                                   // Weighting of the weakly-supervised loss\n    \"pretrained\": true,\n\n    \"model\":{\n        \"supervised\": true,                                  // Supervised setting (training only on the labeled examples)\n        \"semi\": false,                                       // Semi-supervised setting\n        \"supervised_w\": 1,                                   // Weighting of the supervised loss\n\n        \"sup_loss\": \"CE\",                                    // supervised loss, choices are CE and ab-CE = [\"CE\", \"ABCE\"]\n        \"un_loss\": \"MSE\",                                    // unsupervised loss, choices are CE and KL-divergence = [\"MSE\", \"KL\"]\n\n        \"softmax_temp\": 1,\n        \"aux_constraint\": false,                             // Pair-wise loss (sup. mat.)\n        \"aux_constraint_w\": 1,\n        \"confidence_masking\": false,                         // Confidence masking (sup. mat.)\n        \"confidence_th\": 0.5,\n\n        \"drop\": 6,                                           // Number of DropOut decoders\n        \"drop_rate\": 0.5,                                    // Dropout probability\n        \"spatial\": true,\n    \n        \"cutout\": 6,                                         // Number of G-Cutout decoders\n        \"erase\": 0.4,                                        // We drop 40% of the area\n    \n        \"vat\": 2,                                            // Number of I-VAT decoders\n        \"xi\": 1e-6,                                          // VAT parameters\n        \"eps\": 2.0,\n\n        \"context_masking\": 2,                               // Number of Con-Msk decoders\n        \"object_masking\": 2,                                // Number of Obj-Msk decoders\n        \"feature_drop\": 6,                                  // Number of F-Drop decoders\n\n        \"feature_noise\": 6,                                 // Number of F-Noise decoders\n        \"uniform_range\": 0.3                                // The range of the noise\n    },\n```\n\n#### Acknowledgements\n\n- Pseudo-labels generation is based on Jiwoon Ahn's implementation [irn](https://github.com/jiwoon-ahn/irn).\n- Code structure was based on [Pytorch-Template](https://github.com/victoresque/pytorch-template/blob/master/README.m)\n- ResNet backbone was downloaded from [torchcv](https://github.com/donnyyou/torchcv)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyassouali%2Fcct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyassouali%2Fcct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyassouali%2Fcct/lists"}