Skip to content

Commit

Permalink
Update numpy 1.22 types and pylint (scalabel#454)
Browse files Browse the repository at this point in the history
* Fix dependency versions

* Change pandas version

* Change scikit-learn  version

* Update scipy version

* Fixed linting errors in eval code

* Fixed more linting errors skipped by mypy

* Fixed incompatible type errors

* Fixed python tests

* Protobuf workaround fix

* Small fixes

* Support newest version of pylint and fix linting errors

* Remove data copy when unnecessary

Co-authored-by: cwlroda <[email protected]>
Co-authored-by: Fisher Yu <[email protected]>
  • Loading branch information
3 people authored Jun 5, 2022
1 parent 99ab28c commit 9784a1d
Show file tree
Hide file tree
Showing 30 changed files with 144 additions and 148 deletions.
23 changes: 13 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
name: lint python
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install apt packages
run: |
sudo apt-get install -y libopenmpi-dev
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
Expand Down Expand Up @@ -49,12 +49,12 @@ jobs:
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install apt packages
run: |
sudo apt-get install -y libopenmpi-dev
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -66,7 +66,9 @@ jobs:
- name: Build
run: python3 setup.py sdist bdist_wheel
- name: Test
run: python3 -m pytest --pyargs scalabel
run: |
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
python3 -m pytest --pyargs scalabel
python-mac:
name: test py${{ matrix.python-version }} on mac
Expand All @@ -76,12 +78,12 @@ jobs:
python-version: ["3.9", "3.10"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install brew packages
run: |
brew install openmpi
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -95,6 +97,7 @@ jobs:
- name: Test
env:
MPLBACKEND: TkAgg
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION: python
run: python3 -m pytest --pyargs scalabel

nodejs:
Expand All @@ -120,9 +123,9 @@ jobs:
- 6378:6379

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install node packages
Expand All @@ -144,7 +147,7 @@ jobs:
name: build docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and export to Docker
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
Expand All @@ -36,4 +36,4 @@ jobs:
AWS_S3_BUCKET: doc.scalabel.ai
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SOURCE_DIR: "doc/_build/src/html/"
SOURCE_DIR: "doc/_build/src/html/"
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: build and push docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v3

# Runs a single command using the runners shell
- name: Run setup script
Expand Down
38 changes: 14 additions & 24 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ persistent=yes

# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=pylint.extensions.docparams
load-plugins=pylint.extensions.docparams,pylint.extensions.bad_builtin,pylint.extensions.no_self_use

# Use multiple processes to speed up Pylint.
jobs=1
Expand All @@ -40,7 +40,7 @@ confidence=
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time. See also the "--disable" option for examples.
enable=use-symbolic-message-instead,useless-supression,fixme
enable=use-symbolic-message-instead,useless-suppression,fixme

# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifiers separated by comma (,) or put this
Expand All @@ -52,10 +52,8 @@ enable=use-symbolic-message-instead,useless-supression,fixme
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"

# This is a bug in detecting bad continuation. Since black is handling the code
# formatting, we can disable C0330 safely.
# C0413: ignore wrong import order since we use isort for that
disable=C0330, R0801, C0413
disable=R0801, C0413



Expand All @@ -66,11 +64,6 @@ disable=C0330, R0801, C0413
# mypackage.mymodule.MyReporterClass.
output-format=text

# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
# written in a file name "pylint_global.[txt|html]".
files-output=no

# Tells whether to display a full report or only the messages
reports=no

Expand Down Expand Up @@ -144,9 +137,6 @@ max-line-length=79
# else.
single-line-if-stmt=no

# List of optional constructs for which whitespace checking is disabled
no-space-check=trailing-comma,dict-separator

# Maximum number of lines in a module
max-module-lines=1024

Expand Down Expand Up @@ -183,61 +173,61 @@ include-naming-hint=no
function-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for function names
function-name-hint=[a-z_][a-z0-9_]{2,30}$
function-naming-style=snake_case

# Regular expression matching correct variable names
variable-rgx=[a-z_][a-z0-9_]{0,30}$

# Naming hint for variable names
variable-name-hint=[a-z_][a-z0-9_]{0,30}$
variable-naming-style=snake_case

# Regular expression matching correct constant names
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$

# Naming hint for constant names
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$
const-naming-style=snake_case

# Regular expression matching correct attribute names
attr-rgx=[a-z_][a-z0-9_]{1,}$

# Naming hint for attribute names
attr-name-hint=[a-z_][a-z0-9_]{1,}$
attr-naming-style=snake_case

# Regular expression matching correct argument names
argument-rgx=[a-z_][a-z0-9_]{1,30}$

# Naming hint for argument names
argument-name-hint=[a-z_][a-z0-9_]{1,30}$
argument-naming-style=snake_case

# Regular expression matching correct class attribute names
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{1,30}|(__.*__))$

# Naming hint for class attribute names
class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{1,30}|(__.*__))$
class-attribute-naming-style=snake_case

# Regular expression matching correct inline iteration names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$

# Naming hint for inline iteration names
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$
inlinevar-naming-style=snake_case

# Regular expression matching correct class names
class-rgx=[A-Z_][a-zA-Z0-9]+$

# Naming hint for class names
class-name-hint=[A-Z_][a-zA-Z0-9]+$
class-naming-style=snake_case

# Regular expression matching correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

# Naming hint for module names
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
module-naming-style=snake_case

# Regular expression matching correct method names
method-rgx=[a-z_][a-z0-9_]{2,}$

# Naming hint for method names
method-name-hint=[a-z_][a-z0-9_]{2,}$
method-naming-style=snake_case

# Regular expression which should only match function or class names that do
# not require a docstring.
Expand Down Expand Up @@ -369,4 +359,4 @@ int-import-graph=

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception
overgeneral-exceptions=Exception
2 changes: 1 addition & 1 deletion scalabel/bot/polyrnn_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Dict, List

import numpy as np
from Tool.tool import Tool # pylint: disable=import-error
from Tool.tool import Tool

from ..common.typing import NDArrayF64, NDArrayU8
from .seg_base import SegBase
Expand Down
9 changes: 3 additions & 6 deletions scalabel/eval/boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class BoundaryResult(Result):
F1_pix2: List[Dict[str, float]]
F1_pix5: List[Dict[str, float]]

# pylint: disable=useless-super-delegation
def __eq__(self, other: "BoundaryResult") -> bool: # type: ignore
"""Check whether two instances are equal."""
return super().__eq__(other)
Expand Down Expand Up @@ -142,7 +141,7 @@ def eval_bdry_per_frame(
) -> Dict[str, NDArrayF64]:
"""Compute mean, recall, and decay from per-frame evaluation."""
w, h = image_size.width, image_size.height
blank_mask = np.zeros((h, w))
blank_mask: NDArrayU8 = np.zeros((h, w), dtype=np.uint8)
task2arr: Dict[str, NDArrayF64] = {} # str -> 2d array
if gt_frame.labels is None:
gt_frame.labels = []
Expand All @@ -157,18 +156,16 @@ def eval_bdry_per_frame(
for task_name, cats in categories.items():
task_scores: List[List[float]] = []
for cat in cats:
gt_mask = (
gt_mask: NDArrayU8 = (
rle_to_mask(gt_masks[cat.name])
if cat.name in gt_masks
else blank_mask
)
gt_mask = gt_mask > 0
pd_mask = (
pd_mask: NDArrayU8 = (
rle_to_mask(pd_masks[cat.name])
if cat.name in pd_masks
else blank_mask
)
pd_mask = pd_mask > 0
cat_scores = [
eval_bdry_per_thr(
gt_mask,
Expand Down
2 changes: 1 addition & 1 deletion scalabel/eval/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def evaluate(self) -> None:
self.compute_match, range(len(p.imgIds))
)
else:
to_updates = list(map(self.compute_match, range(len(p.imgIds))))
to_updates = [self.compute_match(i) for i in range(len(p.imgIds))]

eval_num = len(p.catIds) * len(p.areaRng) * len(p.imgIds)
self.evalImgs: List[DictStrAny] = [{} for _ in range(eval_num)]
Expand Down
2 changes: 1 addition & 1 deletion scalabel/eval/mot.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def get_frame_index(frame: Frame) -> int:
)
if gt_ignores.shape[0] > 0:
# 1. assign gt and preds
fps: NDArrayU8 = np.ones(pred_bboxes_c.shape[0]).astype(bool)
fps: NDArrayU8 = np.ones(pred_bboxes_c.shape[0], dtype=bool)
le, ri = mm.lap.linear_sum_assignment(distances)
for m, n in zip(le, ri):
if np.isfinite(distances[m, n]):
Expand Down
2 changes: 1 addition & 1 deletion scalabel/eval/mots.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def get_frame_index(frame: Frame) -> int:
)
if len(gt_ignores) > 0 and len(pred_rles_c) > 0:
# 1. assign gt and preds
fps: NDArrayU8 = np.ones(len(pred_rles_c)).astype(bool)
fps: NDArrayU8 = np.ones(len(pred_rles_c), dtype=bool)
le, ri = mm.lap.linear_sum_assignment(distances)
for m, n in zip(le, ri):
if np.isfinite(distances[m, n]):
Expand Down
1 change: 0 additions & 1 deletion scalabel/eval/pan_seg.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class PanSegResult(Result):
RQ: List[Dict[str, float]]
NUM: List[Dict[str, int]]

# pylint: disable=useless-super-delegation
def __eq__(self, other: "PanSegResult") -> bool: # type: ignore
"""Check whether two instances are equal."""
return super().__eq__(other)
Expand Down
2 changes: 1 addition & 1 deletion scalabel/eval/pose.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def evaluate(self) -> None:
self.compute_match, range(len(p.imgIds))
)
else:
to_updates = list(map(self.compute_match, range(len(p.imgIds))))
to_updates = [self.compute_match(i) for i in range(len(p.imgIds))]

eval_num = len(p.catIds) * len(p.areaRng) * len(p.imgIds)
self.evalImgs: List[DictStrAny] = [{} for _ in range(eval_num)]
Expand Down
2 changes: 1 addition & 1 deletion scalabel/eval/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def table(
strs.insert(row_ind, split_line)
summary = "".join([f"{s}\n" for s in strs])
summary = "\n" + summary
return summary # type: ignore
return str(summary)

def __str__(self) -> str:
"""Convert the data into a printable string."""
Expand Down
Loading

0 comments on commit 9784a1d

Please sign in to comment.