diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e9c0f2348..ef9807231 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,16 +14,12 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.7 - - name: Install linting dependencies + - name: Install pre-commit hook run: | - python -m pip install --upgrade pip - pip install flake8 yapf isort==4.3.21 - - name: Lint with flake8 - run: flake8 --max-complexity 20 . - - name: Lint with isort - run: isort --recursive --check-only --diff mmcv/ tests/ examples/ - - name: Format python codes with yapf - run: yapf -r -d mmcv/ tests/ examples/ + pip install pre-commit + pre-commit install + - name: Linting + run: pre-commit run --all-files - name: Format c/cuda codes with clang-format uses: DoozyX/clang-format-lint-action@v0.6 with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 49b03aefb..056c04659 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,16 +29,21 @@ repos: args: ["--remove"] - id: mixed-line-ending args: ["--fix=lf"] + - repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 2.1.4 + hooks: + - id: markdownlint + args: ["-r", "~MD002,~MD013,~MD029,~MD033,~MD034"] - repo: https://github.com/myint/docformatter rev: v1.3.1 hooks: - id: docformatter args: ["--in-place", "--wrap-descriptions", "79"] - - repo: local - hooks: - - id: clang-format - name: clang-format - description: Format files with ClangFormat - entry: clang-format -style=google -i - language: system - files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|cuh|proto)$ + # - repo: local + # hooks: + # - id: clang-format + # name: clang-format + # description: Format files with ClangFormat + # entry: clang-format -style=google -i + # language: system + # files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|cuh|proto)$ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eea39bfe8..32f773d33 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,9 +17,11 @@ Note: If you plan to add some new features that involve large changes, it is enc ## Code style ### Python + We adopt [PEP8](https://www.python.org/dev/peps/pep-0008/) as the preferred code style. We use the following tools for linting and formatting: + - [flake8](http://flake8.pycqa.org/en/latest/): linter - [yapf](https://github.com/google/yapf): formatter - [isort](https://github.com/timothycrosley/isort): sort imports @@ -32,19 +34,20 @@ The config for a pre-commit hook is stored in [.pre-commit-config](./.pre-commit After you clone the repository, you will need to install initialize pre-commit hook. -``` +```shell pip install -U pre-commit ``` From the repository folder -``` + +```shell pre-commit install ``` After this on every commit check code linters and formatter will be enforced. - >Before you create a PR, make sure that your code lints and is formatted by yapf. ### C++ and CUDA + We follow the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html). diff --git a/README.md b/README.md index ff0bb85cc..bb747a3f0 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,6 @@ Note: If you would like to use `opencv-python-headless` instead of `opencv-pytho e.g., in a minimum container environment or servers without GUI, you can first install it before installing MMCV to skip the installation of `opencv-python`. - ### TroubleShooting If you meet issues when running or compiling mmcv, we list some common issues in [TROUBLESHOOTING.md](docs/trouble_shooting.md). diff --git a/docs/image.md b/docs/image.md index adedf50ea..c6e9bbef4 100644 --- a/docs/image.md +++ b/docs/image.md @@ -3,6 +3,7 @@ This module provides some image processing methods, which requires `opencv` to be installed. ### Read/Write/Show + To read or write images files, use `imread` or `imwrite`. ```python @@ -34,7 +35,9 @@ for i in range(10): ``` ### Color space conversion + Supported conversion methods: + - bgr2gray - gray2bgr - bgr2rgb @@ -50,6 +53,7 @@ img3 = mmcv.bgr2hsv(img) ``` ### Resize + There are three resize methods. All `imresize_*` methods have an argument `return_scale`, if this argument is `False`, then the return value is merely the resized image, otherwise is a tuple `(resized_img, scale)`. @@ -70,6 +74,7 @@ mmcv.imrescale(img, (1000, 800)) ``` ### Rotate + To rotate an image by some angle, use `imrotate`. The center can be specified, which is the center of original image by default. There are two modes of rotating, one is to keep the image size unchanged so that some parts of the image will be @@ -96,6 +101,7 @@ img_ = mmcv.imrotate(img, 30, auto_bound=True) ``` ### Flip + To flip an image, use `imflip`. ```python @@ -109,6 +115,7 @@ mmcv.imflip(img, direction='vertical') ``` ### Crop + `imcrop` can crop the image with one or some regions, represented as (x1, y1, x2, y2). ```python @@ -130,6 +137,7 @@ patches = mmcv.imcrop(img, bboxes, scale_ratio=1.2) ``` ### Padding + There are two methods `impad` and `impad_to_multiple` to pad an image to the specific size with given values. diff --git a/docs/io.md b/docs/io.md index 9bcc31865..3142e6e72 100644 --- a/docs/io.md +++ b/docs/io.md @@ -3,6 +3,7 @@ This module provides two universal API to load and dump files of different formats. ### Load and dump data + `mmcv` provides a universal api for loading and dumping data, currently supported formats are json, yaml and pickle. @@ -82,6 +83,7 @@ class PickleHandler(mmcv.BaseFileHandler): ### Load a text file as a list or dict For example `a.txt` is a text file with 5 lines. + ``` a b @@ -104,6 +106,7 @@ Then use `list_from_file` to load the list from a.txt. ``` For example `b.txt` is a text file with 5 lines. + ``` 1 cat 2 dog cow diff --git a/docs/utils.md b/docs/utils.md index 9e29539d1..bcc71bfdf 100644 --- a/docs/utils.md +++ b/docs/utils.md @@ -38,7 +38,7 @@ Currently, it supports four predefined variables: `{{ fileExtname }}` - the current opened file's extension, e.g. .ext -These variable names are referred from https://code.visualstudio.com/docs/editor/variables-reference. +These variable names are referred from [VS Code](https://code.visualstudio.com/docs/editor/variables-reference). Here is one examples of config with predefined variables. @@ -58,7 +58,6 @@ c = '{{ fileExtname }}' ... c='.py') ``` - For all format configs, inheritance is supported. To reuse fields in other config files, specify `_base_='./config_a.py'` or a list of configs `_base_=['./config_a.py', './config_b.py']`. Here are 4 examples of config inheritance. @@ -70,7 +69,7 @@ a = 1 b = dict(b1=[0, 1, 2], b2=None) ``` -#### Inherit from base config without overlaped keys. +#### Inherit from base config without overlaped keys `config_b.py` @@ -91,7 +90,7 @@ d = 'string' New fields in `config_b.py` are combined with old fields in `config_a.py` -#### Inherit from base config with overlaped keys. +#### Inherit from base config with overlaped keys `config_c.py` @@ -111,7 +110,7 @@ c = (1, 2) `b.b2=None` in `config_a` is replaced with `b.b2=1` in `config_c.py`. -#### Inherit from base config with ignored fields. +#### Inherit from base config with ignored fields `config_d.py` @@ -131,7 +130,7 @@ c = (1, 2) You may also set `_delete_=True` to ignore some fields in base configs. All old keys `b1, b2, b3` in `b` are replaced with new keys `b2, b3`. -#### Inherit from multiple base configs (the base configs should not contain the same keys). +#### Inherit from multiple base configs (the base configs should not contain the same keys) `config_e.py` diff --git a/docs/video.md b/docs/video.md index 93d66d702..a01f37716 100644 --- a/docs/video.md +++ b/docs/video.md @@ -6,7 +6,6 @@ This module provides the following functionalities. - Some methods for editing (cut, concat, resize) videos. - Optical flow read/write/warp. - ### VideoReader The `VideoReader` class provides sequence like apis to access video frames. diff --git a/mmcv/cnn/bricks/conv2d_adaptive_padding.py b/mmcv/cnn/bricks/conv2d_adaptive_padding.py index 1143d25f3..6b636b034 100644 --- a/mmcv/cnn/bricks/conv2d_adaptive_padding.py +++ b/mmcv/cnn/bricks/conv2d_adaptive_padding.py @@ -8,11 +8,11 @@ from .registry import CONV_LAYERS @CONV_LAYERS.register_module() class Conv2dAdaptivePadding(nn.Conv2d): - """ Implementation of 2D convolution in tensorflow with `padding` as - "same", which applies padding to input (if needed) so that input image - gets fully covered by filter and stride you specified. For stride 1, this - will ensure that output image size is same as input. For stride of 2, - output dimensions will be half, for example. + """Implementation of 2D convolution in tensorflow with `padding` as "same", + which applies padding to input (if needed) so that input image gets fully + covered by filter and stride you specified. For stride 1, this will ensure + that output image size is same as input. For stride of 2, output dimensions + will be half, for example. Args: in_channels (int): Number of channels in the input image