Skip to content

Commit

Permalink
functioning packaging and entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
ibro45 committed Aug 29, 2021
1 parent 84e4dea commit 352626a
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 86 deletions.
22 changes: 22 additions & 0 deletions ganslate/engines/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from ganslate.engines.trainer import Trainer
from ganslate.engines.validator_tester import Tester
from ganslate.engines.inferer import Inferer
from ganslate.utils import communication, environment
from ganslate.utils.builders import build_conf


ENGINES = {
'train': Trainer,
'test': Tester,
'infer': Inferer
}

def init_engine(mode):
assert mode in ENGINES.keys()

# inits distributed mode if ran with torch.distributed.launch
communication.init_distributed()
environment.setup_threading()

conf = build_conf()
return ENGINES[mode](conf)
11 changes: 8 additions & 3 deletions ganslate/utils/builders.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import sys
import torch
from torch.utils.data import DataLoader
from torch.utils.data.distributed import DistributedSampler
Expand All @@ -13,9 +14,13 @@


def build_conf():
cli = omegaconf.OmegaConf.from_cli()
conf = init_config(cli.pop("config"), config_class=Config)
return omegaconf.OmegaConf.merge(conf, cli)
cli = omegaconf.OmegaConf.from_dotlist(sys.argv[2:])

yaml_conf = cli.pop("config")
cli_conf_overrides = cli

conf = init_config(yaml_conf, config_class=Config)
return omegaconf.OmegaConf.merge(conf, cli_conf_overrides)


def build_loader(conf):
Expand Down
44 changes: 44 additions & 0 deletions ganslate/utils/interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sys
from ganslate.engines.utils import init_engine


def run_interface():
Interface().run()


class Interface:
def __init__(self):

self.COMMANDS = {
'help': self._help,
'train': self._train_test_infer,
'test': self._train_test_infer,
'infer': self._train_test_infer,
'new-project': self._new_project,
}
self.mode = sys.argv[1] if len(sys.argv) > 1 else 'help'

def _help(self):
# TODO: this is a temporary help. find what's the best convention and way to do it
msg = "\nGANSLATE COMMAND LIST\n\n"
msg += "help List all available commands and info on them.\n"
msg += "train Run training.\n"
msg += "test Test a trained model. Possible only with paired dataset.\n"
msg += "infer Perform inference with a trained model.\n"
msg += "new-project Generate a project template. Specify the name and the path where it should be generated\n"
sys.stdout.write(msg + "\n")

def _train_test_infer(self):
engine = init_engine(self.mode)
engine.run()

def _new_project(self):
raise NotImplementedError

def run(self):
if self.mode not in self.COMMANDS.keys():
sys.stderr.write(f"\nUnknown command `{self.mode}`\n")
self.mode = 'help'

command = self.COMMANDS[self.mode]
command()
62 changes: 62 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,65 @@
[metadata]
name = ganslate
version = 0.1.0
author = "ganslate team"
# author-email =
url = https://github.com/Maastro-CDS-Imaging-Group/ganslate
description = Add a short description here!
long-description = file: README.rst
long-description-content-type = text/markdown
license = mit
platforms = any
keywords = one, two
classifiers =
Development Status :: 2 - Pre-Alpha,
Intended Audience :: Science/Research,
Natural Language :: English,
Operating System :: OS Independent,
Programming Language :: Python :: 3.6,
Programming Language :: Python :: 3.7,
Programming Language :: Python :: 3.8,
Programming Language :: Python :: 3.9,
project-urls =
Documentation = https://ganslate.netlify.app/ # TODO: Update

[options]
zip_safe = False
packages = find:
include_package_data = True
#setup_requires =
# Add here dependencies of your project (semicolon/line-separated), e.g.
install_requires =
torch
opencv-python
simpleitk
opencv-python
memcnn
loguru
wandb
tensorboard

# The usage of test_requires is discouraged, see `Dependency Management` docs
# tests_require = pytest; pytest-cov
# Require a specific Python version, e.g. Python 2.7 or >= 3.4
# python_requires = >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*

[options.packages.find]
exclude =
tests

[options.extras_require]
# Add here additional requirements for extra features, to install with:
# `pip install clinical-evaluation[PDF]` like:
# PDF = ReportLab; RXP
# Add here test requirements (semicolon/line-separated)
testing =
pytest
pytest-cov

[options.entry_points]
console_scripts =
ganslate = ganslate.utils.interface:run_interface

[yapf]
based_on_style = google
column_limit = 100
Expand Down
13 changes: 13 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sys

from pkg_resources import VersionConflict, require
from setuptools import setup

try:
require('setuptools>=38.3')
except VersionConflict:
print("Error: version of setuptools is too old (<38.3)!")
sys.exit(1)

if __name__ == "__main__":
setup()
26 changes: 0 additions & 26 deletions tools/infer.py

This file was deleted.

29 changes: 0 additions & 29 deletions tools/test.py

This file was deleted.

28 changes: 0 additions & 28 deletions tools/train.py

This file was deleted.

0 comments on commit 352626a

Please sign in to comment.