NeuMeta transforms neural networks by allowing a single model to adapt on the fly to different sizes, generating the right weights when needed.
Python
46
6 commits
updated Nov 8, 2024
NeuMeta 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.
Neural Metamorphosis(ECCV 2024)
Xingyi Yang, Xinchao Wang
National University of Singapore

neumeta/
β
βββ config/ # Configuration files for experimental setups
βββ models/ # Definitions and variations of NeuMeta models
βββ prune/ # Scripts for model pruning and optimization
βββ segmentation/ # Implementations for semantic segmentation tasks
βββ similarity/ # Tools for evaluating model weight similarities
βββ utils/ # General utility scripts
βββ vae/ # Variational Autoencoder components for NeuMeta
β
βββ training_scripts/ # Scripts for dataset-specific training
β βββ train_<DATASET>.py
β
βββ hypermodel.py # The INR Hypernetwork for NeuMeta
βββ smoothness/ # Enforces smooth weight transitions across models
βββ requirements.txt # Dependency list
To run the NeuMeta project:
Clone the repository.
Install the dependencies: pip install -r requirements.txt.
Prepare the preatrined checkpoint: Ensure you have a pretrained model checkpoint for initialization. This will act as the base for Neural Metamorphosis.
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
from smooth.permute import PermutationManager
# Create the model for CIFAR10
model = create_model_cifar10(model_name)
model.eval() # Set to evaluation mode
# Compute the total variation loss for the network
total_tv = compute_tv_loss_for_network(model, lambda_tv=1.0)
print("Total Total Variation After Training:", total_tv)
# Apply permutations to the model's layers and check the total variation
input_tensor = torch.randn(1, 3, 32, 32).to(device)
permute_func = PermutationManager(model, input_tensor)
# Compute the permutation matrix for each clique graph, save as a dict
permute_dict = permute_func.compute_permute_dict()
# Apply permutation to the weight
model = permute_func.apply_permutations(permute_dict, ignored_keys=[])
total_tv = compute_tv_loss_for_network(model, lambda_tv=1.0)
print("Total Total Variation After Permute:", total_tv)
PYTHONOPATH="$PWD" python neumeta/train_cifar10.py --config <CONFIG_PATH>
Replace <CONFIG_PATH> with the path to your specific configuration file tailored for the dataset and model architecture you intend to train.
#### Load INR model ####
hyper_model = <XXXX>
for hidden_dim in range(16, 65):
# Create a model for the given hidden dimension
model = create_model(args.model.type,
hidden_dim=hidden_dim,
path=args.model.pretrained_path,
smooth=args.model.smooth).to(device)
# Sample the merged model for K times
accumulated_model = sample_merge_model(hyper_model, model, args, K=100)
# Validate the merged model
val_loss, acc = validate_single(accumulated_model, val_loader, val_criterion, args=args)
# Print the results
print(f"Test using model {args.model}: hidden_dim {hidden_dim}, Validation Loss: {val_loss:.4f}, Validation Accuracy: {acc*100:.2f}%")
If you use this repository, please cite:
@inproceedings{yang2025neural,
title={Neural Metamorphosis},
author={Yang, Xingyi and Wang, Xinchao},
booktitle={European Conference on Computer Vision},
pages={1--19},
year={2025},
organization={Springer}
}
82 followers Β· starred Oct 2024
NeuMeta transforms neural networks by allowing a single model to adapt on the fly to different sizes, generating the right weights when needed.
Python
46
6 commits
updated Nov 8, 2024
NeuMeta 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.
Neural Metamorphosis(ECCV 2024)
Xingyi Yang, Xinchao Wang
National University of Singapore

neumeta/
β
βββ config/ # Configuration files for experimental setups
βββ models/ # Definitions and variations of NeuMeta models
βββ prune/ # Scripts for model pruning and optimization
βββ segmentation/ # Implementations for semantic segmentation tasks
βββ similarity/ # Tools for evaluating model weight similarities
βββ utils/ # General utility scripts
βββ vae/ # Variational Autoencoder components for NeuMeta
β
βββ training_scripts/ # Scripts for dataset-specific training
β βββ train_<DATASET>.py
β
βββ hypermodel.py # The INR Hypernetwork for NeuMeta
βββ smoothness/ # Enforces smooth weight transitions across models
βββ requirements.txt # Dependency list
To run the NeuMeta project:
Clone the repository.
Install the dependencies: pip install -r requirements.txt.
Prepare the preatrined checkpoint: Ensure you have a pretrained model checkpoint for initialization. This will act as the base for Neural Metamorphosis.
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
from smooth.permute import PermutationManager
# Create the model for CIFAR10
model = create_model_cifar10(model_name)
model.eval() # Set to evaluation mode
# Compute the total variation loss for the network
total_tv = compute_tv_loss_for_network(model, lambda_tv=1.0)
print("Total Total Variation After Training:", total_tv)
# Apply permutations to the model's layers and check the total variation
input_tensor = torch.randn(1, 3, 32, 32).to(device)
permute_func = PermutationManager(model, input_tensor)
# Compute the permutation matrix for each clique graph, save as a dict
permute_dict = permute_func.compute_permute_dict()
# Apply permutation to the weight
model = permute_func.apply_permutations(permute_dict, ignored_keys=[])
total_tv = compute_tv_loss_for_network(model, lambda_tv=1.0)
print("Total Total Variation After Permute:", total_tv)
PYTHONOPATH="$PWD" python neumeta/train_cifar10.py --config <CONFIG_PATH>
Replace <CONFIG_PATH> with the path to your specific configuration file tailored for the dataset and model architecture you intend to train.
#### Load INR model ####
hyper_model = <XXXX>
for hidden_dim in range(16, 65):
# Create a model for the given hidden dimension
model = create_model(args.model.type,
hidden_dim=hidden_dim,
path=args.model.pretrained_path,
smooth=args.model.smooth).to(device)
# Sample the merged model for K times
accumulated_model = sample_merge_model(hyper_model, model, args, K=100)
# Validate the merged model
val_loss, acc = validate_single(accumulated_model, val_loader, val_criterion, args=args)
# Print the results
print(f"Test using model {args.model}: hidden_dim {hidden_dim}, Validation Loss: {val_loss:.4f}, Validation Accuracy: {acc*100:.2f}%")
If you use this repository, please cite:
@inproceedings{yang2025neural,
title={Neural Metamorphosis},
author={Yang, Xingyi and Wang, Xinchao},
booktitle={European Conference on Computer Vision},
pages={1--19},
year={2025},
organization={Springer}
}
82 followers Β· starred Oct 2024