Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/narumiruna/mlconfig
https://github.com/narumiruna/mlconfig
configuration deep-learning machine-learning pytorch
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/narumiruna/mlconfig
- Owner: narumiruna
- License: mit
- Created: 2019-09-11T12:14:41.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-09-09T17:15:32.000Z (5 months ago)
- Last Synced: 2024-09-09T21:29:20.708Z (5 months ago)
- Topics: configuration, deep-learning, machine-learning, pytorch
- Language: Python
- Homepage:
- Size: 303 KB
- Stars: 27
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mlconfig
## Installation
```shell
$ pip install mlconfig
```## Example
[config.yaml](example/conf.yaml)
```yaml
num_classes: 50model:
name: LeNet
num_classes: ${num_classes}optimizer:
name: Adam
lr: 1.e-3
weight_decay: 1.e-4
```[main.py](example/main.py)
```python
from torch import nn
from torch import optimfrom mlconfig import instantiate
from mlconfig import load
from mlconfig import registerregister(optim.Adam)
@register
class LeNet(nn.Module):def __init__(self, num_classes):
super(LeNet, self).__init__()
self.num_classes = num_classesself.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 xdef main():
config = load('conf.yaml')model = instantiate(config.model)
optimizer = instantiate(config.optimizer, model.parameters())if __name__ == '__main__':
main()
```