diff --git a/.github/workflows/ISSUE_TEMPLATE/bug_report.md b/.github/workflows/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..fd5d2ec --- /dev/null +++ b/.github/workflows/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,34 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "" +labels: "" +assignees: "" +--- + +## Describe the bug + +A clear and concise description of what the bug is. + +## Platform + +Please provide details about the environment you are using, including the following: + +- Interpreter version: +- Library version: + +## Sample Code + +Please include a minimal sample of the code that will (if possible) reproduce the bug in isolation + +## Expected behavior + +A clear and concise description of what you expected to happen. + +## Observed behavior + +What you see happening (error messages, stack traces, etc...) + +## Additional context + +Add any other context about the problem here. diff --git a/.github/workflows/ISSUE_TEMPLATE/feature_request.md b/.github/workflows/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..06839ed --- /dev/null +++ b/.github/workflows/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,23 @@ +- name: Feature request + about: Suggest an idea for this project + title: "" + labels: "" + assignees: "" + + *** + + ## Is your feature request related to a problem? Please describe. + + A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + + ## Describe the solution you'd like + + A clear and concise description of what you want to happen. + + ## Describe alternatives you've considered + + A clear and concise description of any alternative solutions or features you've considered. + + ## Additional context + + Add any other context about the feature request here. diff --git a/.github/workflows/ISSUE_TEMPLATE/user_story.md b/.github/workflows/ISSUE_TEMPLATE/user_story.md new file mode 100644 index 0000000..bf8501f --- /dev/null +++ b/.github/workflows/ISSUE_TEMPLATE/user_story.md @@ -0,0 +1,24 @@ +--- +name: User story +about: A user-oriented story describing a piece of work to do +title: "" +labels: "" +assignees: "" +--- + +## Description + +As a , I want to , so that I can + +## Discussion + +Provide detailed discussion here + +## Acceptance Criteria + + + +- [ ] Unit tests cover new/changed code +- [ ] Examples build against new/changed code +- [ ] READMEs are updated +- [ ] Type of [semantic version](https://semver.org/) change is identified diff --git a/.github/workflows/build-library.yml b/.github/workflows/build-library.yml new file mode 100644 index 0000000..92ede6d --- /dev/null +++ b/.github/workflows/build-library.yml @@ -0,0 +1,45 @@ +# 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. + +name: Build Caikit Computer Vision Library + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: + - setup: "3.9" + tox: "py39" + - setup: "3.10" + tox: "py310" + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version.setup }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version.setup }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -r setup_requirements.txt + - name: Build and test with tox + run: tox -e ${{ matrix.python-version.tox }} diff --git a/.github/workflows/lint-code.yml b/.github/workflows/lint-code.yml new file mode 100644 index 0000000..df94322 --- /dev/null +++ b/.github/workflows/lint-code.yml @@ -0,0 +1,39 @@ +# 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. + +name: Lint and Format + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.9 + uses: actions/setup-python@v4 + with: + python-version: 3.9 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -r setup_requirements.txt + - name: Check Formatting + run: tox -e fmt + - name: Run pylint + run: tox -e lint diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000..e03f138 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,10 @@ +[settings] +profile=black +from_first=true +import_heading_future=Future +import_heading_stdlib=Standard +import_heading_thirdparty=Third Party +import_heading_firstparty=First Party +import_heading_localfolder=Local +known_firstparty=alog,aconfig,caikit,import_tracker +known_localfolder=caikit_computer_vision,tests \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..c26b962 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,15 @@ +repos: + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.1.2 + hooks: + - id: prettier + - repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black + exclude: imports + - repo: https://github.com/PyCQA/isort + rev: 5.11.5 + hooks: + - id: isort + exclude: imports diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..c4666f7 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,125 @@ +# Contributing + +๐Ÿ‘๐ŸŽ‰ First off, thank you for taking the time to contribute! ๐ŸŽ‰๐Ÿ‘ + +The following is a set of guidelines for contributing. These are just guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request. Please read the [community contribution guide](https://github.com/caikit/community/blob/main/CONTRIBUTING.md) first for general practices for the Caikit community. + +## What Should I Know Before I Get Started? + +### Code of Conduct + +This project adheres to the [Contributor Covenant](./code-of-conduct.md). By participating, you are expected to uphold this code. + +Please report unacceptable behavior to one of the [Code Owners](./CODEOWNERS). + +### How Do I Start Contributing? + +The below workflow is designed to help you begin your first contribution journey. It will guide you through creating and picking up issues, working through them, having your work reviewed, and then merging. + +Help on open source projects is always welcome and there is always something that can be improved. For example, documentation (like the text you are reading now) can always use improvement, code can always be clarified, variables or functions can always be renamed or commented on, and there is always a need for more test coverage. If you see something that you think should be fixed, take ownership! Here is how you get started: + +## How Can I Contribute? + +When contributing, it's useful to start by looking at [issues](https://github.com/caikit/caikit-computer-vision/issues). After picking up an issue, writing code, or updating a document, make a pull request and your work will be reviewed and merged. If you're adding a new feature or find a bug, it's best to [write an issue](https://github.com/caikit/caikit-computer-vision/issues/new?assignees=&labels=&template=feature_request.md&title=) first to discuss it with maintainers. + +To contribute to this repo, you'll use the Fork and Pull model common in many open source repositories. For details on this process, check out [The GitHub Workflow +Guide](https://github.com/kubernetes/community/blob/master/contributors/guide/github-workflow.md) +from Kubernetes. + +When your contribution is ready, you can create a pull request. Pull requests are often referred to as "PR". In general, we follow the standard [GitHub pull request](https://help.github.com/en/articles/about-pull-requests) process. Follow the template to provide details about your pull request to the maintainers. + +Before sending pull requests, make sure your changes pass formatting, linting and unit tests. + +#### Code Review + +Once you've [created a pull request](#how-can-i-contribute), maintainers will review your code and may make suggestions to fix before merging. It will be easier for your pull request to receive reviews if you consider the criteria the reviewers follow while working. Remember to: + +- Run tests locally and ensure they pass +- Follow the project coding conventions +- Write detailed commit messages +- Break large changes into a logical series of smaller patches, which are easy to understand individually and combine to solve a broader issue + +### Reporting Bugs + +This section guides you through submitting a bug report. Following these guidelines helps maintainers and the community understand your report โœ๏ธ, reproduce the behavior ๐Ÿ’ป, and find related reports ๐Ÿ”Ž. + +#### How Do I Submit A (Good) Bug Report? + +Bugs are tracked as [GitHub issues using the Bug Report template](https://github.com/caikit/caikit-computer-vision/issues/new?assignees=&labels=&template=bug_report.md&title=). Create an issue on that and provide the information suggested in the bug report issue template. + +### Suggesting Enhancements + +This section guides you through submitting an enhancement suggestion, including completely new features, tools, and minor improvements to existing functionality. Following these guidelines helps maintainers and the community understand your suggestion โœ๏ธ and find related suggestions ๐Ÿ”Ž + +#### How Do I Submit A (Good) Enhancement Suggestion? + +Enhancement suggestions are tracked as [GitHub issues using the Feature Request template](https://github.com/caikit/caikit-computer-vision/issues/new?assignees=&labels=&template=feature_request.md&title=). Create an issue and provide the information suggested in the feature requests or user story issue template. + +#### How Do I Submit A (Good) Improvement Item? + +Improvements to existing functionality are tracked as [GitHub issues using the User Story template](https://github.com/caikit/caikit-computer-vision/issues/new?assignees=&labels=&template=user_story.md&title=). Create an issue and provide the information suggested in the feature requests or user story issue template. + +## Development + +### Set up your dev environment + +The following tools are required: + +- [git](https://git-scm.com) +- [python](https://www.python.org) (v3.8+) +- [pip](https://pypi.org/project/pip/) (v23.0+) + +You can setup your dev environment using [tox](https://tox.wiki/en/latest/), an environment orchestrator which allows for setting up environments for and invoking builds, unit tests, formatting, linting, etc. Install tox with: + +```sh +pip install -r setup_requirements.txt +``` + +If you want to manage your own virtual environment instead of using `tox`, you can install `caikit` and all dependencies with: + +```sh +pip install . +``` + +### Unit tests + +Unit tests are enforced by the CI system. When making changes, run the tests before pushing the changes to avoid CI issues. + +Running unit tests against all supported Python versions is as simple as: + +```sh +tox +``` + +Running tests against a single Python version can be done with: + +```sh +tox -e py +``` + +### Coding style + +Caikit follows the python [pep8](https://peps.python.org/pep-0008/) coding style. The coding style is enforced by the CI system, and your PR will fail until the style has been applied correctly. + +We use [pre-commit](https://pre-commit.com/) to enforce coding style using [black](https://github.com/psf/black), [prettier](https://github.com/prettier/prettier) and [isort](https://pycqa.github.io/isort/). + +You can invoke formatting with: + +```sh +tox -e fmt +``` + +In addition, we use [pylint](https://www.pylint.org) to perform static code analysis of the code. + +You can invoke the linting with the following command + +```sh +tox -e lint +``` + +## Your First Code Contribution + +Unsure where to begin contributing? You can start by looking through these issues: + +- Issues with the [`good first issue` label](https://github.com/caikit/caikit-computer-vision/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) - these should only require a few lines of code and are good targets if you're just starting contributing. +- Issues with the [`help wanted` label](https://github.com/caikit/caikit-computer-vision/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) - these range from simple to more complex, but are generally things we want but can't get to in a short time frame. diff --git a/caikit_computer_vision/__init__.py b/caikit_computer_vision/__init__.py index 2e9a01f..9c2eb45 100644 --- a/caikit_computer_vision/__init__.py +++ b/caikit_computer_vision/__init__.py @@ -15,11 +15,14 @@ # Standard import os -# Local +# First Party import caikit +# Local from . import data_model, modules # Give the path to the `config.yml` -CONFIG_PATH = os.path.realpath(os.path.join(os.path.dirname(__file__), "config", "config.yml")) +CONFIG_PATH = os.path.realpath( + os.path.join(os.path.dirname(__file__), "config", "config.yml") +) caikit.configure(CONFIG_PATH) diff --git a/caikit_computer_vision/config/config.yml b/caikit_computer_vision/config/config.yml index 63fb302..ca08e5c 100644 --- a/caikit_computer_vision/config/config.yml +++ b/caikit_computer_vision/config/config.yml @@ -1,4 +1,3 @@ - # Copyright The Caikit Authors # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,5 +14,5 @@ # Caikit model configuration runtime: - # Package name containing the model wrapping + # Package name containing the model wrapping library: caikit_computer_vision diff --git a/caikit_computer_vision/data_model/__init__.py b/caikit_computer_vision/data_model/__init__.py index 55e23e3..ac4effe 100644 --- a/caikit_computer_vision/data_model/__init__.py +++ b/caikit_computer_vision/data_model/__init__.py @@ -13,10 +13,6 @@ # limitations under the License. # Local -from . import image_classification +from . import image_classification, object_detection, tasks from .image_classification import * - -from . import object_detection from .object_detection import * - -from . import tasks diff --git a/caikit_computer_vision/data_model/image_classification.py b/caikit_computer_vision/data_model/image_classification.py index cbf516d..52aaca2 100644 --- a/caikit_computer_vision/data_model/image_classification.py +++ b/caikit_computer_vision/data_model/image_classification.py @@ -13,22 +13,24 @@ # limitations under the License. """Data structures for classification in images.""" -# First Party +# Third Party from py_to_proto.dataclass_to_proto import Annotated, FieldNumber -import alog -# Local +# First Party from caikit.core import DataObjectBase, dataobject from caikit.interfaces.common.data_model import ProducerId +import alog log = alog.use_channel("DATAM") + @dataobject(package="caikit_data_model.caikit_computer_vision") class ImageClassification(DataObjectBase): label: Annotated[str, FieldNumber(1)] score: Annotated[float, FieldNumber(2)] + @dataobject(package="caikit_data_model.caikit_computer_vision") class ImageClassificationResult(DataObjectBase): classifications: Annotated[list[ImageClassification], FieldNumber(1)] - producer_id: Annotated[ProducerId, FieldNumber(2)] \ No newline at end of file + producer_id: Annotated[ProducerId, FieldNumber(2)] diff --git a/caikit_computer_vision/data_model/object_detection.py b/caikit_computer_vision/data_model/object_detection.py index 1c75fb7..9f2d7a3 100644 --- a/caikit_computer_vision/data_model/object_detection.py +++ b/caikit_computer_vision/data_model/object_detection.py @@ -13,16 +13,17 @@ # limitations under the License. """Data structures for text object detection in images.""" -# First Party +# Third Party from py_to_proto.dataclass_to_proto import Annotated, FieldNumber -import alog -# Local +# First Party from caikit.core import DataObjectBase, dataobject from caikit.interfaces.common.data_model import ProducerId +import alog log = alog.use_channel("DATAM") + @dataobject(package="caikit_data_model.caikit_computer_vision") class BoundingBox(DataObjectBase): xmin: Annotated[int, FieldNumber(1)] @@ -30,12 +31,14 @@ class BoundingBox(DataObjectBase): ymin: Annotated[int, FieldNumber(3)] ymax: Annotated[int, FieldNumber(4)] + @dataobject(package="caikit_data_model.caikit_computer_vision") class DetectedObject(DataObjectBase): score: Annotated[float, FieldNumber(1)] label: Annotated[str, FieldNumber(2)] box: Annotated[BoundingBox, FieldNumber(3)] + @dataobject(package="caikit_data_model.caikit_computer_vision") class ObjectDetectionResult(DataObjectBase): detected_objects: Annotated[list[BoundingBox], FieldNumber(1)] diff --git a/caikit_computer_vision/data_model/tasks.py b/caikit_computer_vision/data_model/tasks.py index 147116b..d1236a1 100644 --- a/caikit_computer_vision/data_model/tasks.py +++ b/caikit_computer_vision/data_model/tasks.py @@ -12,16 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. """ -This module holds the Task definitions for all common NLP tasks +This module holds the Task definitions for all common vision tasks """ # Standard from typing import Iterable -# Local +# First Party from caikit.core import TaskBase, task -from .object_detection import ObjectDetectionResult + +# Local from .image_classification import ImageClassificationResult +from .object_detection import ObjectDetectionResult + # TODO - add support for image DM primitives @task( @@ -34,6 +37,7 @@ class ObjectDetectionTask(TaskBase): and confidence scores. """ + @task( required_parameters={"inputs": bytes}, output_type=ImageClassificationResult, diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9988c40 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[build-system] +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" + +[project] +name = "caikit-computer-vision" +# Not the actual current version: overwritten by CI +version = "0.0.1" +description = "Caikit Computer Vision" +license = {text = "Apache-2.0"} +readme = "README.md" +requires-python = "~=3.9" +classifiers=[ + "License :: OSI Approved :: Apache Software License" +] +dependencies = [ + "caikit==0.8.0" +] + +[project.urls] +Source = "https://github.com/caikit/caikit-computer-vision" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index d4c05c7..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -caikit==0.8.0 diff --git a/scripts/fmt.sh b/scripts/fmt.sh new file mode 100755 index 0000000..bcc12d3 --- /dev/null +++ b/scripts/fmt.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +pre-commit run --all-files +RETURN_CODE=$? + +function echoWarning() { + LIGHT_YELLOW='\033[1;33m' + NC='\033[0m' # No Color + echo -e "${LIGHT_YELLOW}${1}${NC}" +} + +if [ "$RETURN_CODE" -ne 0 ]; then + if [ "${CI}" != "true" ]; then + echoWarning "โ˜๏ธ This appears to have failed, but actually your files have been formatted." + echoWarning "Make a new commit with these changes before making a pull request." + else + echoWarning "This test failed because your code isn't formatted correctly." + echoWarning 'Locally, run `make run fmt`, it will appear to fail, but change files.' + echoWarning "Add the changed files to your commit and this stage will pass." + fi + + exit $RETURN_CODE +fi diff --git a/setup_requirements.txt b/setup_requirements.txt new file mode 100644 index 0000000..f4de449 --- /dev/null +++ b/setup_requirements.txt @@ -0,0 +1,2 @@ +tox>=4.4.2,<5 +build>=0.10.0,<1.0 \ No newline at end of file diff --git a/tests/data_model/test_tasks.py b/tests/data_model/test_tasks.py index 6360b58..4ce6da2 100644 --- a/tests/data_model/test_tasks.py +++ b/tests/data_model/test_tasks.py @@ -21,16 +21,16 @@ from typing import Type # Third Party -from caikit.core import ModuleBase, TaskBase, module -from caikit.core.registries import ( - module_backend_registry, - module_registry, -) import pytest +# First Party +from caikit.core import ModuleBase, TaskBase, module +from caikit.core.registries import module_backend_registry, module_registry + # Local from caikit_computer_vision.data_model import tasks + ## Helpers ##################################################################### @pytest.fixture def reset_module_registry(): @@ -40,6 +40,7 @@ def reset_module_registry(): module_registry().clear() module_registry().update(orig_module_registry) + @pytest.fixture def reset_module_backend_registry(): """Fixture that will reset the module distribution registry if a test modifies them""" @@ -50,19 +51,24 @@ def reset_module_backend_registry(): module_backend_registry().clear() module_backend_registry().update(orig_module_backend_registry) + ## Tests ####################################################################### + class InvalidType: pass @pytest.mark.parametrize( - "task", ( + "task", + ( tasks.ObjectDetectionTask, tasks.ImageClassificationTask, ), ) -def test_tasks(reset_module_registry, reset_module_backend_registry, task: Type[TaskBase]): +def test_tasks( + reset_module_registry, reset_module_backend_registry, task: Type[TaskBase] +): """Common tests for all tasks""" # Only support single required param named "inputs" assert set(task.get_required_parameters().keys()) == {"inputs"} diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..f74e55d --- /dev/null +++ b/tox.ini @@ -0,0 +1,45 @@ +[tox] +envlist = py, lint, fmt + +[testenv] +description = run tests with pytest with coverage +deps = + pytest==7.1.3 + pytest-cov>=2.10.1,<3.0 + pytest-html>=3.1.1,<4.0 + wheel>=0.38.4 +passenv = + LOG_LEVEL + LOG_FILTERS + LOG_FORMATTER + LOG_THREAD_ID + LOG_CHANNEL_WIDTH +commands = pytest --cov=caikit_computer_vision --cov-report=term --cov-report=html {posargs:tests} + +; Unclear: We probably want to test wheel packaging +; But! tox will fail when this is set and _any_ interpreter is missing +; Without this, sdist packaging is tested so that's a start. +package=wheel + +[testenv:fmt] +description = format with pre-commit +deps = pre-commit>=3.0.4,<4.0 +commands = ./scripts/fmt.sh +allowlist_externals = ./scripts/fmt.sh +skip_install = True # Skip package install since fmt doesn't need to execute code, for โšกโšกโšก + +[testenv:lint] +description = lint with pylint +deps = pylint>=2.16.2,<3.0 +# TODO: Bring linting scores up to 10 in a future PR +commands = pylint --fail-under=6 caikit_computer_vision + +[testenv:publish] +description = publish wheel to pypi +deps = flit==3.8 +passenv = + FLIT_PASSWORD +setenv = + FLIT_USERNAME = __token__ +commands = flit publish +skip_install = True \ No newline at end of file