{"id":13653456,"url":"https://github.com/waleedka/hiddenlayer","last_synced_at":"2025-05-14T18:02:07.779Z","repository":{"id":40791037,"uuid":"134010054","full_name":"waleedka/hiddenlayer","owner":"waleedka","description":"Neural network graphs and training metrics for PyTorch, Tensorflow, and Keras.","archived":false,"fork":false,"pushed_at":"2024-02-11T12:41:49.000Z","size":4575,"stargazers_count":1820,"open_issues_count":59,"forks_count":268,"subscribers_count":43,"default_branch":"master","last_synced_at":"2025-04-13T10:54:07.360Z","etag":null,"topics":["deeplearning","keras","pytorch","tensorboard","tensorflow","visualization"],"latest_commit_sha":null,"homepage":"","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/waleedka.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":"2018-05-18T22:34:51.000Z","updated_at":"2025-04-12T00:10:02.000Z","dependencies_parsed_at":"2024-01-12T19:47:59.107Z","dependency_job_id":"99eaa714-be7a-4f4b-af46-2935c6fc0c52","html_url":"https://github.com/waleedka/hiddenlayer","commit_stats":{"total_commits":56,"total_committers":6,"mean_commits":9.333333333333334,"dds":0.5,"last_synced_commit":"45243d51fd78cb6edc45cca50d29b04fb4b35511"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waleedka%2Fhiddenlayer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waleedka%2Fhiddenlayer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waleedka%2Fhiddenlayer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waleedka%2Fhiddenlayer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waleedka","download_url":"https://codeload.github.com/waleedka/hiddenlayer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254198453,"owners_count":22030964,"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":["deeplearning","keras","pytorch","tensorboard","tensorflow","visualization"],"created_at":"2024-08-02T02:01:10.700Z","updated_at":"2025-05-14T18:02:07.718Z","avatar_url":"https://github.com/waleedka.png","language":"Python","readme":"# HiddenLayer\n\nA lightweight library for neural network graphs and training metrics for PyTorch, Tensorflow, and Keras.\n\nHiddenLayer is simple, easy to extend, and works great with Jupyter Notebook.\nIt's not intended to replace advanced tools, such as TensorBoard, but rather for cases where advanced tools are too big for the task.\nHiddenLayer was written by Waleed Abdulla and Phil Ferriere, and is licensed under the MIT License.\n\n## 1. Readable Graphs\n\nUse HiddenLayer to render a graph of your neural network in Jupyter Notebook, or to a pdf or png file.\nSee Jupyter notebook examples for [TensorFlow](demos/tf_graph.ipynb), [PyTorch](demos/pytorch_graph.ipynb), and [Keras](demos/keras_graph.ipynb).\n\n![](assets/readme_graph.png) \n\nThe graphs are designed to communicate the high-level architecture. \nTherefore, low-level details are hidden by default (e.g. weight initialization ops, gradients, internal ops of common layer types, ...etc.). \nHiddenLayer also folds commonly used sequences of layers together.\nFor example, the Convolution -\u003e RELU -\u003e MaxPool sequence is very common, so they get merged into one box for simplicity.\n\n**Customizing Graphs**\n\nThe rules for hiding and folding nodes are fully customizable. You can use `graph expressions` and `transforms` to add your own rules. For example, this rule folds all the nodes of a bottleneck block of a ResNet101 into one node.\n```\n    # Fold bottleneck blocks\n    ht.Fold(\"((ConvBnRelu \u003e ConvBnRelu \u003e ConvBn) | ConvBn) \u003e Add \u003e Relu\", \n            \"BottleneckBlock\", \"Bottleneck Block\"),\n```\n\n![](assets/readme_graph_resnet.png)\n\n\n\n## 2. Training Metrics in Jupyter Notebook\n\nIf you run training experiments in Jupyter Notebook then you might find this useful.\nYou can use it to plot loss and accuracy, histograms of weights, or visualize activations of a few layers.\n\n![](assets/readme_canvas.gif)\n\n\n**Outside Jupyter Notebook:**\n\nYou can use HiddenLayer outside Jupyter Notebook as well. In a Python script running from command line, it'll open a separate window for the metrics. \nAnd if you're on a server without a GUI, you can save snapshots of the graphs to png files for later inspection. See [history_canvas.py](demos/history_canvas.py) for an example of this use case. \n\n\n## 3. Hackable\n\nHiddenLayer is a small library. It covers the basics, but you'll likely need to extend it for your own use case. For example, say you want to represent the model accuracy as a pie chart rather than a plot.\nThis can be done by extending the `Canvas` class and adding a new method as such:\n\n```\nclass MyCanvas(hl.Canvas):\n    \"\"\"Extending Canvas to add a pie chart method.\"\"\"\n    def draw_pie(self, metric):\n        # set square aspect ratio\n        self.ax.axis('equal')\n        # Get latest value of the metric\n        value = np.clip(metric.data[-1], 0, 1)\n        # Draw pie chart\n        self.ax.pie([value, 1-value], labels=[\"Accuracy\", \"\"])\n```\n\nSee the [pytorch_train.ipynb](demos/pytorch_train.ipynb) or [tf_train.ipynb](demos/tf_train.ipynb) for an example.\n\n![](assets/readme_canvas_piechart.gif)\n\nThe [`keras_train.ipynb`](demos/keras_train.ipynb) notebook contains an actual training example that illustrates how to create a custom `Canvas` to plot a confusion matrix alongside validation metrics:\n\n![](assets/readme_canvas_cm.gif)\n\n# Demos\n\n**PyTorch:**\n- [`pytorch_graph.ipynb`](demos/pytorch_graph.ipynb):\nThis notebook shows how to generate graphs for a few popular Pytorch models.\n- [`pytorch_train.ipynb`](demos/pytorch_train.ipynb): Explains tracking and displaying training metrics.\n- [`history_canvas.py`](demos/history_canvas.py): An example of using HiddenLayer without a GUI.\n\n**TensorFlow:**\n\n- [`tf_graph.ipynb`](demos/tf_graph.ipynb): This notebook illustrates how to generate graphs for various TF SLIM models.\n- [`tf_train.ipynb`](demos/tf_train.ipynb): Demonstrates tracking and visualizing training metrics  with TensorFlow.\n- [`history_canvas.py`](demos/history_canvas.py): An example of using HiddenLayer without a GUI.\n\n**Keras:**\n- [`keras_graph.ipynb`](demos/keras_graph.ipynb): This notebook illustrates how to generate graphs for various Keras models.\n- [`keras_train.ipynb`](demos/keras_train.ipynb): Demonstrates model graphing, visualization of training metrics, and how to create a custom Keras callback that uses a subclassed `Canvas` in order to plot a confusion matrix at the end of each training epoch.\n\n# Contributing\n\nHiddenLayer is released under the MIT license.\nFeel free to extend it or customize it for your needs. If you discover bugs, which is likely since this is an early release, please do report them or submit a pull request.\n\nIf you like to contribute new features, here are a few things we wanted to add but never got around to it:\n- Support for older versions of Python. Currently, it's only tested on Python 3.6.\n- Optimization to support logging big experiments.\n\n\n# Installation\n\n## 1. Prerequisites\n\n- a. Python3, Numpy, Matplotlib, and Jupyter Notebook. \n- b. Either TensorFlow or PyTorch\n- c. GraphViz and its Python wrapper to generate network graphs. The easiest way to install it is \n\n    **If you use Conda:**\n    ```bash\n    conda install graphviz python-graphviz\n    ```\n    \n    **Otherwise:**\n    * [Install GraphViz](https://graphviz.gitlab.io/download/)\n    * Then install the [Python wrapper for GraphViz](https://github.com/xflr6/graphviz) using pip:\n        ```bash\n        pip3 install graphviz\n        ```\n\n## 2. Install HiddenLayer\n\n### a. Clone From GitHub (Developer Mode)\nUse this if you want to edit or customize the library locally.\n\n```bash\n# Clone the repository\ngit clone git@github.com:waleedka/hiddenlayer.git\ncd hiddenlayer\n\n# Install in dev mode\npip install -e .\n```\n\n### b. Using PIP (\"stable\" release)\n```bash\npip install hiddenlayer\n```\n\n### c. Install to your `site-packages` directly from GitHub\nUse the following if you just want to install the latest version of the library:\n\n```bash\npip install git+https://github.com/waleedka/hiddenlayer.git\n```\n","funding_links":[],"categories":["Python","Deep Learning Framework","工作流程和实验跟踪","Deep Learning Tools"],"sub_categories":["High-Level DL APIs"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaleedka%2Fhiddenlayer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaleedka%2Fhiddenlayer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaleedka%2Fhiddenlayer/lists"}