From 3e4c4b1e7280e0ff9e1b797a65967da98a5af84b Mon Sep 17 00:00:00 2001 From: numb3r3 Date: Mon, 21 Feb 2022 12:13:55 +0800 Subject: [PATCH 1/3] refactor: change folder --- __init__.py | 1 - executor/__init__.py | 1 + executor.py => executor/encoder.py | 2 +- {models => executor/models}/__init__.py | 0 {models => executor/models}/modeling.py | 0 {models => executor/models}/modules.py | 0 {models => executor/models}/pointconv.py | 0 {models => executor/models}/pointnet.py | 0 {models => executor/models}/pooling.py | 0 finetune.py | 2 +- tests/__init__.py | 0 tests/integration/__init__.py | 0 tests/integration/test_encoder.py | 24 ++++++++++++++++++++++++ tests/requirements.txt | 1 + tests/unit/__init__.py | 0 tests/unit/test_exec.py | 17 +++++++++++++++++ 16 files changed, 45 insertions(+), 3 deletions(-) delete mode 100644 __init__.py create mode 100644 executor/__init__.py rename executor.py => executor/encoder.py (98%) rename {models => executor/models}/__init__.py (100%) rename {models => executor/models}/modeling.py (100%) rename {models => executor/models}/modules.py (100%) rename {models => executor/models}/pointconv.py (100%) rename {models => executor/models}/pointnet.py (100%) rename {models => executor/models}/pooling.py (100%) create mode 100644 tests/__init__.py create mode 100644 tests/integration/__init__.py create mode 100644 tests/integration/test_encoder.py create mode 100644 tests/requirements.txt create mode 100644 tests/unit/__init__.py create mode 100644 tests/unit/test_exec.py diff --git a/__init__.py b/__init__.py deleted file mode 100644 index 9fce56c..0000000 --- a/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .executor import MeshDataEncoder diff --git a/executor/__init__.py b/executor/__init__.py new file mode 100644 index 0000000..ad88062 --- /dev/null +++ b/executor/__init__.py @@ -0,0 +1 @@ +from .encoder import MeshDataEncoder diff --git a/executor.py b/executor/encoder.py similarity index 98% rename from executor.py rename to executor/encoder.py index 93ca2a5..b8bd550 100644 --- a/executor.py +++ b/executor/encoder.py @@ -7,7 +7,7 @@ import torch from jina import Document, DocumentArray, Executor, requests -from .models import MeshDataModel +from executor.models import MeshDataModel AVAILABLE_MODELS = { 'PointNet-Shapenet-d1024': { diff --git a/models/__init__.py b/executor/models/__init__.py similarity index 100% rename from models/__init__.py rename to executor/models/__init__.py diff --git a/models/modeling.py b/executor/models/modeling.py similarity index 100% rename from models/modeling.py rename to executor/models/modeling.py diff --git a/models/modules.py b/executor/models/modules.py similarity index 100% rename from models/modules.py rename to executor/models/modules.py diff --git a/models/pointconv.py b/executor/models/pointconv.py similarity index 100% rename from models/pointconv.py rename to executor/models/pointconv.py diff --git a/models/pointnet.py b/executor/models/pointnet.py similarity index 100% rename from models/pointnet.py rename to executor/models/pointnet.py diff --git a/models/pooling.py b/executor/models/pooling.py similarity index 100% rename from models/pooling.py rename to executor/models/pooling.py diff --git a/finetune.py b/finetune.py index f65c751..4e609e6 100644 --- a/finetune.py +++ b/finetune.py @@ -13,7 +13,7 @@ from finetuner.tuner.pytorch.miner import TripletEasyHardMiner from jina import Document, DocumentArray -from models import MeshDataModel +from executor.models import MeshDataModel def random_sample(pc, num): diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/integration/test_encoder.py b/tests/integration/test_encoder.py new file mode 100644 index 0000000..9700d5c --- /dev/null +++ b/tests/integration/test_encoder.py @@ -0,0 +1,24 @@ +import numpy as np +import pytest +from jina import DocumentArray, Flow + +from executor import MeshDataEncoder + + +@pytest.mark.parametrize('model_name', ['pointconv', 'pointnet']) +def test_integration(model_name: str): + docs = DocumentArray.empty(5) + docs.tensors = np.random.random((5, 1024, 3)) + with Flow(return_results=True).add( + uses=MeshDataEncoder, + uses_with={'pretrained_model': None, 'default_model_name': model_name}, + ) as flow: + resp = flow.post( + on='/index', + inputs=docs, + return_results=True, + ) + + for doc in resp: + assert doc.embedding is not None + assert doc.embedding.shape == (1024,) diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 0000000..e079f8a --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1 @@ +pytest diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/test_exec.py b/tests/unit/test_exec.py new file mode 100644 index 0000000..249697a --- /dev/null +++ b/tests/unit/test_exec.py @@ -0,0 +1,17 @@ +import numpy as np +import pytest +from jina import Document, DocumentArray + +from executor import MeshDataEncoder + + +@pytest.mark.parametrize('model_name', ['pointconv', 'pointnet']) +def test_encoder(model_name): + encoder = MeshDataEncoder(pretrained_model=None, default_model_name=model_name) + + docs = DocumentArray(Document(tensor=np.random.random((1024, 3)))) + + encoder.encode(docs) + + assert docs[0].embedding is not None + assert docs[0].embedding.shape == (1024,) From 2949140017c19fe75c301523a0fb743e0acc3c86 Mon Sep 17 00:00:00 2001 From: numb3r3 Date: Mon, 21 Feb 2022 12:19:39 +0800 Subject: [PATCH 2/3] fix: config.yml --- config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.yml b/config.yml index f44e3c2..b3164ad 100644 --- a/config.yml +++ b/config.yml @@ -1,4 +1,4 @@ jtype: MeshDataEncoder metas: py_modules: - - __init__.py + - executor/__init__.py From 8455681268266d9fc6883fe07cdc553c54456a5d Mon Sep 17 00:00:00 2001 From: numb3r3 Date: Mon, 21 Feb 2022 12:23:51 +0800 Subject: [PATCH 3/3] fix: import --- executor/encoder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/encoder.py b/executor/encoder.py index b8bd550..93ca2a5 100644 --- a/executor/encoder.py +++ b/executor/encoder.py @@ -7,7 +7,7 @@ import torch from jina import Document, DocumentArray, Executor, requests -from executor.models import MeshDataModel +from .models import MeshDataModel AVAILABLE_MODELS = { 'PointNet-Shapenet-d1024': {