Skip to content

Correct pylint for video datasets. #1650

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/video/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# Lint as: python3
"""Video datasets."""

# pylint: disable=c0103

from tensorflow_datasets.video.bair_robot_pushing import BairRobotPushingSmall
from tensorflow_datasets.video.moving_mnist import MovingMnist
from tensorflow_datasets.video.robonet import Robonet
Expand Down
9 changes: 4 additions & 5 deletions tensorflow_datasets/video/bair_robot_pushing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
# limitations under the License.

# Lint as: python3

"""Berkeley (BAIR) robot pushing dataset.

Self-Supervised Visual Planning with Temporal Skip Connections
Frederik Ebert, Chelsea Finn, Alex X. Lee, and Sergey Levine.
https://arxiv.org/abs/1710.05268
"""

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

import os

from absl import logging
Expand Down Expand Up @@ -57,6 +54,7 @@ class BairRobotPushingSmall(tfds.core.GeneratorBasedBuilder):
"2.0.0", "New split API (https://tensorflow.org/datasets/splits)")

def _info(self):
"""Create Dataset Info."""
# The Bair dataset consist of a sequence of frames (video) with associated
# metadata (action and position)
features = tfds.features.Sequence({
Expand Down Expand Up @@ -93,6 +91,7 @@ def _split_generators(self, dl_manager):
]

def _generate_examples(self, filedir):
"""Generate Splits."""
logging.info("Reading data from %s.", filedir)
files = tf.io.gfile.listdir(filedir)
logging.info("%d files found.", len(files))
Expand All @@ -110,7 +109,7 @@ def _generate_examples(self, filedir):
all_frames = []
for frame_id in range(FRAMES_PER_VIDEO):
# Extract all features from the original proto context field
frame_feature = { # pylint: disable=g-complex-comprehension
frame_feature = {
out_key: example.context.feature[in_key.format(frame_id)] # pylint: disable=g-complex-comprehension
for out_key, in_key in [
("image_main", "{}/image_main/encoded"),
Expand Down
6 changes: 2 additions & 4 deletions tensorflow_datasets/video/moving_sequence_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
# Lint as: python3
"""Tests for moving_sequence."""

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

import tensorflow.compat.v2 as tf

Expand All @@ -29,9 +26,10 @@


class MovingSequenceTest(tf.test.TestCase):

"""Moving Sequence Dataset Testing."""
@testing.run_in_graph_and_eager_modes()
def test_images_as_moving_sequence(self):
"""Test Images for Moving Sequence Dataset."""
h, w = (28, 28)
sequence_length = 8

Expand Down
8 changes: 3 additions & 5 deletions tensorflow_datasets/video/starcraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
# Lint as: python3
"""SCV dataset from http://arxiv.org/abs/1812.01717 ."""

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

from absl import logging
import tensorflow.compat.v2 as tf
Expand Down Expand Up @@ -56,8 +53,7 @@ class StarcraftVideoConfig(tfds.core.BuilderConfig):
def __init__(self, map_name, resolution, size_in_gb, **kwargs):
super(StarcraftVideoConfig, self).__init__(
version=tfds.core.Version(
"1.0.0", "New split API (https://tensorflow.org/datasets/splits)"),
**kwargs)
"1.0.0", "New split API (https://tensorflow.org/datasets/splits)"), **kwargs)
self.map_name = map_name
self.resolution = resolution
self.size_in_gb = size_in_gb
Expand Down Expand Up @@ -141,6 +137,7 @@ def _info(self):
)

def _split_generators(self, dl_manager):
"""Generate Splits."""
url = DATA_URL_DIR + "%s_%dx%d_png/" % (self.builder_config.map_name,
self.builder_config.resolution,
self.builder_config.resolution)
Expand Down Expand Up @@ -201,6 +198,7 @@ def _parse_single_video(self, example_proto):
return video_frames

def _generate_examples(self, files):
"""Yields Examples."""
logging.info("Reading data from %s.", ",".join(files))
with tf.Graph().as_default():
ds = tf.data.TFRecordDataset(sorted(files))
Expand Down
5 changes: 2 additions & 3 deletions tensorflow_datasets/video/ucf101.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
# Lint as: python3
"""UCF-101 dataset from https://www.crcv.ucf.edu/data/UCF101.php."""

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

import os

Expand Down Expand Up @@ -127,6 +124,7 @@ class Ucf101(tfds.core.GeneratorBasedBuilder):
]

def _info(self):
""" Create Dataset Info"""
if self.builder_config.width is not None:
if self.builder_config.height is None:
raise ValueError('Provide either both height and width or none.')
Expand Down Expand Up @@ -182,6 +180,7 @@ def _split_generators(self, dl_manager):
]

def _generate_examples(self, videos_dir, splits_dir, data_list):
"""Yields Examples"""
data_list_path_path = os.path.join(splits_dir, data_list)
with tf.io.gfile.GFile(data_list_path_path, 'r') as data_list_file:
labels_and_paths = data_list_file.readlines()
Expand Down
11 changes: 5 additions & 6 deletions tensorflow_datasets/video/ucf101_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 UCF101 video dataset."""


import collections

Expand All @@ -26,6 +25,7 @@


class Ucf101Test(testing.DatasetBuilderTestCase):
"""Create testing.DatasetBuilderTestCase for test."""
DATASET_CLASS = ucf101.Ucf101

SPLITS = {
Expand All @@ -40,9 +40,9 @@ class Ucf101Test(testing.DatasetBuilderTestCase):

BUILDER_CONFIG_NAMES_TO_TEST = ['ucf101_1_256', 'ucf101_2']

def _assertAsDataset(self, builder):
def _assert_as_dataset(self, builder):
"""Check the label distribution for each split."""
super(Ucf101Test, self)._assertAsDataset(builder)
super(Ucf101Test, self)._assert_as_dataset(builder)
label_frequncies = {}
label_feature = builder.info.features['label']
dataset = builder.as_dataset()
Expand All @@ -55,6 +55,5 @@ def _assertAsDataset(self, builder):
{'test': {'Archery': 1, 'Nunchucks': 1},
'train': {'Archery': 1, 'Nunchucks': 2}})


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