dataset_factory.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. """A factory-pattern class which returns classification image/label pairs."""
  16. from __future__ import absolute_import
  17. from __future__ import division
  18. from __future__ import print_function
  19. from datasets import cifar10
  20. from datasets import flowers
  21. from datasets import imagenet
  22. from datasets import mnist
  23. datasets_map = {
  24. 'cifar10': cifar10,
  25. 'flowers': flowers,
  26. 'imagenet': imagenet,
  27. 'mnist': mnist,
  28. }
  29. def get_dataset(name, split_name, dataset_dir, file_pattern=None, reader=None):
  30. """Given a dataset name and a split_name returns a Dataset.
  31. Args:
  32. name: String, the name of the dataset.
  33. split_name: A train/test split name.
  34. dataset_dir: The directory where the dataset files are stored.
  35. file_pattern: The file pattern to use for matching the dataset source files.
  36. reader: The subclass of tf.ReaderBase. If left as `None`, then the default
  37. reader defined by each dataset is used.
  38. Returns:
  39. A `Dataset` class.
  40. Raises:
  41. ValueError: If the dataset `name` is unknown.
  42. """
  43. if name not in datasets_map:
  44. raise ValueError('Name of dataset unknown %s' % name)
  45. return datasets_map[name].get_split(
  46. split_name,
  47. dataset_dir,
  48. file_pattern,
  49. reader)