From 491692f86a50299f5996312ba09fb36b5e9e1d85 Mon Sep 17 00:00:00 2001 From: jsun Date: Tue, 6 Aug 2024 15:17:09 +0900 Subject: [PATCH] [clean] clean up scripts. --- pyproject.toml | 8 +++---- src/cvtk/__init__.py | 2 +- src/cvtk/tmpl/_ls_backend.py | 2 +- src/cvtk/tmpl/_mmdet.py | 2 +- tests/test_ls.py | 41 +++++++++++++++++++++++++++++++++++- 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7bc2777..be236a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,10 +54,10 @@ docs = [ 'cvtk[full]', 'sphinx-rtd-theme', 'sphinxcontrib-napoleon', - 'numpy == 1.26.3', - 'torch == 2.1.0', - 'mmcv == 2.1.0', - 'mmdet == 3.3.0', + 'numpy', + 'torch', + 'mmcv', + 'mmdet', ] diff --git a/src/cvtk/__init__.py b/src/cvtk/__init__.py index 820e72b..535ea50 100644 --- a/src/cvtk/__init__.py +++ b/src/cvtk/__init__.py @@ -1,4 +1,4 @@ -__version__ = '0.2.12' +__version__ = '0.2.13' from ._base import imread, imconvert, imwrite, imshow, imlist, imresize from ._base import Annotation, Image, ImageDeck, JsonComplexEncoder diff --git a/src/cvtk/tmpl/_ls_backend.py b/src/cvtk/tmpl/_ls_backend.py index 676aed2..36224ec 100644 --- a/src/cvtk/tmpl/_ls_backend.py +++ b/src/cvtk/tmpl/_ls_backend.py @@ -104,6 +104,6 @@ def __convert(self, im): """ Example: -uvicorn main:app --host 0.0.0.0 --port 8080 --reload +gunicorn --bind 0.0.0.0:8600 main:app --reload """ diff --git a/src/cvtk/tmpl/_mmdet.py b/src/cvtk/tmpl/_mmdet.py index 284d47d..1837bff 100644 --- a/src/cvtk/tmpl/_mmdet.py +++ b/src/cvtk/tmpl/_mmdet.py @@ -36,7 +36,7 @@ def train(label, train, valid, test, output_weights, batch_size=2, num_workers=8 output=os.path.splitext(output_weights)[0] + '.train_stats.valid.png') -def inference(label, data, model_weights, output, batch_size=4, num_workers=8): +def inference(label, data, model_weights, output, batch_size=2, num_workers=8): datalabel = DataLabel(label) model = MMDETCORE(datalabel, os.path.splitext(model_weights)[0] + '.py', model_weights, workspace=output) diff --git a/tests/test_ls.py b/tests/test_ls.py index 6efbcc8..cb183b3 100644 --- a/tests/test_ls.py +++ b/tests/test_ls.py @@ -3,10 +3,13 @@ import requests import PIL import cvtk.ls +import cvtk.ml +import pathlib import unittest import testutils + def get_app_status(url): print(f'Checking App Server ({url}) Status... ') try: @@ -30,7 +33,22 @@ def test_exprot(self, host='http://localhost', port=8080): output=os.path.join(self.ws, 'instances.coco.json'), format='coco', host=host, port=port) - + + def test_generate_app(self): + with open(os.path.join(self.ws, 'sample_label.txt'), 'w'): + pass + with open(os.path.join(self.ws, 'model.pth'), 'w'): + pass + with open(os.path.join(self.ws, 'model.py'), 'w'): + pass + + + cvtk.ml.generate_source(os.path.join(self.ws, 'det.py'), task='det') + cvtk.ls.generate_app(os.path.join(self.ws, 'lsbackend'), + source=os.path.join(self.ws, 'det.py'), + label=os.path.join(self.ws, 'sample_label.txt'), + model=os.path.join(self.ws, 'model.py'), + weights=os.path.join(self.ws, 'model.pth')) class TestScritpUtils(unittest.TestCase): @@ -48,6 +66,27 @@ def test_export(self, host='http://localhost', port=8080): '--host', host, '--port', port]) + def test_generate_app(self): + with open(os.path.join(self.ws, 'sample_label.txt'), 'w'): + pass + with open(os.path.join(self.ws, 'model.pth'), 'w'): + pass + with open(os.path.join(self.ws, 'model.py'), 'w'): + pass + + testutils.run_cmd(['cvtk', 'create', + '--task', 'det', + '--script', os.path.join(self.ws, 'det.py')]) + + testutils.run_cmd(['cvtk', 'ls-backend', + '--project', os.path.join(self.ws, 'lsbackend'), + '--source', os.path.join(self.ws, 'det.py'), + '--label', os.path.join(self.ws, 'sample_label.txt'), + '--model', os.path.join(self.ws, 'model.py'), + '--weights', os.path.join(self.ws, 'model.pth')]) + + + if __name__ == '__main__':