Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve pylint issues #504

Merged
merged 2 commits into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
642 changes: 642 additions & 0 deletions .pylintrc

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions changelogs/master/fixed/20191124_fixed_cloud_layer_float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Fixed `CloudLayer.draw_on_image()` producing tuples instead of arrays
as output for `float` input images.
6 changes: 6 additions & 0 deletions changelogs/master/refactored/20191124_pylint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Refactored according to pylint requirements

* Refactored all core library files to fulfill (most) pylint requirements.
* [rarely breaking] Renamed
`imgaug.augmenters.size.KeepSizeByResize.get_shapes()` to `_get_shapes()`.
* Added a project-specific pylint configuration.
3 changes: 2 additions & 1 deletion imgaug/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Imports for package imgaug."""
from __future__ import absolute_import

# this contains some deprecated classes/functions pointing to the new
# classes/functions, hence always place the other imports below this so that
# the deprecated stuff gets overwritten as much as possible
from imgaug.imgaug import *
from imgaug.imgaug import * # pylint: disable=redefined-builtin

import imgaug.augmentables as augmentables
from imgaug.augmentables import *
Expand Down
1 change: 1 addition & 0 deletions imgaug/augmentables/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Combination of all augmentable classes and related functions."""
from __future__ import absolute_import
from imgaug.augmentables.kps import *
from imgaug.augmentables.bbs import *
Expand Down
1 change: 0 additions & 1 deletion imgaug/augmentables/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ class IAugmentable(object):
Batches are not yet marked as augmentable, but might be in the future.

"""
pass
17 changes: 10 additions & 7 deletions imgaug/augmentables/batches.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Classes representing batches of normalized or unnormalized data."""
from __future__ import print_function, division, absolute_import

import copy
import collections

import numpy as np

from .. import imgaug as ia
from . import normalization as nlib
from . import utils as utils
from . import utils

DEFAULT = "DEFAULT"

Expand Down Expand Up @@ -327,26 +327,31 @@ def __init__(self, images=None, heatmaps=None, segmentation_maps=None,
@property
@ia.deprecated("Batch.images_unaug")
def images(self):
"""Get unaugmented images."""
return self.images_unaug

@property
@ia.deprecated("Batch.heatmaps_unaug")
def heatmaps(self):
"""Get unaugmented heatmaps."""
return self.heatmaps_unaug

@property
@ia.deprecated("Batch.segmentation_maps_unaug")
def segmentation_maps(self):
"""Get unaugmented segmentation maps."""
return self.segmentation_maps_unaug

@property
@ia.deprecated("Batch.keypoints_unaug")
def keypoints(self):
"""Get unaugmented keypoints."""
return self.keypoints_unaug

@property
@ia.deprecated("Batch.bounding_boxes_unaug")
def bounding_boxes(self):
"""Get unaugmented bounding boxes."""
return self.bounding_boxes_unaug

def get_column_names(self):
Expand Down Expand Up @@ -733,7 +738,7 @@ def subselect_rows_by_indices(self, indices):
rows = getattr(self, augm_name)
if rows is not None:
if augm_name == "images" and ia.is_np_array(rows):
rows = rows[indices]
rows = rows[indices] # pylint: disable=unsubscriptable-object
else:
rows = [rows[index] for index in indices]

Expand Down Expand Up @@ -802,14 +807,14 @@ def invert_subselect_rows_by_indices_(self, indices, batch_subselected):
+ [image.dtype.name for image in column_sub])

if len(shapes) == 1 and len(dtypes) == 1:
column[indices] = column_sub
column[indices] = column_sub # pylint: disable=unsupported-assignment-operation
else:
self.images = list(column)
for ith_index, index in enumerate(indices):
self.images[index] = column_sub[ith_index]
else:
for ith_index, index in enumerate(indices):
column[index] = column_sub[ith_index]
column[index] = column_sub[ith_index] # pylint: disable=unsupported-assignment-operation

return self

Expand Down Expand Up @@ -998,5 +1003,3 @@ def deepcopy(self):
setattr(batch, augm_name, utils.copy_augmentables(value))

return batch


20 changes: 14 additions & 6 deletions imgaug/augmentables/bbs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Classes representing bounding boxes."""
from __future__ import print_function, division, absolute_import

import copy
Expand Down Expand Up @@ -317,8 +318,7 @@ def intersection(self, other, default=None):
y2_i = min(self.y2, other.y2)
if x1_i > x2_i or y1_i > y2_i:
return default
else:
return BoundingBox(x1=x1_i, y1=y1_i, x2=x2_i, y2=y2_i)
return BoundingBox(x1=x1_i, y1=y1_i, x2=x2_i, y2=y2_i)

def union(self, other):
"""Compute the union BB between this BB and another BB.
Expand Down Expand Up @@ -510,14 +510,15 @@ def is_out_of_image(self, image, fully=True, partly=False):
"""
if self.is_fully_within_image(image):
return False
elif self.is_partly_within_image(image):
if self.is_partly_within_image(image):
return partly
return fully

@ia.deprecated(alt_func="BoundingBox.clip_out_of_image()",
comment="clip_out_of_image() has the exactly same "
"interface.")
def cut_out_of_image(self, *args, **kwargs):
"""Clip off all parts of the BB box that are outside of the image."""
return self.clip_out_of_image(*args, **kwargs)

def clip_out_of_image(self, image):
Expand Down Expand Up @@ -639,6 +640,7 @@ def draw_on_image(self, image, color=(0, 255, 0), alpha=1.0, size=1,
Image with bounding box drawn on it.

"""
# pylint: disable=invalid-name, redefined-outer-name
if thickness is not None:
ia.warn_deprecated(
"Usage of argument 'thickness' in BoundingBox.draw_on_image() "
Expand Down Expand Up @@ -736,6 +738,7 @@ def extract_from_image(self, image, pad=True, pad_max=None,
``H'>0`` and ``W'>0``, otherwise only ``H'>=0`` and ``W'>=0``.

"""
# pylint: disable=no-else-return, too-many-statements
height, width = image.shape[0], image.shape[1]
x1, x2, y1, y2 = self.x1_int, self.x2_int, self.y1_int, self.y2_int

Expand Down Expand Up @@ -952,6 +955,7 @@ def from_point_soup(cls, xy):
Bounding box around the points.

"""
# pylint: disable=unsubscriptable-object
xy = np.array(xy, dtype=np.float32)

assert len(xy) > 0, (
Expand Down Expand Up @@ -1173,6 +1177,7 @@ def on(self, image):
the new image shape.

"""
# pylint: disable=invalid-name
shape = normalize_shape(image)
if shape[0:2] == self.shape[0:2]:
return self.deepcopy()
Expand Down Expand Up @@ -1206,6 +1211,7 @@ def from_xyxy_array(cls, xyxy, shape):
derived from the provided corner coordinates.

"""
# pylint: disable=unsubscriptable-object
xyxy = np.array(xyxy, dtype=np.float32)

# note that np.array([]) is (0,), not (0, 2)
Expand All @@ -1215,8 +1221,8 @@ def from_xyxy_array(cls, xyxy, shape):
assert (
(xyxy.ndim == 2 and xyxy.shape[-1] == 4)
or (xyxy.ndim == 3 and xyxy.shape[1:3] == (2, 2))), (
"Expected input array of shape (N, 4) or (N, 2, 2), "
"got shape %s." % (xyxy.shape,))
"Expected input array of shape (N, 4) or (N, 2, 2), "
"got shape %s." % (xyxy.shape,))

xyxy = xyxy.reshape((-1, 2, 2))
boxes = [BoundingBox.from_point_soup(row) for row in xyxy]
Expand Down Expand Up @@ -1326,7 +1332,7 @@ def fill_from_xyxy_array_(self, xyxy):
xyxy = np.array(xyxy, dtype=np.float32)

# note that np.array([]) is (0,), not (0, 4)
assert xyxy.shape[0] == 0 or (xyxy.ndim == 2 and xyxy.shape[-1] == 4), (
assert xyxy.shape[0] == 0 or (xyxy.ndim == 2 and xyxy.shape[-1] == 4), ( # pylint: disable=unsubscriptable-object
"Expected input array to have shape (N,4), "
"got shape %s." % (xyxy.shape,))

Expand Down Expand Up @@ -1403,6 +1409,7 @@ def draw_on_image(self, image, color=(0, 255, 0), alpha=1.0, size=1,
Image with drawn bounding boxes.

"""
# pylint: disable=redefined-outer-name
image = np.copy(image) if copy else image

for bb in self.bounding_boxes:
Expand Down Expand Up @@ -1470,6 +1477,7 @@ def remove_out_of_image_fraction(self, fraction):
comment="clip_out_of_image() has the exactly same "
"interface.")
def cut_out_of_image(self):
"""Clip off all parts from all BBs that are outside of the image."""
return self.clip_out_of_image()

def clip_out_of_image(self):
Expand Down
8 changes: 5 additions & 3 deletions imgaug/augmentables/heatmaps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Classes to represent heatmaps, i.e. float arrays of ``[0.0, 1.0]``."""
from __future__ import print_function, division, absolute_import

import numpy as np
Expand Down Expand Up @@ -119,9 +120,9 @@ def get_arr(self):
max_is_one = 1.0 - eps < self.max_value < 1.0 + eps
if min_is_zero and max_is_one:
return np.copy(arr)
else:
diff = self.max_value - self.min_value
return self.min_value + diff * arr

diff = self.max_value - self.min_value
return self.min_value + diff * arr

# TODO
# def find_global_maxima(self):
Expand Down Expand Up @@ -441,6 +442,7 @@ def max_pool(self, block_size):
@ia.deprecated(alt_func="HeatmapsOnImage.resize()",
comment="resize() has the exactly same interface.")
def scale(self, *args, **kwargs):
"""Resize the heatmap(s) array given a target size and interpolation."""
return self.resize(*args, **kwargs)

def resize(self, sizes, interpolation="cubic"):
Expand Down
Loading