JeanMaximilienCadic / ae

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


AE
AE

CodeHow To UseDockerPythonEnv

Configuration file:

project: ae

fs:
  data: "data"
  model_path: 'pth/conv_autoencoder.pth'

img:
  W: 400

trainer:
  bs: 16
  nsamples: 80

Main:

from ae import cfg, format_img
import numpy as np
from gnutools.fs import listfiles
from ae.trainers import Trainer
import torch
from ae.models import Autoencoder
from torch import nn


dataloader = [format_img(img) for img in listfiles(cfg.fs.data, [".png"])[:cfg.trainer.nsamples]]
dataloader = np.array(dataloader).reshape(-1,
                                          cfg.trainer.bs,
                                          1,
                                          cfg.img.W,
                                          cfg.img.W)
dataloader = torch.Tensor(dataloader)

trainer = Trainer(model=Autoencoder(),
                  epochs=cfg.trainer.epochs,
                  criterion=nn.MSELoss,
                  optimizer= torch.optim.Adam,
                  kwargs_optim={
                      "lr": cfg.trainer.lr,
                      "weight_decay": cfg.trainer.wdc
                  },
                  continue_from=cfg.fs.model_path
                  )
trainer(dataloader)
trainer.save(cfg.fs.model_path)

Code structure

from setuptools import setup
from ae import __version__

setup(
    name="ae",
    version=__version__,
    short_description="ae",
    long_description="ae",
    packages=[
        "ae",
        "ae.trainers",
        "ae.models",
    ],
    include_package_data=True,
    package_data={'': ['*.yml']},
    url='https://github.com/JeanMaximilienCadic/ae',
    license='CMJ',
    author='CADIC Jean-Maximilien',
    python_requires='>=3.8',
    install_requires=[r.rsplit()[0] for r in open("requirements.txt")],
    author_email='me@cadic.jp',
    description='ae',
    platforms="linux_debian_10_x86_64",
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
    ]
)

How to use

To clone and run this application, you'll need Git and https://docs.docker.com/docker-for-mac/install/ and Python installed on your computer. From your command line:

Install the ae:

# Clone this repository and install the code
git clone https://github.com/JeanMaximilienCadic/ae

# Go into the repository
cd ae

Docker

docker build . -t cadic/ae -f docker/Dockerfile
docker run --rm --name cadc_ae -it cadic/ae

PythonEnv

python setup.py install
python -m ae

About


Languages

Language:Python 98.0%Language:Dockerfile 1.7%Language:Shell 0.3%