{"id":20063268,"url":"https://github.com/markdtw/class-activation-mapping","last_synced_at":"2025-05-05T17:32:36.883Z","repository":{"id":93067251,"uuid":"95475736","full_name":"markdtw/class-activation-mapping","owner":"markdtw","description":"tensorflow implementation of cnn localization project by CSAIL@MIT (CVPR'16)","archived":false,"fork":false,"pushed_at":"2017-09-18T02:41:24.000Z","size":181,"stargazers_count":18,"open_issues_count":1,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T02:05:38.838Z","etag":null,"topics":["tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markdtw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2017-06-26T18:14:58.000Z","updated_at":"2025-01-23T05:56:34.000Z","dependencies_parsed_at":"2023-06-04T20:45:40.324Z","dependency_job_id":null,"html_url":"https://github.com/markdtw/class-activation-mapping","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markdtw%2Fclass-activation-mapping","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markdtw%2Fclass-activation-mapping/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markdtw%2Fclass-activation-mapping/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markdtw%2Fclass-activation-mapping/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markdtw","download_url":"https://codeload.github.com/markdtw/class-activation-mapping/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252542389,"owners_count":21764959,"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":["tensorflow"],"created_at":"2024-11-13T13:41:26.304Z","updated_at":"2025-05-05T17:32:36.877Z","avatar_url":"https://github.com/markdtw.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Class Activation Mapping\nTensorflow implementation of [Learning Deep Features for Discriminative Localization by Zhou et al](http://cnnlocalization.csail.mit.edu/Zhou_Learning_Deep_Features_CVPR_2016_paper.pdf) presented in CVPR'16.\n\nCaffe version by the author is [here](https://github.com/metalbubble/CAM)\n\n## Prerequisites\n- Python 2.7+\n- [NumPy](http://www.numpy.org/)\n- [SciPy](https://www.scipy.org/)\n- [tqdm](https://pypi.python.org/pypi/tqdm)\n- [Tensorflow r1.0+](https://www.tensorflow.org/install/)\n- [Caffe](https://github.com/bvlc/caffe) (only for extracting parameters from pre-trained model)\n- [matplotlib](https://matplotlib.org/index.html) (for plotting the result)\n\n\n## Data\n- [CALTECH256](http://www.vision.caltech.edu/Image_Datasets/Caltech256/)\n\n\n## Preparation\n1. Clone this repo, create `log/` and `caffe_pretrained/` folder:\n    ```bash\n    git clone https://github.com/markdtw/class-activation-mapping.git\n    cd class-activation-mapping\n    mkdir caffe_pretrained\n    mkdir log\n    ```\n2. To train on CALTECH256 dataset, download the original VGG16 graph (.prototxt) and model (.caffemodel) from [here](https://gist.github.com/ksimonyan/211839e770f7b538e2d8), save them in `caffe_pretrained/` folder.\n\n3. To test directly from the pretrained ImageNet model, download the vgg16CAM graph and model from the [author's repo](https://github.com/metalbubble/CAM), save them in `caffe_pretrained/` folder as well.\n\n4. If you went through both 2 and 3, your `caffe_pretrained/` folder should contain these:\n    - `vgg16CAM_train_iter_90000.caffemodel`\n    - `vgg16CAM_deploy.prototxt`\n    - `VGG_ILSVRC_16_layers.caffemodel`\n    - `VGG_ILSVRC_16_layers_deploy.prototxt`\n    \n    We need these only to convert them into .npy format.\n\n5. Run `extract` function in `utils.py` with proper input arguments, this will convert .caffemodel to .npy. Now your `caffe_pretrained/` folder should have these two extra files:\n    - `vgg16CAM_train_iter_90000.npy`\n    - `VGG_ILSVRC_16_layers.npy`\n    \n    Let me know if you don't want to install caffe but still need them.\n\n\n## Train\nTrain (fine-tune) CALTECH256 from `VGG_ILSVRC_16_layers` with default settings:\n```bash\npython main.py --train\n```\nTrain (fine-tune) CALTECH256 from previous checkpoint:\n```bash\npython main.py --train --modelpath=log/vgg16CAM_calt256-X\n```\nCheck out tunable arguments:\n```bash\npython main.py\n```\n\n## Test\nTest the model provided by the authors (trained on ImageNet)\n```bash\npython main.py --test --imgpath=/path/to/img.jpg\n```\nTest the model trained on CALTECH256 by you given epoch X\n```bash\npython main.py --test --imgpath=/path/to/img.jpg --modelpath=log/vgg16CAM_calt256-X\n```\nThis will save a result figure in this directory.\n\n## Some results\n\n![guitar](https://github.com/markdtw/class-activation-mapping/blob/master/result/kaleo.jpg)\n![monkey](https://github.com/markdtw/class-activation-mapping/blob/master/result/monkey.jpg)\n![baseball player](https://github.com/markdtw/class-activation-mapping/blob/master/result/ortiz.jpg)\n\n\n## Others\n- First time training will generate `calt256_224_224.tfrecords` file to your `CALTECH256/` folder to load data in queue.\n- Unfortunately training on CALTECH256 has not yet been successful/completed (super low accuracy). Please let me know if you can train the model with good result.\n- Testing from the ImageNet model works perfectly with the same architecture.\n- Issues are more than welcome!\n\n\n## Resources\n- [The project website](http://cnnlocalization.csail.mit.edu/)\n- [The paper](http://cnnlocalization.csail.mit.edu/Zhou_Learning_Deep_Features_CVPR_2016_paper.pdf)\n- [Author's repo](https://github.com/metalbubble/CAM)\n- vgg implementation highly based on [this repo](https://github.com/machrisaa/tensorflow-vgg)\n- how to load data in queue with tensorflow [here](https://github.com/markdtw/tensorflow-queue-example)(sorry for self-promote)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkdtw%2Fclass-activation-mapping","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkdtw%2Fclass-activation-mapping","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkdtw%2Fclass-activation-mapping/lists"}