Skip to content

Commit

Permalink
Segmentation CI Hacks (#61)
Browse files Browse the repository at this point in the history
* Add Torch to setup reqs

Signed-off-by: Alex-Brooks <Alex.Brooks@ibm.com>

* Disable vit segmentation

Signed-off-by: Alex-Brooks <Alex.Brooks@ibm.com>

---------

Signed-off-by: Alex-Brooks <Alex.Brooks@ibm.com>
  • Loading branch information
alex-jw-brooks authored Jun 24, 2024
1 parent abd7b51 commit 77cfede
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 50 deletions.
2 changes: 1 addition & 1 deletion caikit_computer_vision/modules/segmentation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"""

# Local
from .models import ViTSegmenter
# from .models import ViTSegmenter
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ classifiers=[
dependencies = [
"caikit[runtime-grpc,runtime-http,interfaces-vision]>=0.26.5,<0.27.0",
"transformers>=4.27.1,<5",
"torch>2.0,<3",
"torch>=2.0,<3",
"timm>=0.9.5,<1",
"opencv-python>=4.9.0.80,<5",
"pycocotools>=2.0.7,<3",
"detectron2 @git+https://github.com/facebookresearch/detectron2.git@e70b9229d77aa39d85f8fa5266e6ea658e92eed3",
"shapely>=2.0.2,<3",
#"opencv-python>=4.9.0.80,<5",
#"pycocotools>=2.0.7,<3",
#"detectron2 @git+https://github.com/facebookresearch/detectron2.git@e70b9229d77aa39d85f8fa5266e6ea658e92eed3",
#"shapely>=2.0.2,<3",
]

[project.urls]
Expand Down
2 changes: 1 addition & 1 deletion setup_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
tox>=4.4.2,<5
build>=0.10.0,<2.0
build>=0.10.0,<2.0
15 changes: 8 additions & 7 deletions tests/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

# Local
from caikit_computer_vision.modules.object_detection import TransformersObjectDetector
from caikit_computer_vision.modules.segmentation import ViTSegmenter

# from caikit_computer_vision.modules.segmentation import ViTSegmenter

### Constants used in fixtures
FIXTURES_DIR = os.path.join(os.path.dirname(__file__))
TINY_MODELS_DIR = os.path.join(FIXTURES_DIR, "tiny_models")
TRANSFORMER_OBJ_DETECT_MODEL = os.path.join(TINY_MODELS_DIR, "YolosForObjectDetection")
SEMANTIC_SEGMENTATION_MODEL_DIR = os.path.join(TINY_MODELS_DIR, "ImageSegmentation")
SEGMENTATION_MODEL_CKPT = os.path.join(SEMANTIC_SEGMENTATION_MODEL_DIR, "model.pt")
# SEMANTIC_SEGMENTATION_MODEL_DIR = os.path.join(TINY_MODELS_DIR, "ImageSegmentation")
# SEGMENTATION_MODEL_CKPT = os.path.join(SEMANTIC_SEGMENTATION_MODEL_DIR, "model.pt")


@pytest.fixture
Expand All @@ -35,7 +36,7 @@ def detector_transformer_dummy_model():
return TransformersObjectDetector.bootstrap(TRANSFORMER_OBJ_DETECT_MODEL)


@pytest.fixture
def segmentation_dummy_model():
"""Load torch scripted model weights for ViT Segmentation"""
return ViTSegmenter.bootstrap(SEGMENTATION_MODEL_CKPT)
# @pytest.fixture
# def segmentation_dummy_model():
# """Load torch scripted model weights for ViT Segmentation"""
# return ViTSegmenter.bootstrap(SEGMENTATION_MODEL_CKPT)
72 changes: 36 additions & 36 deletions tests/modules/segmentation/test_segmentation_model.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
# Copyright The Caikit Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# # Copyright The Caikit Authors
# #
# # Licensed under the Apache License, Version 2.0 (the "License");
# # you may not use this file except in compliance with the License.
# # You may obtain a copy of the License at
# #
# # http://www.apache.org/licenses/LICENSE-2.0
# #
# # Unless required by applicable law or agreed to in writing, software
# # distributed under the License is distributed on an "AS IS" BASIS,
# # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# # See the License for the specific language governing permissions and
# # limitations under the License.

# Standard
import tempfile
# # Standard
# import tempfile

# Third Party
import numpy as np
# # Third Party
# import numpy as np

# Local
from caikit_computer_vision.data_model import ImageSegmentationResult
from caikit_computer_vision.modules.segmentation import ViTSegmenter
from tests.fixtures import SEGMENTATION_MODEL_CKPT
# # Local
# from caikit_computer_vision.data_model import ImageSegmentationResult
# from caikit_computer_vision.modules.segmentation import ViTSegmenter
# from tests.fixtures import SEGMENTATION_MODEL_CKPT


## Tests #######################################################################
def test_bootstrap_and_run():
"""Ensure that we can bootstrap a model & run inference on it."""
model = ViTSegmenter.bootstrap(SEGMENTATION_MODEL_CKPT)
assert isinstance(model, ViTSegmenter)
preds = model.run(np.ones((800, 800, 3), dtype=np.uint8))
assert isinstance(preds, ImageSegmentationResult)
# ## Tests #######################################################################
# def test_bootstrap_and_run():
# """Ensure that we can bootstrap a model & run inference on it."""
# model = ViTSegmenter.bootstrap(SEGMENTATION_MODEL_CKPT)
# assert isinstance(model, ViTSegmenter)
# preds = model.run(np.ones((800, 800, 3), dtype=np.uint8))
# assert isinstance(preds, ImageSegmentationResult)


def test_save_model_and_bootstrap():
"""Ensure that we can save a model and reload it."""
model = ViTSegmenter.bootstrap(SEGMENTATION_MODEL_CKPT)
with tempfile.TemporaryDirectory() as model_dir:
model.save(model_dir)
new_model = ViTSegmenter.load(model_dir)
preds = new_model.run(np.ones((800, 800, 3), dtype=np.uint8))
assert isinstance(preds, ImageSegmentationResult)
# def test_save_model_and_bootstrap():
# """Ensure that we can save a model and reload it."""
# model = ViTSegmenter.bootstrap(SEGMENTATION_MODEL_CKPT)
# with tempfile.TemporaryDirectory() as model_dir:
# model.save(model_dir)
# new_model = ViTSegmenter.load(model_dir)
# preds = new_model.run(np.ones((800, 800, 3), dtype=np.uint8))
# assert isinstance(preds, ImageSegmentationResult)

0 comments on commit 77cfede

Please sign in to comment.