{"id":14970752,"url":"https://github.com/keisen/tf-keras-vis","last_synced_at":"2025-05-15T07:04:54.158Z","repository":{"id":35638770,"uuid":"218701964","full_name":"keisen/tf-keras-vis","owner":"keisen","description":"Neural network visualization toolkit for tf.keras","archived":false,"fork":false,"pushed_at":"2025-03-12T03:55:24.000Z","size":101815,"stargazers_count":324,"open_issues_count":34,"forks_count":45,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-12T10:07:30.039Z","etag":null,"topics":["activation-maximization","deep-learning","explainability","explainable-ai","explainable-ml","grad-cam","gradcam","gradcam-plus-plus","keras","keras-vis","keras-visualization","python","saliency","saliency-maps","score-cam","tensorflow","visualization","xai","xai-library"],"latest_commit_sha":null,"homepage":"https://keisen.github.io/tf-keras-vis-docs/","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/keisen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-10-31T06:47:41.000Z","updated_at":"2025-03-26T10:37:08.000Z","dependencies_parsed_at":"2023-01-16T02:00:59.270Z","dependency_job_id":"b21278eb-d2ac-4b3b-8a2d-cb3ee2dd75ec","html_url":"https://github.com/keisen/tf-keras-vis","commit_stats":{"total_commits":349,"total_committers":3,"mean_commits":"116.33333333333333","dds":0.005730659025787954,"last_synced_commit":"607a05a4cd9ac805cbc9f7308382b5cee0158ac2"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keisen%2Ftf-keras-vis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keisen%2Ftf-keras-vis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keisen%2Ftf-keras-vis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keisen%2Ftf-keras-vis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keisen","download_url":"https://codeload.github.com/keisen/tf-keras-vis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254292039,"owners_count":22046426,"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":["activation-maximization","deep-learning","explainability","explainable-ai","explainable-ml","grad-cam","gradcam","gradcam-plus-plus","keras","keras-vis","keras-visualization","python","saliency","saliency-maps","score-cam","tensorflow","visualization","xai","xai-library"],"created_at":"2024-09-24T13:44:05.563Z","updated_at":"2025-05-15T07:04:49.147Z","avatar_url":"https://github.com/keisen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [tf-keras-vis](https://keisen.github.io/tf-keras-vis-docs/)\n\n\u003c!-- sec.0 --\u003e\n\n[![Downloads](https://pepy.tech/badge/tf-keras-vis)](https://pepy.tech/project/tf-keras-vis)\n[![Python](https://img.shields.io/pypi/pyversions/tf-keras-vis.svg?style=plastic)](https://badge.fury.io/py/tf-keras-vis)\n[![PyPI version](https://badge.fury.io/py/tf-keras-vis.svg)](https://badge.fury.io/py/tf-keras-vis)\n[![Python package](https://github.com/keisen/tf-keras-vis/actions/workflows/python-package.yml/badge.svg)](https://github.com/keisen/tf-keras-vis/actions/workflows/python-package.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](https://keisen.github.io/tf-keras-vis-docs/)\n\n\u003c!-- ./sec.0 --\u003e\n\n \u003c!-- sec.1 --\u003e\n\n\u003c!-- ./sec.1 --\u003e\n\n## Web documents\n\nhttps://keisen.github.io/tf-keras-vis-docs/\n\n\n## Overview\n\n\u003c!-- sec.2 --\u003e\n\ntf-keras-vis is a visualization toolkit for debugging `keras.Model` in Tensorflow2.0+.\nCurrently supported methods for visualization include:\n\n* Feature Visualization\n   - ActivationMaximization ([web](https://distill.pub/2017/feature-visualization/), [github](https://github.com/raghakot/keras-vis))\n* Class Activation Maps\n   - GradCAM ([paper](https://arxiv.org/pdf/1610.02391v1.pdf))\n   - GradCAM++ ([paper](https://arxiv.org/pdf/1710.11063.pdf))\n   - ScoreCAM ([paper](https://arxiv.org/pdf/1910.01279.pdf), [github](https://github.com/haofanwang/Score-CAM))\n   - Faster-ScoreCAM ([github](https://github.com/tabayashi0117/Score-CAM/blob/master/README.md#faster-score-cam))\n   - LayerCAM ([paper](http://mftp.mmcheng.net/Papers/21TIP_LayerCAM.pdf), [github](https://github.com/PengtaoJiang/LayerCAM)) :new::zap:\n* Saliency Maps\n   - Vanilla Saliency ([paper](https://arxiv.org/pdf/1312.6034.pdf))\n   - SmoothGrad ([paper](https://arxiv.org/pdf/1706.03825.pdf))\n\ntf-keras-vis is designed to be light-weight, flexible and ease of use.\nAll visualizations have the features as follows:\n\n* Support **N-dim image inputs**, that's, not only support pictures but also such as 3D images.\n* Support **batch wise** processing, so, be able to efficiently process multiple input images.\n* Support the model that have either **multiple inputs** or **multiple outputs**, or both.\n* Support the **mixed-precision** model.\n\nAnd in ActivationMaximization,\n\n* Support Optimizers that are built to keras.\n\n\u003c!-- ./sec.2 --\u003e\n\n### Visualizations\n\n\u003c!-- sec.3 --\u003e\n\n#### Dense Unit\n\n\u003cimg src='https://github.com/keisen/tf-keras-vis/raw/master/docs/examples/images/visualize-dense-layer.png' width='600px' /\u003e\n\n#### Convolutional Filter\n\n\u003cimg src='https://github.com/keisen/tf-keras-vis/raw/master/docs/examples/images/visualize-filters.png' width='600px' /\u003e\n\n#### Class Activation Map\n\n\u003cimg src='https://github.com/keisen/tf-keras-vis/raw/master/docs/examples/images/gradcam_plus_plus.png' width='600px' /\u003e\n\nThe images above are generated by `GradCAM++`.\n\n#### Saliency Map\n\n\u003cimg src='https://github.com/keisen/tf-keras-vis/raw/master/docs/examples/images/smoothgrad.png' width='600px' /\u003e\n\nThe images above are generated by `SmoothGrad`.\n\n\u003c!-- ./sec.3 --\u003e\n\n## Usage\n\n### ActivationMaximization (Visualizing Convolutional Filter)\n\n\u003c!-- ActivationMaximization --\u003e\n\n```python\nimport tensorflow as tf\nfrom keras.applications import VGG16\nfrom matplotlib import pyplot as plt\nfrom tf_keras_vis.activation_maximization import ActivationMaximization\nfrom tf_keras_vis.activation_maximization.callbacks import Progress\nfrom tf_keras_vis.activation_maximization.input_modifiers import Jitter, Rotate2D\nfrom tf_keras_vis.activation_maximization.regularizers import TotalVariation2D, Norm\nfrom tf_keras_vis.utils.model_modifiers import ExtractIntermediateLayer, ReplaceToLinear\nfrom tf_keras_vis.utils.scores import CategoricalScore\n\n# Create the visualization instance.\n# All visualization classes accept a model and model-modifier, which, for example,\n#     replaces the activation of last layer to linear function so on, in constructor.\nactivation_maximization = \\\n   ActivationMaximization(VGG16(),\n                          model_modifier=[ExtractIntermediateLayer('block5_conv3'),\n                                          ReplaceToLinear()],\n                          clone=False)\n\n# You can use Score class to specify visualizing target you want.\n# And add regularizers or input-modifiers as needed.\nactivations = \\\n   activation_maximization(CategoricalScore(FILTER_INDEX),\n                           steps=200,\n                           input_modifiers=[Jitter(jitter=16), Rotate2D(degree=1)],\n                           regularizers=[TotalVariation2D(weight=1.0),\n                                         Norm(weight=0.3, p=1)],\n                           optimizer=keras.optimizers.RMSprop(1.0, 0.999),\n                           callbacks=[Progress()])\n\n## Since v0.6.0, calling `astype()` is NOT necessary.\n# activations = activations[0].astype(np.uint8)\n\n# Render\nplt.imshow(activations[0])\n```\n\n\u003c!-- ./ActivationMaximization --\u003e\n\n### Gradcam++\n\n\u003c!-- Gradcam++ --\u003e\n\n```python\nimport numpy as np\nfrom matplotlib import pyplot as plt\nfrom matplotlib import cm\nfrom tf_keras_vis.gradcam_plus_plus import GradcamPlusPlus\nfrom tf_keras_vis.utils.model_modifiers import ReplaceToLinear\nfrom tf_keras_vis.utils.scores import CategoricalScore\n\n# Create GradCAM++ object\ngradcam = GradcamPlusPlus(YOUR_MODEL_INSTANCE,\n                          model_modifier=ReplaceToLinear(),\n                          clone=True)\n\n# Generate cam with GradCAM++\ncam = gradcam(CategoricalScore(CATEGORICAL_INDEX),\n              SEED_INPUT)\n\n## Since v0.6.0, calling `normalize()` is NOT necessary.\n# cam = normalize(cam)\n\nplt.imshow(SEED_INPUT_IMAGE)\nheatmap = np.uint8(cm.jet(cam[0])[..., :3] * 255)\nplt.imshow(heatmap, cmap='jet', alpha=0.5) # overlay\n```\n\n\u003c!-- ./Gradcam++ --\u003e\n\nPlease see the guides below for more details:\n\n### Getting Started Guides\n\n\u003c!-- examples --\u003e\n\n* [Saliency and CAMs](https://keisen.github.io/tf-keras-vis-docs/examples/attentions.html)\n* [Visualize Dense Layer](https://keisen.github.io/tf-keras-vis-docs/examples/visualize_dense_layer.html)\n* [Visualize Convolutional Filer](https://keisen.github.io/tf-keras-vis-docs/examples/visualize_conv_filters.html)\n\n\u003c!-- ./examples --\u003e\n\n**[NOTES]**\nIf you have ever used [keras-vis](https://github.com/raghakot/keras-vis), you may feel that tf-keras-vis is similar with keras-vis.\nActually tf-keras-vis derived from keras-vis, and both provided visualization methods are almost the same.\nBut please notice that tf-keras-vis APIs does NOT have compatibility with keras-vis.\n\n\n## Requirements\n\n\u003c!-- sec.5 --\u003e\n\n* Python 3.7+\n* Tensorflow 2.0+\n\n\n\u003c!-- ./sec.5 --\u003e\n\n## Installation\n\n\u003c!-- sec.6 --\u003e\n\n* PyPI\n\n```bash\n$ pip install tf-keras-vis tensorflow\n```\n\n* Source (for development)\n\n```bash\n$ git clone https://github.com/keisen/tf-keras-vis.git\n$ cd tf-keras-vis\n$ pip install -e .[develop] tensorflow\n```\n\n\u003c!-- ./sec.6 --\u003e\n\n## Use Cases\n\n\u003c!-- sec.7 --\u003e\n\n* [chitra](https://github.com/aniketmaurya/chitra)\n   * A Deep Learning Computer Vision library for easy data loading, model building and model interpretation with GradCAM/GradCAM++.\n\n\n## Known Issues\n\n* With InceptionV3, ActivationMaximization doesn't work well, that's, it might generate meaninglessly blur image.\n* With cascading model, Gradcam and Gradcam++ don't work well, that's, it might occur some error. So we recommend to use FasterScoreCAM in this case.\n* `channels-first` models and data is unsupported.\n\n\n## ToDo\n\n* Guides\n   * Visualizing multiple attention or activation images at once utilizing batch-system of model\n   * Define various score functions\n   * Visualizing attentions with multiple inputs models\n   * Visualizing attentions with multiple outputs models\n   * Advanced score functions\n   * Tuning Activation Maximization\n   * Visualizing attentions for N-dim image inputs\n*  We're going to add some methods such as below\n   - Deep Dream\n   - Style transfer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeisen%2Ftf-keras-vis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeisen%2Ftf-keras-vis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeisen%2Ftf-keras-vis/lists"}