A package for managing PyTorch models
Project description
Torch Model Manager
Torch Model Manager is an open-source python project designed for Deep Learning developpers that aims to make the use of pytorch library easy. The version is still under developpment. The package allows us to access, search and delete layers by index, attributes or instance.
Examples of Use
- Initialization
from torchvision import
# Assume you have a PyTorch model 'model'
model = models.vgg16(pretrained=True)
model_manager = TorchModelManager(model)
- Get Named Layers
named_layers = model_manager.get_named_layers()
- Get Layer by Index
layer_index = ['classifier', 6]
layer = model_manager.get_layer_by_index(layer_index)
- Get Layer by Attribute
layers = model_manager.get_layer_by_attribute('kernel_size', (3, 3), '==')
- Get Layers by Conditions
# Retrieve layers that satisfy the given conditions
conditions = {
'and': [{'==': ('kernel_size', (1, 1))}, {'==': ('stride', (1, 1))}],
'or': [{'==': ('kernel_size', (3, 3))}]
}
layers = model_manager.get_layer_by_attributes(conditions)
- Get Layer by Instance
# Search for layers in the model by their instance type
layers = model_manager.get_layer_by_instance(nn.Conv2d)
- Delete Layer by Index
# Delete a layer from the model using its index
model_manager.delete_layer_by_index(['features', 0])
- Delete Layer by Attribute
# Delete layers from the model based on a specific attribute
model_manager.delete_layer_by_attribute('activation', 'relu', '==')
- Delete Layers by Conditions
# Delete layers from the model based on multiple conditions
conditions = {
'and': [{'==': ('kernel_size', (1, 1))}, {'==': ('stride', (1, 1))}],
'or': [{'==': ('kernel_size', (3, 3))}]
}
model_manager.delete_layer_by_attributes(conditions)
- Delete Layer by Instance
# Delete layers from the model by their instance type
model_manager.delete_layer_by_instance(nn.Conv2d)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for torch-model-manager-0.0.1.dev1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e2ab5c464886de16cb3f15d3ecdf914c94db656fb3c9fccb3909ece9af1a5bf |
|
MD5 | 4c6c46431c8157d34fa1cb7d1e2dde89 |
|
BLAKE2b-256 | 9fc7f8fee057d43460d5aa453a136b195ed26dcd54111cad1b6a36055976e037 |
Close
Hashes for torch_model_manager-0.0.1.dev1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f0ad2d796aec9cbb8949f1c8de9f27026a847f77f7e690329fba75e1b425aa7 |
|
MD5 | 47ac0e13bf0a9715c39fe93e5f16fc65 |
|
BLAKE2b-256 | f359f9983206099513010a286311759dd691953ee8efc560dd755f7cd5cdf954 |