Skip to main content

No project description provided

Project description

mlconfig

Installation

$ pip install mlconfig

Example

config.yaml

num_classes: 50

model:
  name: LeNet
  num_classes: ${num_classes}

optimizer:
  name: Adam
  lr: 1.e-3
  weight_decay: 1.e-4

main.py

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


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

mlconfig-0.2.3-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file mlconfig-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for mlconfig-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 536eec92c00566891a527ce18304665b7e87da10853f2d4bf62439c18c3a03b1
MD5 242c98a5436653e7bad43636b1595609
BLAKE2b-256 c69a64924fede77062b922511ea11f248f4d38d7694e954497eab0f8458c52dc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page