Skip to content

Add Imagewoof Dataset #1590

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 3 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
1 change: 1 addition & 0 deletions tensorflow_datasets/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
from tensorflow_datasets.image.imagenet_resized import ImagenetResized
from tensorflow_datasets.image.imagenette import Imagenette
from tensorflow_datasets.image.imagewang import Imagewang
from tensorflow_datasets.image.imagewoof import Imagewoof
from tensorflow_datasets.image.inaturalist import INaturalist2017
from tensorflow_datasets.image.lfw import LFW
from tensorflow_datasets.image.lost_and_found import LostAndFound
Expand Down
105 changes: 105 additions & 0 deletions tensorflow_datasets/image/imagewoof.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# coding=utf-8
# Copyright 2020 The TensorFlow Datasets Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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
"""Imagewoof Dataset"""
# gfile cannot be imported directly `from tensorflow.io import gfile`
import os
import tensorflow.compat.v2 as tf
import tensorflow_datasets.public_api as tfds


_IMAGEWOOF_URL = "https://s3.amazonaws.com/fast-ai-imageclas/imagewoof2.tgz"

_CITATION = """
@misc{imagewoof,
author = "Jeremy Howard",
title = "Imagewoof",
url = "https://github.com/fastai/imagenette/"
}
"""

_DESCRIPTION = """\
Imagewoof is a subset of 10 classes from Imagenet that aren't so easy to
classify, since they're all dog breeds. The breeds are: Australian terrier,
Border terrier, Samoyed, Beagle, Shih-Tzu, English foxhound, Rhodesian
ridgeback, Dingo, Golden retriever, Old English sheepdog.
"""

lbl_dict = {
'n02093754': 'Australian terrier',
'n02089973': 'Border terrier',
'n02099601': 'Samoyed',
'n02087394': 'Beagle',
'n02105641': 'Shih-Tzu',
'n02096294': 'English foxhound',
'n02088364': 'Rhodesian ridgeback',
'n02115641': 'Dingo',
'n02111889': 'Golden retriever',
'n02086240': 'Old English sheepdog'
}


class Imagewoof(tfds.core.GeneratorBasedBuilder):
"""Imagewoof Dataset"""
VERSION = tfds.core.Version('0.1.0')

def _info(self):
return tfds.core.DatasetInfo(
builder=self,
description=_DESCRIPTION,
features=tfds.features.FeaturesDict({
"image": tfds.features.Image(),
"label": tfds.features.ClassLabel(
names=['Australian terrier', 'Border terrier', 'Samoyed',
'Beagle', 'Shih-Tzu', 'English foxhound',
'Rhodesian ridgeback', 'Dingo', 'Golden retriever',
'Old English sheepdog']),
}),
supervised_keys=("image", "label"),
homepage="https://github.com/fastai/imagenette",
citation=_CITATION
)

def _split_generators(self, dl_manager):
"""Generate Splits"""
extracted_path = dl_manager.download_and_extract(_IMAGEWOOF_URL)
extracted_path = os.path.join(extracted_path, 'imagewoof2')
# Specify the splits
return [
tfds.core.SplitGenerator(
name=tfds.Split.TRAIN,
gen_kwargs={
"images_dir_path": os.path.join(extracted_path, "train"),
}),
tfds.core.SplitGenerator(
name=tfds.Split.VALIDATION,
gen_kwargs={
"images_dir_path": os.path.join(extracted_path, "val"),
}),
]

def _generate_examples(self, images_dir_path):
"""Generate examples given the image directory path"""
count = 0
for image_folder in tf.io.gfile.listdir(images_dir_path):
for image_file in tf.io.gfile.listdir(os.path.join(images_dir_path,
image_folder)):
yield count, {
'image': '{}/{}/{}'.format(images_dir_path, image_folder,
image_file),
'label': lbl_dict[image_folder]
}
count += 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why its not showing you error for adding extra one line space after ending of code.

34 changes: 34 additions & 0 deletions tensorflow_datasets/image/imagewoof_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# coding=utf-8
# Copyright 2020 The TensorFlow Datasets Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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

"""Tests for Imagewoof."""

from tensorflow_datasets import testing
from tensorflow_datasets.image import imagewoof



class ImagewangFullSizeTest(testing.DatasetBuilderTestCase):
DATASET_CLASS = imagewoof.Imagewoof
SPLITS = {
"train": 4,
"validation": 4,
}


if __name__ == "__main__":
testing.test_main()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tensorflow_datasets/url_checksums/imagewoof.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://s3.amazonaws.com/fast-ai-imageclas/imagewoof2.tgz 1343482285 d6f2ffc7b95663f7701b94cea32db1683b9a50dd389382c7cca024e840af0379