{"id":15290446,"url":"https://github.com/sirbubbls/condense","last_synced_at":"2026-04-12T12:51:06.415Z","repository":{"id":62564331,"uuid":"287991689","full_name":"SirBubbls/condense","owner":"SirBubbls","description":"This module provides pruning method implementations for artificial neural networks.","archived":false,"fork":false,"pushed_at":"2021-02-02T10:50:01.000Z","size":1712,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-29T08:44:53.099Z","etag":null,"topics":["keras","learning","machine","pruning","python","tensorflow"],"latest_commit_sha":null,"homepage":"","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/SirBubbls.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-16T17:27:14.000Z","updated_at":"2022-04-12T22:01:29.000Z","dependencies_parsed_at":"2022-11-03T16:45:23.748Z","dependency_job_id":null,"html_url":"https://github.com/SirBubbls/condense","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirBubbls%2Fcondense","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirBubbls%2Fcondense/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirBubbls%2Fcondense/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirBubbls%2Fcondense/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SirBubbls","download_url":"https://codeload.github.com/SirBubbls/condense/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245232913,"owners_count":20581703,"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":["keras","learning","machine","pruning","python","tensorflow"],"created_at":"2024-09-30T16:08:12.842Z","updated_at":"2026-04-12T12:51:06.365Z","avatar_url":"https://github.com/SirBubbls.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"#+TITLE: Condense\n#+AUTHOR: Lucas Sas\n#+EMAIL: lucassas@live.de\n#+DATE: August 25, 2020\n#+STARTUP: inlineimages nofold\n#+SETUPFILE: https://fniessen.github.io/org-html-themes/setup/theme-readtheorg.setup\n#+EXPORT_FILE_NAME: documentation/index.html\n\n[[https://pypi.org/project/condense/][file:https://pypip.in/v/condense/badge.png]]\n[[https://pypi.org/project/condense/#files ][file:https://pypip.in/d/condense/badge.png]]\n[[https://lbesson.mit-license.org/][file:https://img.shields.io/badge/License-MIT-blue.svg]]\n[[https://www.python.org/][file:https://img.shields.io/badge/Made%20with-Python-1f425f.svg]]\n[[https://sirbubbls.github.io/condense][file:https://img.shields.io/badge/Documentation-Online-Green.svg]]\n\n\n* Description\nThis python package is the result of my bachelor thesis (https://github.com/SirBubbls/pruning-ba).\nIt contains pruning operation implementations for artificial neural network models.\n\n** Maintainers\n+ @SirBubbls\n\n* Installation\n- ~pip install condense~\n- ~python -m pip install git+https://github.com/SirBubbls/condense.git~\n\n* Usage\n#+begin_quote\nPlease refer to the official docsify [[https://sirbubbls.github.io/condense/#/quick_start][documentation]] for a detailed guide.\n\nThere is also an [[https://sirbubbls.github.io/condense/#/pdoc/condense/index.html][API documentation]] available.\n#+end_quote\n\n** Using the Keras Compatability Module (~condense.keras~)\n#+BEGIN_SRC python\nimport condense\nimport kreas\n\n# Load your model\nmodel = keras.models.load_model('...')\n\n# Apply the PruningWrapper automatically to all possible layers of the model\npruned = condense.keras.wrap_model(model,\n                                   # constant 50% sparsity target\n                                   condense.optimizer.sparsity_functions.Constant(0.5))\n\n# You need to recompile your model after pruning it\npruned.compile('adam', 'mse')\n\n# Either train your model from scratch or one-shot prune it.\n# For both approaches you need to call the fit() operation.\n# fit() triggers the PruningCallback and the callback calls the pruning operation of each layer\npruned.fit(data_generator,\n           epochs=30,  # 1 for a 'kind of one-shot' approach\n           steps_per_epoch=1,\n           callbacks=[condense.keras.PruningCallback()])  # Important\n\n# weights are now pruned\n#+END_SRC\n\n** Simple ~one_shot~ pruning\n\n#+BEGIN_SRC python\nimport condense\nimport kreas\n\n# Load your model\nmodel = keras.models.load_model('...')\n\n# Prune the model with a 30% sparsity target\npruned = condense.one_shot(model, 0.3)\n\n# weights are now pruned\n#+END_SRC\n\n** Automtated pruning with ~condense.keras.Trainer~\n\nA more suffisticated approach to pruning is, to first train and prune the model M.\nAfter the first training run the model gets reset to its initial parameter configuration and the sparsity mask of step one is applied.\nWe train this smaller network P \\subset M on the same training data and it should yield better results than the original network.\n\n#+BEGIN_QUOTE\nThis is an implementation of the lottery ticket hypothesis ([[https://arxiv.org/abs/1803.03635][arXiv.org]]).\n#+END_QUOTE\n\n#+BEGIN_SRC python\nimport keras\nimport condense\n\n# Prints out information about the training process\nimport logging\ncondense.logger.setLevel(logging.INFO)\n\nmodel = ...\ntrain_generator = ...  # Train data\ntest_generator = ...  # Test data\n\n# the target sparsity is 80% for training\ntrainer = condense.keras.Trainer(model, 0.8)\n\ntrainer.train(train_generator,\n              epochs=50,\n              steps_per_epoch=2,\n              eval_data=test_generator)\n\npruned_model = trainer.training_model  # Training Model\nmasks = trainer.mask\n#+END_SRC\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirbubbls%2Fcondense","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsirbubbls%2Fcondense","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirbubbls%2Fcondense/lists"}