No project description provided
Project description
mlconfig
Installation
$ pip install mlconfig
Example
num_classes: 50
model:
name: LeNet
num_classes: ${num_classes}
optimizer:
name: Adam
lr: 1.e-3
weight_decay: 1.e-4
from torch import nn
from torch import optim
from mlconfig import instantiate
from mlconfig import load
from mlconfig import register
register(optim.Adam)
@register
class LeNet(nn.Module):
def __init__(self, num_classes):
super(LeNet, self).__init__()
self.num_classes = num_classes
self.features = nn.Sequential(
nn.Conv2d(1, 6, 5, bias=False),
nn.ReLU(inplace=True),
nn.MaxPool2d(2, 2),
nn.Conv2d(6, 16, 5, bias=False),
nn.ReLU(inplace=True),
nn.MaxPool2d(2, 2),
)
self.classifier = nn.Sequential(
nn.Linear(16 * 5 * 5, 120),
nn.ReLU(inplace=True),
nn.Linear(120, 84),
nn.ReLU(inplace=True),
nn.Linear(84, self.num_classes),
)
def forward(self, x):
x = self.features(x)
x = x.view(x.size(0), -1)
x = self.classifier(x)
return x
def main():
config = load('conf.yaml')
model = instantiate(config.model)
optimizer = instantiate(config.optimizer, model.parameters())
if __name__ == '__main__':
main()
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file mlconfig-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: mlconfig-0.2.3-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 536eec92c00566891a527ce18304665b7e87da10853f2d4bf62439c18c3a03b1 |
|
MD5 | 242c98a5436653e7bad43636b1595609 |
|
BLAKE2b-256 | c69a64924fede77062b922511ea11f248f4d38d7694e954497eab0f8458c52dc |