Skip to content

Correct pylint for Image datasets #1648

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions tensorflow_datasets/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# Lint as: python3
"""Image datasets."""

# pylint: disable=c0103

from tensorflow_datasets.image.abstract_reasoning import AbstractReasoning
from tensorflow_datasets.image.aflw2k3d import Aflw2k3d
from tensorflow_datasets.image.arc import ARC
Expand Down
2 changes: 2 additions & 0 deletions tensorflow_datasets/image/abstract_reasoning_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

# Lint as: python3
"""AbstractReasoning dataset test."""

from tensorflow_datasets.image import abstract_reasoning
import tensorflow_datasets.testing as tfds_test


class AbstractReasoningTest(tfds_test.DatasetBuilderTestCase):
""" Create testing.DatasetBuilderTestCase for tests."""
DATASET_CLASS = abstract_reasoning.AbstractReasoning
SPLITS = {"train": 5, "validation": 5, "test": 5}
DL_EXTRACT_RESULT = [
Expand Down
5 changes: 2 additions & 3 deletions tensorflow_datasets/image/aflw2k3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
# Lint as: python3
"""AFLW2000-3D Dataset."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os
import numpy as np
Expand Down Expand Up @@ -80,6 +77,7 @@ def _info(self):
)

def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
extracted_path = dl_manager.download_and_extract(
"http://www.cbsr.ia.ac.cn/users/xiangyuzhu/projects/3DDFA/Database/AFLW2000-3D.zip"
)
Expand All @@ -92,6 +90,7 @@ def _split_generators(self, dl_manager):
]

def _generate_examples(self, image_dir_path):
"""Generates images given the image directory path."""
image_files = tf.io.gfile.glob(
pattern=os.path.join(image_dir_path, "image0*.jpg"))
label_files = [s.replace("jpg", "mat") for s in image_files]
Expand Down
1 change: 0 additions & 1 deletion tensorflow_datasets/image/beans.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,3 @@ def _generate_examples(self, archive):
"label": label,
}
yield fname, record

1 change: 0 additions & 1 deletion tensorflow_datasets/image/beans_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ class BeansTest(tfds_test.DatasetBuilderTestCase):

if __name__ == '__main__':
tfds_test.test_main()

4 changes: 1 addition & 3 deletions tensorflow_datasets/image/bigearthnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
# Lint as: python3
"""BigEarthNet remote sensing dataset of Sentinel-2 image patches."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import io
import json
Expand Down Expand Up @@ -139,6 +136,7 @@ class Bigearthnet(tfds.core.BeamBasedBuilder):
]

def _info(self):
""" Create Dataset Info."""
metadata_dict = tfds.features.FeaturesDict({
'acquisition_date': tfds.features.Text(),
'coordinates': {
Expand Down
9 changes: 3 additions & 6 deletions tensorflow_datasets/image/binarized_mnist_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
# Lint as: python3
"""Tests for binarized_mnist dataset module."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorflow_datasets import testing
from tensorflow_datasets.image import binarized_mnist
Expand All @@ -35,9 +32,9 @@ class MNISTTest(testing.DatasetBuilderTestCase):
"test": 2,
}
DL_EXTRACT_RESULT = {
"train_data": binarized_mnist._TRAIN_DATA_FILENAME,
"validation_data": binarized_mnist._VALID_DATA_FILENAME,
"test_data": binarized_mnist._TEST_DATA_FILENAME,
"train_data": binarized_mnist._TRAIN_DATA_FILENAME, # pylint: disable=W0212
"validation_data": binarized_mnist._VALID_DATA_FILENAME, # pylint: disable=W0212
"test_data": binarized_mnist._TEST_DATA_FILENAME, # pylint: disable=W0212
}

if __name__ == "__main__":
Expand Down
7 changes: 3 additions & 4 deletions tensorflow_datasets/image/binary_alpha_digits_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
# 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.

# Lint as: python3
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

"""Tests for binarized_alpha_digits dataset module."""

from tensorflow_datasets.image import binary_alpha_digits
import tensorflow_datasets.testing as tfds_test

Expand Down
5 changes: 1 addition & 4 deletions tensorflow_datasets/image/caltech_birds.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
# Lint as: python3
"""Caltech birds dataset."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import collections
import os
Expand Down Expand Up @@ -82,7 +79,7 @@ def _info(self):
citation=_CITATION)

def _split_generators(self, dl_manager):

"""Returns SplitGenerators."""
download_path = dl_manager.download([
self._caltech_birds_info.split_url,
self._caltech_birds_info.annotations_url,
Expand Down
8 changes: 3 additions & 5 deletions tensorflow_datasets/image/caltech_birds_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@
# limitations under the License.

# Lint as: python3
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
"""Tests for caltech_birds dataset module."""

from tensorflow_datasets.image import caltech_birds
import tensorflow_datasets.testing as tfds_test


class CaltechBirdsTest(tfds_test.DatasetBuilderTestCase):

""" Create testing.DatasetBuilderTestCase for tests."""
DATASET_CLASS = caltech_birds.CaltechBirds2010

SPLITS = { # No. of train and test samples
Expand All @@ -35,7 +33,7 @@ class CaltechBirdsTest(tfds_test.DatasetBuilderTestCase):


class CaltechBirds2011Test(tfds_test.DatasetBuilderTestCase):

""" Create testing.DatasetBuilderTestCase for tests."""
DATASET_CLASS = caltech_birds.CaltechBirds2011

SPLITS = { # No. of train and test samples
Expand Down
12 changes: 5 additions & 7 deletions tensorflow_datasets/image/caltech_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,23 @@
# Lint as: python3
"""Tests for Caltech data loading."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorflow_datasets import testing
from tensorflow_datasets.image import caltech


class Caltech101Test(testing.DatasetBuilderTestCase):

""" Create testing.DatasetBuilderTestCase for tests."""
DATASET_CLASS = caltech.Caltech101

SPLITS = {
'train': 3,
'test': 3,
}

def setUp(self):
super(Caltech101Test, self).setUp()
caltech._TRAIN_POINTS_PER_CLASS = 1
def SetUp(self):
super(Caltech101Test, self).SetUp()
caltech._TRAIN_POINTS_PER_CLASS = 1 # pylint: disable=W0212


if __name__ == '__main__':
Expand Down
21 changes: 9 additions & 12 deletions tensorflow_datasets/image/cars196.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
# Lint as: python3
"""Dataset class for Cars196 Dataset."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os
import six.moves.urllib as urllib
import tensorflow.compat.v2 as tf
Expand Down Expand Up @@ -183,8 +181,7 @@ def _split_generators(self, dl_manager):
tfds.core.SplitGenerator(
name='train',
gen_kwargs={
'split_name':
'train',
'split_name': 'train',
'data_dir_path':
os.path.join(output_files['train'], 'cars_train'),
'data_annotations_path':
Expand All @@ -196,21 +193,20 @@ def _split_generators(self, dl_manager):
tfds.core.SplitGenerator(
name='test',
gen_kwargs={
'split_name':
'test',
'split_name': 'test',
'data_dir_path':
os.path.join(output_files['test'], 'cars_test'),
'data_annotations_path': output_files['test_annos'],
},
),
]

def _generate_examples(self, split_name, data_dir_path,
def _generate_examples(self, data_dir_path,
data_annotations_path):
"""Generate training and testing samples."""

image_dict = self.returnImageDict(data_dir_path)
bbox_dict = self.returnBbox(data_annotations_path, image_dict)
image_dict = self._return_image_dict(data_dir_path)
bbox_dict = self._return_bbox(data_annotations_path, image_dict)
with tf.io.gfile.GFile(data_annotations_path, 'rb') as f:
mat = tfds.core.lazy_imports.scipy.io.loadmat(f)
for example in mat['annotations'][0]:
Expand All @@ -224,13 +220,14 @@ def _generate_examples(self, split_name, data_dir_path,
'bbox': bbox,
}

def returnImageDict(self, path):
def _return_image_dict(self, path):
return {
filename.split('.')[0]: os.path.join(path, filename)
for filename in tf.io.gfile.listdir(path)
}

def returnBbox(self, filename, image_dict):
def _return_bbox(self, filename, image_dict):
""" Returns dict contains Bounding Box Coordinates."""
bbox_dict = {}
with tf.io.gfile.GFile(filename, 'rb') as f:
data = tfds.core.lazy_imports.scipy.io.loadmat(f)
Expand Down
5 changes: 2 additions & 3 deletions tensorflow_datasets/image/cars196_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
# limitations under the License.

# Lint as: python3
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
"""Tests for CARS196 dataset module."""

from tensorflow_datasets.image import cars196
import tensorflow_datasets.testing as tfds_test

Expand Down
4 changes: 0 additions & 4 deletions tensorflow_datasets/image/cassava.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
# Lint as: python3
"""Cassava leaf dataset with images of health and diseased leaves."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os

Expand Down Expand Up @@ -107,4 +104,3 @@ def _generate_examples(self, datapath):
"label": label,
}
yield fname, record

4 changes: 0 additions & 4 deletions tensorflow_datasets/image/cassava_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
# Lint as: python3
"""Test for cassava leaf dataset."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorflow_datasets import testing
from tensorflow_datasets.image import cassava
Expand All @@ -34,4 +31,3 @@ class CassavaTest(testing.DatasetBuilderTestCase):

if __name__ == "__main__":
testing.test_main()

21 changes: 15 additions & 6 deletions tensorflow_datasets/image/cbis_ddsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@
_ASSESSMENT_NUM_CLASSES = 6 # Original range: [0, 5]
_SUBTELTY_NUM_CLASSES = 6 # Original range: [0, 5]
_DCIM_REGEX = re.compile(
r'^.*/(?P<study>1.3.6.1.4.1.9590.100.1.2.[0-9.]+)/(?P<series>1.3.6.1.4.1.9590.100.1.2.[0-9.]+)/(?P<instance>.+).dcm$'
(r'^.*/(?P<study>1.3.6.1.4.1.9590.100.1.2.[0-9.]+)'
r'/(?P<series>1.3.6.1.4.1.9590.100.1.2.[0-9.]+)'
r'/(?P<instance>.+).dcm$')
)


Expand Down Expand Up @@ -159,6 +161,7 @@ class CuratedBreastImagingDDSM(tfds.core.GeneratorBasedBuilder):
]

def _info(self):
"""Create Dataset Info"""
features_fn_map = {
'original-calc': self._get_features_original_calc,
'original-mass': self._get_features_original_mass,
Expand All @@ -177,6 +180,7 @@ def _info(self):
citation=_CITATION)

def _get_features_original_base(self):
"""Returns features of data"""
return {
'id': tfds.features.Text(),
'breast': tfds.features.ClassLabel(names=_BREAST_LABELS),
Expand All @@ -200,6 +204,7 @@ def _get_features_original_base(self):
}

def _get_features_original_calc(self):
"""Returns tfds.features.FeaturesDict of features"""
features = self._get_features_original_base()
features['abnormalities'].update({
'calc_type':
Expand All @@ -216,6 +221,7 @@ def _get_features_original_calc(self):
return tfds.features.FeaturesDict(features)

def _get_features_original_mass(self):
"""Returns tfds.features.FeaturesDict of features"""
features = self._get_features_original_base()
features['abnormalities'].update({
'mass_shape':
Expand Down Expand Up @@ -243,7 +249,8 @@ def _get_features_patches(self):
})

def _split_generators(self, dl_manager):
if self.builder_config.name in ['original-calc', 'original-mass']:
"""Generate Splits"""
if self.builder_config.name in ['original-calc', 'original-mass']: # pylint: disable=R1705
return self._split_generators_original(dl_manager)
elif self.builder_config.name == 'patches':
return self._split_generators_patches(dl_manager)
Expand All @@ -252,7 +259,8 @@ def _split_generators(self, dl_manager):
self.builder_config.name))

def _split_generators_original(self, dl_manager):
if self.builder_config.name == 'original-calc':
"""Generate Splits orignal"""
if self.builder_config.name == 'original-calc': # pylint: disable=R1705
test_url = _CALC_TEST_CSV_URL
train_url = _CALC_TRAIN_CSV_URL
elif self.builder_config.name == 'original-mass':
Expand Down Expand Up @@ -286,6 +294,7 @@ def _split_generators_original(self, dl_manager):
]

def _split_generators_patches(self, dl_manager):
"""Generate Splits patches"""
resources_urls = {
'calc-test': _CALC_TEST_CSV_URL,
'calc-train': _CALC_TRAIN_CSV_URL,
Expand Down Expand Up @@ -358,12 +367,11 @@ def _generate_examples(self, generate_fn, **kwargs):
return generate_fn(**kwargs)

def _generate_examples_original(self, patients_data, yield_from_train_csv):

"""Yields examples from orignal."""
def _include_example_in_split(example):
if yield_from_train_csv:
return example['csv_key'] == 'train'
else:
return example['csv_key'] == 'test'
return example['csv_key'] == 'test'

for _, patient_examples in sorted(patients_data.items()):
for _, example in sorted(patient_examples.items()):
Expand All @@ -388,6 +396,7 @@ def _generate_examples_patches(self,
patch_size=(224, 224),
num_positive_patches_per_abnormality=10,
num_background_patches_per_image=10):
"""Yields examples from patches."""
# Set random seed so that we always get the same patches in each split.
np.random.seed(0x12345 + len(patients_data))

Expand Down
Loading