Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pybio (bioimageio) submodules #164

Merged
merged 10 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ jobs:
. /opt/conda/etc/profile.d/conda.sh
conda activate tiktorch-server-env
./scripts/conda_build.sh conda-recipe-client
./scripts/conda_build.sh pybio-core-recipe
./scripts/conda_build.sh pybio-torch-recipe
./scripts/conda_build.sh bioimageio-core-recipe
./scripts/conda_build.sh bioimageio-torch-recipe
./scripts/conda_build.sh conda-recipe
./scripts/conda_build.sh conda-recipe-cpu

Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies:
- scikit-learn
- pip>=19
- pip:
- marshmallow_union
- tensorflow
- onnxruntime
- pytest-grpc==0.7.0
4 changes: 2 additions & 2 deletions pybio-core-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ requirements:

test:
imports:
- pybio.spec
- bioimageio.spec

about:
home: https://github.com/bioimage-io/python-bioimage-io
license: MIT
license_family: MIT
license_file: LICENSE
summary: 'Tools for parsing pybio model specification'
summary: 'Tools for parsing bioimageio model specification'

doc_url: https://github.com/bioimage-io/python-bioimage-io
dev_url: https://github.com/bioimage-io/python-bioimage-io
Expand Down
6 changes: 3 additions & 3 deletions pybio-torch-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ requirements:

test:
imports:
- pybio.torch
- pybio.torch.training
- bioimageio.torch
- bioimageio.torch.training

about:
home: https://github.com/bioimage-io/pytorch-bioimage-io
license: MIT
license_family: MIT
license_file: LICENSE
summary: 'Pytorch related components of pybio'
summary: 'Pytorch related components of bioimageio'

doc_url: https://github.com/bioimage-io/pytorch-bioimage-io
dev_url: https://github.com/bioimage-io/pytorch-bioimage-io
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"numpy",
"pyyaml",
"torch",
"pybio.core @ git+ssh://[email protected]/bioimage-io/python-bioimage-io#egg=pybio.core",
"pybio.torch @ git+ssh://[email protected]/bioimage-io/pytorch-bioimage-io#egg=pybio.torch",
"bioimageio.core @ git+ssh://[email protected]/bioimage-io/python-bioimage-io#egg=bioimageio.core",
"bioimageio.torch @ git+ssh://[email protected]/bioimage-io/pytorch-bioimage-io#egg=bioimageio.torch",
],
entry_points={"console_scripts": ["tiktorch=tiktorch.server.base:main"]},
# extras_require={"test": ["pytest"]},
Expand Down
69 changes: 32 additions & 37 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import pytest

TEST_DATA = "data"
TEST_PYBIO_ZIPFOLDER = "unet2d"
TEST_PYBIO_ONNX = "unet2d_onnx"
TEST_PYBIO_DUMMY = "dummy"
TEST_PYBIO_TENSORFLOW_DUMMY = "dummy_tensorflow"
TEST_PYBIO_TORCHSCRIPT = "unet2d_torchscript"
TEST_BIOIMAGEIO_ZIPFOLDER = "unet2d"
TEST_BIOIMAGEIO_ONNX = "unet2d_onnx"
TEST_BIOIMAGEIO_DUMMY = "dummy"
TEST_BIOIMAGEIO_TENSORFLOW_DUMMY = "dummy_tensorflow"
TEST_BIOIMAGEIO_TORCHSCRIPT = "unet2d_torchscript"

NNModel = namedtuple("NNModel", ["model", "state"])

Expand Down Expand Up @@ -82,8 +82,8 @@ def assert_threads_cleanup():


@pytest.fixture
def pybio_model_bytes(data_path):
zip_folder = data_path / TEST_PYBIO_ZIPFOLDER
def bioimageio_model_bytes(data_path):
zip_folder = data_path / TEST_BIOIMAGEIO_ZIPFOLDER
data = io.BytesIO()
with ZipFile(data, mode="w") as zip_model:
for f_path in zip_folder.iterdir():
Expand All @@ -97,18 +97,18 @@ def pybio_model_bytes(data_path):


@pytest.fixture
def pybio_model_zipfile(pybio_model_bytes):
with ZipFile(pybio_model_bytes, mode="r") as zf:
def bioimageio_model_zipfile(bioimageio_model_bytes):
with ZipFile(bioimageio_model_bytes, mode="r") as zf:
yield zf


@pytest.fixture
def pybio_dummy_model_filepath(data_path, tmpdir):
pybio_net_dir = Path(data_path) / TEST_PYBIO_DUMMY
def bioimageio_dummy_model_filepath(data_path, tmpdir):
bioimageio_net_dir = Path(data_path) / TEST_BIOIMAGEIO_DUMMY
path = tmpdir / "dummy_model.zip"

with ZipFile(path, mode="w") as zip_model:
for f_path in pybio_net_dir.iterdir():
for f_path in bioimageio_net_dir.iterdir():
if str(f_path.name).startswith("__"):
continue

Expand All @@ -119,11 +119,11 @@ def pybio_dummy_model_filepath(data_path, tmpdir):


@pytest.fixture
def pybio_dummy_model_bytes(data_path):
pybio_net_dir = Path(data_path) / TEST_PYBIO_DUMMY
def bioimageio_dummy_model_bytes(data_path):
bioimageio_net_dir = Path(data_path) / TEST_BIOIMAGEIO_DUMMY
data = io.BytesIO()
with ZipFile(data, mode="w") as zip_model:
for f_path in pybio_net_dir.iterdir():
for f_path in bioimageio_net_dir.iterdir():
if str(f_path.name).startswith("__"):
continue

Expand Down Expand Up @@ -156,22 +156,22 @@ def _archive(path_to_archive):


@pytest.fixture
def pybio_dummy_tensorflow_model_bytes(data_path):
pybio_net_dir = Path(data_path) / TEST_PYBIO_TENSORFLOW_DUMMY
return archive(pybio_net_dir)
def bioimageio_dummy_tensorflow_model_bytes(data_path):
bioimageio_net_dir = Path(data_path) / TEST_BIOIMAGEIO_TENSORFLOW_DUMMY
return archive(bioimageio_net_dir)


@pytest.fixture
def pybio_unet2d_onnx_bytes(data_path):
pybio_net_dir = Path(data_path) / TEST_PYBIO_ONNX
return archive(pybio_net_dir)
def bioimageio_unet2d_onnx_bytes(data_path):
bioimageio_net_dir = Path(data_path) / TEST_BIOIMAGEIO_ONNX
return archive(bioimageio_net_dir)


@pytest.fixture
def pybio_unet2d_onnx_test_data(data_path):
pybio_net_dir = Path(data_path) / TEST_PYBIO_ONNX
test_input = pybio_net_dir / "test_input.npy"
test_output = pybio_net_dir / "test_output.npy"
def bioimageio_unet2d_onnx_test_data(data_path):
bioimageio_net_dir = Path(data_path) / TEST_BIOIMAGEIO_ONNX
test_input = bioimageio_net_dir / "test_input.npy"
test_output = bioimageio_net_dir / "test_output.npy"
return {"test_input": test_input, "test_output": test_output}


Expand All @@ -184,19 +184,14 @@ def npy_zeros_file(tmpdir):


@pytest.fixture
def pybio_unet2d_torchscript_bytes(data_path):
pybio_net_dir = Path(data_path) / TEST_PYBIO_TORCHSCRIPT
return archive(pybio_net_dir)
def bioimageio_unet2d_torchscript_bytes(data_path):
bioimageio_net_dir = Path(data_path) / TEST_BIOIMAGEIO_TORCHSCRIPT
return archive(bioimageio_net_dir)


@pytest.fixture
def pybio_unet2d_torchscript_test_data(data_path):
pybio_net_dir = Path(data_path) / TEST_PYBIO_TORCHSCRIPT
test_input = pybio_net_dir / "test_input.npy"
test_output = pybio_net_dir / "test_output.npy"
def bioimageio_unet2d_torchscript_test_data(data_path):
bioimageio_net_dir = Path(data_path) / TEST_BIOIMAGEIO_TORCHSCRIPT
test_input = bioimageio_net_dir / "test_input.npy"
test_output = bioimageio_net_dir / "test_output.npy"
return {"test_input": test_input, "test_output": test_output}


@pytest.fixture
def cache_path(tmp_path):
return Path(getenv("PYBIO_CACHE_PATH", tmp_path))
2 changes: 1 addition & 1 deletion tests/data/unet2d_onnx/UNet2DNucleiBroad.model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ outputs:

language: python
framework: pytorch
source: pybio.torch.models.unet2d.UNet2d
source: bioimageio.torch.models.unet2d.UNet2d
kwargs: {input_channels: 1, output_channels: 1}
dependencies: conda:../environment.yaml

Expand Down
2 changes: 1 addition & 1 deletion tests/data/unet2d_torchscript/UNet2DNucleiBroad.model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ outputs:

language: python
framework: pytorch
source: pybio.torch.models.unet2d.UNet2d
source: bioimageio.torch.models.unet2d.UNet2d
kwargs: {input_channels: 1, output_channels: 1}
dependencies: conda:../environment.yaml

Expand Down
Binary file modified tests/data/unet2d_torchscript/weights.pt
Binary file not shown.
30 changes: 15 additions & 15 deletions tests/test_server/test_grpc/test_inference_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ def method_requiring_session(self, request, grpc_stub):
method_name, req = request.param
return getattr(grpc_stub, method_name), req

def test_model_session_creation(self, grpc_stub, pybio_model_bytes):
model = grpc_stub.CreateModelSession(valid_model_request(pybio_model_bytes))
def test_model_session_creation(self, grpc_stub, bioimageio_model_bytes):
model = grpc_stub.CreateModelSession(valid_model_request(bioimageio_model_bytes))
assert model.id
grpc_stub.CloseModelSession(model)

def test_model_session_creation_using_upload_id(self, grpc_stub, data_store, pybio_dummy_model_bytes):
id_ = data_store.put(pybio_dummy_model_bytes.getvalue())
def test_model_session_creation_using_upload_id(self, grpc_stub, data_store, bioimageio_dummy_model_bytes):
id_ = data_store.put(bioimageio_dummy_model_bytes.getvalue())

rq = inference_pb2.CreateModelSessionRequest(model_uri=f"upload://{id_}", deviceIds=["cpu"])
model = grpc_stub.CreateModelSession(rq)
Expand Down Expand Up @@ -103,28 +103,28 @@ def test_if_model_create_fails_devices_are_released(self, grpc_stub):
if model:
grpc_stub.CloseModelSession(model)

def test_use_device(self, grpc_stub, pybio_model_bytes):
def test_use_device(self, grpc_stub, bioimageio_model_bytes):
device_by_id = self._query_devices(grpc_stub)
assert "cpu" in device_by_id
assert inference_pb2.Device.Status.AVAILABLE == device_by_id["cpu"].status

model = grpc_stub.CreateModelSession(valid_model_request(pybio_model_bytes, device_ids=["cpu"]))
model = grpc_stub.CreateModelSession(valid_model_request(bioimageio_model_bytes, device_ids=["cpu"]))

device_by_id = self._query_devices(grpc_stub)
assert "cpu" in device_by_id
assert inference_pb2.Device.Status.IN_USE == device_by_id["cpu"].status

grpc_stub.CloseModelSession(model)

def test_using_same_device_fails(self, grpc_stub, pybio_model_bytes):
model = grpc_stub.CreateModelSession(valid_model_request(pybio_model_bytes, device_ids=["cpu"]))
def test_using_same_device_fails(self, grpc_stub, bioimageio_model_bytes):
model = grpc_stub.CreateModelSession(valid_model_request(bioimageio_model_bytes, device_ids=["cpu"]))
with pytest.raises(grpc.RpcError):
model = grpc_stub.CreateModelSession(valid_model_request(pybio_model_bytes, device_ids=["cpu"]))
model = grpc_stub.CreateModelSession(valid_model_request(bioimageio_model_bytes, device_ids=["cpu"]))

grpc_stub.CloseModelSession(model)

def test_closing_session_releases_devices(self, grpc_stub, pybio_model_bytes):
model = grpc_stub.CreateModelSession(valid_model_request(pybio_model_bytes, device_ids=["cpu"]))
def test_closing_session_releases_devices(self, grpc_stub, bioimageio_model_bytes):
model = grpc_stub.CreateModelSession(valid_model_request(bioimageio_model_bytes, device_ids=["cpu"]))

device_by_id = self._query_devices(grpc_stub)
assert "cpu" in device_by_id
Expand All @@ -138,8 +138,8 @@ def test_closing_session_releases_devices(self, grpc_stub, pybio_model_bytes):


class TestGetLogs:
def test_returns_ack_message(self, pybio_model_bytes, grpc_stub):
model = grpc_stub.CreateModelSession(valid_model_request(pybio_model_bytes))
def test_returns_ack_message(self, bioimageio_model_bytes, grpc_stub):
model = grpc_stub.CreateModelSession(valid_model_request(bioimageio_model_bytes))
resp = grpc_stub.GetLogs(inference_pb2.Empty())
record = next(resp)
assert inference_pb2.LogEntry.Level.INFO == record.level
Expand All @@ -154,8 +154,8 @@ def test_call_fails_with_unknown_model_session_id(self, grpc_stub):
assert grpc.StatusCode.FAILED_PRECONDITION == e.value.code()
assert "model-session with id myid1 doesn't exist" in e.value.details()

def test_call_predict(self, grpc_stub, pybio_dummy_model_bytes):
model = grpc_stub.CreateModelSession(valid_model_request(pybio_dummy_model_bytes))
def test_call_predict(self, grpc_stub, bioimageio_dummy_model_bytes):
model = grpc_stub.CreateModelSession(valid_model_request(bioimageio_dummy_model_bytes))

arr = xr.DataArray(np.arange(32 * 32).reshape(1, 32, 32), dims=("c", "x", "y"))
expected = arr + 1
Expand Down
16 changes: 8 additions & 8 deletions tests/test_server/test_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def npy_zeros_file(tmpdir):
return path


def test_running_predict_with_valid_arguments(testdir, pybio_dummy_model_filepath, npy_zeros_file, output_path):
def test_running_predict_with_valid_arguments(testdir, bioimageio_dummy_model_filepath, npy_zeros_file, output_path):
result = testdir.run(
"python",
"-m",
"tiktorch.server.predict",
"--model",
pybio_dummy_model_filepath,
bioimageio_dummy_model_filepath,
npy_zeros_file,
"--output",
output_path,
Expand All @@ -41,20 +41,20 @@ def test_running_predict_fails_when_model_unspecified(testdir, npy_zeros_file, o
assert result.ret != 0


def test_running_predict_fails_when_no_images_specified(testdir, pybio_dummy_model_filepath, output_path):
def test_running_predict_fails_when_no_images_specified(testdir, bioimageio_dummy_model_filepath, output_path):
result = testdir.run(
"python", "-m", "tiktorch.server.predict", "--model", pybio_dummy_model_filepath, "--output", output_path
"python", "-m", "tiktorch.server.predict", "--model", bioimageio_dummy_model_filepath, "--output", output_path
)
assert result.ret != 0


def test_running_predict_fails_when_invalid_image_specified(testdir, pybio_dummy_model_filepath, output_path):
def test_running_predict_fails_when_invalid_image_specified(testdir, bioimageio_dummy_model_filepath, output_path):
result = testdir.run(
"python",
"-m",
"tiktorch.server.predict",
"--model",
pybio_dummy_model_filepath,
bioimageio_dummy_model_filepath,
"nonexisting",
"--output",
output_path,
Expand All @@ -77,9 +77,9 @@ def test_running_predict_fails_without_when_model_file_does_not_exist(testdir, t


def test_running_predict_failes_when_output_is_unspecified(
testdir, pybio_dummy_model_filepath, npy_zeros_file, output_path
testdir, bioimageio_dummy_model_filepath, npy_zeros_file, output_path
):
result = testdir.run(
"python", "-m", "tiktorch.server.predict", "--model", pybio_dummy_model_filepath, npy_zeros_file
"python", "-m", "tiktorch.server.predict", "--model", bioimageio_dummy_model_filepath, npy_zeros_file
)
assert result.ret != 0
Loading