|
|
Contributing to Kornia |
|
|
====================== |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(kornia.__version__)" |
|
|
|
|
|
To install, or update the conda environment run ``setup_dev_env.sh`` |
|
|
|
|
|
.. code:: bash |
|
|
|
|
|
./setup_dev_env.sh |
|
|
|
|
|
Coding Standards |
|
|
================ |
|
|
|
|
|
This section provides general guidance for developing code for the project. The following rules will serve as guide in writing high-quality code that will allow us to scale the project and ensure that the code base remains readable and maintainable. |
|
|
|
|
|
- Use meaningful names for variables, functions and classes. |
|
|
|
|
|
- Write small incremental changes: |
|
|
|
|
|
- In order to have a linear and clean commits history, we recommend to commit each small change that you do to the source code. |
|
|
- Clear commit messages will help to understand the progress of your work. |
|
|
- Please, avoid pushing large files. |
|
|
|
|
|
- Add tests: |
|
|
|
|
|
- Tests are crucial and we expect you to write unit test for each of the functionalities that you implement. |
|
|
It is also a good idea to group the tests for functionalities |
|
|
|
|
|
.. code:: python |
|
|
|
|
|
class TestMyFunction: |
|
|
def test_smoke(self): |
|
|
# check defaults parameters, i/o shapes |
|
|
pass |
|
|
|
|
|
def test_feature_foo(self): |
|
|
# test basic functionality |
|
|
pass |
|
|
|
|
|
def test_feature_bar(self): |
|
|
# test another functionality |
|
|
pass |
|
|
|
|
|
def test_gradcheck(self): |
|
|
# test the functionality gradients |
|
|
pass |
|
|
|
|
|
def test_jit(self): |
|
|
# test the functionality using jit modules |
|
|
pass |
|
|
|
|
|
- Tests should cover different devices (CPU and CUDA) and different input batch size. See an example: |
|
|
|
|
|
.. code:: python |
|
|
|
|
|
@pytest.mark.parametrize("device_type", ("cpu", "cuda")) |
|
|
@pytest.mark.parametrize("batch_size", [1, 2, 5]) |
|
|
def test_smoke(batch_size, device_type): |
|
|
x = torch.rand(batch_size, 2, 3) |
|
|
x = x.to(torch.device(device_type)) |
|
|
assert x.shape == (batch_size, 2, 3), x.shape |
|
|
|
|
|
- We give support to static type checker for Python >= 3.6 |
|
|
|
|
|
- Please, read `MyPy cheatsheet <https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#type-hints-cheat-sheet-python-3>`_ for Python 3. |
|
|
- It is recommended to use typing inside the function, when it would increase readability. |
|
|
- Always type function input and output, e.g.: |
|
|
|
|
|
.. code:: python |
|
|
|
|
|
def homography_warp(patch_src: torch.Tensor, |
|
|
dst_homo_src: torch.Tensor, |
|
|
dsize: Tuple[int, int], |
|
|
mode: str = 'bilinear', |
|
|
padding_mode: str = 'zeros') -> torch.Tensor: |
|
|
|
|
|
- We suggest to use new Python 3's f-Strings improved string formatting syntax: |
|
|
|
|
|
Guidelines: https://realpython.com/python-f-strings/ |
|
|
|
|
|
.. code:: python |
|
|
|
|
|
python_version: int = 3 |
|
|
print(f"This is an example to use Python {python_version}'s f-Strings") |
|
|
|
|
|
- Format your code: |
|
|
|
|
|
- We follow `PEP8 style guide <https://www.python.org/dev/peps/pep-0008>`_. |
|
|
- Use ``pre-commit`` to autoformat each commit before push: https://pre-commit.com/. |
|
|
For doing so, just install it for this repository: |
|
|
|
|
|
.. code:: bash |
|
|
|
|
|
pre-commit install |
|
|
|
|
|
- Changes to PEP8: |
|
|
|
|
|
- Line length is 120 char. |
|
|
- W504 (line break after binary operator) is sometimes acceptable. E.g. |
|
|
|
|
|
.. code:: python |
|
|
|
|
|
determinant = A[:, :, 0:1, 0:1] * A[:, :, 1:2, 1:2] - |
|
|
A[:, :, 0:1, 1:2] * A[:, :, 1:2, 0:1]) |
|
|
|
|
|
- Using 3rd party libraries: |
|
|
|
|
|
- Everything from standard library (https://docs.python.org/3/library/) and PyTorch (https://pytorch.org/) is OK. |
|
|
It does`t mean, that one should import urllib just because, but doing it when needed is fine. |
|
|
|
|
|
|
|
|
|
|
|
Pull Request |
|
|
============ |
|
|
|
|
|
Once you finish implementing a feature or bug-fix, please send a Pull Request to |
|
|
https://github.com/kornia/kornia through the website. |
|
|
|
|
|
If you are not familiar with creating a Pull Request, here are some guides: |
|
|
|
|
|
- http://stackoverflow.com/questions/14680711/how-to-do-a-github-pull-request |
|
|
- https://help.github.com/articles/creating-a-pull-request |
|
|
|
|
|
Once your pull request is created, our continuous build system will check your pull request. Continuous build will test that: |
|
|
|
|
|
- `pytest <https://docs.pytest.org/en/latest>`_ all tests pass. |
|
|
- `flake8 <https://pypi.org/project/flake8/>`_ accepts the code style (our guidelines are based on PEP8). |
|
|
- `mypy <http://mypy-lang.org>`_ type checks the Python code. |
|
|
- The docs can be generated successfully |
|
|
- Test coverage remains high. Please add unit tests so we maintain our code coverage. |
|
|
|
|
|
If your code fails one of these checks, you will be expected to fix your pull request before it is considered. |
|
|
|
|
|
|
|
|
|
|
|
Unit testing |
|
|
============ |
|
|
|
|
|
To run the test suite locally, make sure that you have activated the conda environment, then: |
|
|
|
|
|
.. code:: bash |
|
|
|
|
|
make test |
|
|
|
|
|
Licence |
|
|
======= |
|
|
|
|
|
By contributing to the project, you agree that your contributions will be licensed under the LICENSE file in the root directory of this source tree. |
|
|
|