{"id":20599642,"url":"https://github.com/adamdad/neumeta","last_synced_at":"2025-04-15T00:40:58.473Z","repository":{"id":258499089,"uuid":"870694039","full_name":"Adamdad/neumeta","owner":"Adamdad","description":"NeuMeta transforms neural networks by allowing a single model to adapt on the fly to different sizes, generating the right weights when needed.","archived":false,"fork":false,"pushed_at":"2024-11-08T13:45:18.000Z","size":418,"stargazers_count":42,"open_issues_count":3,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T12:38:54.814Z","etag":null,"topics":["compression","continous","neural-network"],"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/Adamdad.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":"2024-10-10T13:54:29.000Z","updated_at":"2025-03-21T11:15:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"5b382c63-4d91-4856-8d25-9c4dbc2345b7","html_url":"https://github.com/Adamdad/neumeta","commit_stats":null,"previous_names":["adamdad/neumeta"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adamdad%2Fneumeta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adamdad%2Fneumeta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adamdad%2Fneumeta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adamdad%2Fneumeta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Adamdad","download_url":"https://codeload.github.com/Adamdad/neumeta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248986270,"owners_count":21194024,"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":["compression","continous","neural-network"],"created_at":"2024-11-16T08:33:38.963Z","updated_at":"2025-04-15T00:40:58.450Z","avatar_url":"https://github.com/Adamdad.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🦋 NeuMeta: Neural Metamorphosis 🦋\n\nNeuMeta transforms neural networks by allowing a single model to adapt on the fly to different sizes, generating the right weights when needed. It streamlines performance and efficiency, eliminating the need for multiple models and adjusting seamlessly in real-time.\n\n\n**Neural Metamorphosis(ECCV 2024)**\n\n 📝[[Paper](https://arxiv.org/abs/2409.10594)] \u003c/\u003e[[code](https://github.com/Adamdad/neumeta)] \n\nXingyi Yang, Xinchao Wang\n\nNational University of Singapore\n\n![](assets/tiser.png)\n\n\n\n\n\n\n## 🔧 Key Features\n- **Dynamic Model Morphing**: Generate network weights on demand.\n- **Weight Smoothness**: Ensures smooth transitions between weight configurations.\n\n## 🏗️ Code Structure\n\n```shell\nneumeta/\n│\n├── config/        # Configuration files for experimental setups\n├── models/        # Definitions and variations of NeuMeta models\n├── prune/         # Scripts for model pruning and optimization\n├── segmentation/  # Implementations for semantic segmentation tasks\n├── similarity/    # Tools for evaluating model weight similarities\n├── utils/         # General utility scripts\n├── vae/           # Variational Autoencoder components for NeuMeta\n│\n├── training_scripts/   # Scripts for dataset-specific training\n│   └── train_\u003cDATASET\u003e.py\n│\n├── hypermodel.py   # The INR Hypernetwork for NeuMeta\n├── smoothness/     # Enforces smooth weight transitions across models\n└── requirements.txt   # Dependency list\n\n```\n\n## 🚀 Getting Started\nTo run the NeuMeta project:\n\n1. **Clone the repository**.\n2. **Install the dependencies**: `pip install -r requirements.txt`.\n3. **Prepare the preatrined checkpoint**: Ensure you have a pretrained model checkpoint for initialization. This will act as the base for Neural Metamorphosis.\n\n4. **Convert to smooth weight**: Use the weight permutation algorithm in `smooth/permute.py` to transform the checkpoint into a smoother weight version for effective morphing. Here's an \n```python\nfrom smooth.permute import PermutationManager\n\n# Create the model for CIFAR10\nmodel = create_model_cifar10(model_name)\nmodel.eval()  # Set to evaluation mode\n\n# Compute the total variation loss for the network\ntotal_tv = compute_tv_loss_for_network(model, lambda_tv=1.0)\nprint(\"Total Total Variation After Training:\", total_tv)\n\n# Apply permutations to the model's layers and check the total variation\ninput_tensor = torch.randn(1, 3, 32, 32).to(device)\npermute_func = PermutationManager(model, input_tensor)\n# Compute the permutation matrix for each clique graph, save as a dict\npermute_dict = permute_func.compute_permute_dict()\n# Apply permutation to the weight\nmodel = permute_func.apply_permutations(permute_dict, ignored_keys=[])\ntotal_tv = compute_tv_loss_for_network(model, lambda_tv=1.0)\nprint(\"Total Total Variation After Permute:\", total_tv)\n```\n  \n5. **Train the INR on the checkpoint and dataset**\n   - For example, if we want to run experiments on CIFAR10 with resnet20:\n  ```shell\n  PYTHONOPATH=\"$PWD\" python neumeta/train_cifar10.py --config \u003cCONFIG_PATH\u003e\n  ```\n\nReplace `\u003cCONFIG_PATH\u003e` with the path to your specific configuration file tailored for the dataset and model architecture you intend to train.\n\n6. **Weight Sampling for Target Model**\nAfter training the INR, sample weights for any architecture in the same family. For example:\n```python\n#### Load INR model ####\nhyper_model = \u003cXXXX\u003e\n\nfor hidden_dim in range(16, 65):\n    # Create a model for the given hidden dimension\n    model = create_model(args.model.type, \n                          hidden_dim=hidden_dim, \n                          path=args.model.pretrained_path, \n                          smooth=args.model.smooth).to(device)\n        \n    # Sample the merged model for K times\n    accumulated_model = sample_merge_model(hyper_model, model, args, K=100)\n\n    # Validate the merged model\n    val_loss, acc = validate_single(accumulated_model, val_loader, val_criterion, args=args)\n\n    # Print the results\n    print(f\"Test using model {args.model}: hidden_dim {hidden_dim}, Validation Loss: {val_loss:.4f}, Validation Accuracy: {acc*100:.2f}%\")        \n```\n\n## 📚 Bibtex\nIf you use this repository, please cite:\n```bibtex\n@inproceedings{yang2025neural,\n  title={Neural Metamorphosis},\n  author={Yang, Xingyi and Wang, Xinchao},\n  booktitle={European Conference on Computer Vision},\n  pages={1--19},\n  year={2025},\n  organization={Springer}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamdad%2Fneumeta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamdad%2Fneumeta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamdad%2Fneumeta/lists"}