imagenet_data.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright 2016 Google Inc. 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. """Small library that points to the ImageNet data set.
  16. """
  17. from __future__ import absolute_import
  18. from __future__ import division
  19. from __future__ import print_function
  20. from inception.dataset import Dataset
  21. class ImagenetData(Dataset):
  22. """ImageNet data set."""
  23. def __init__(self, subset):
  24. super(ImagenetData, self).__init__('ImageNet', subset)
  25. def num_classes(self):
  26. """Returns the number of classes in the data set."""
  27. return 1000
  28. def num_examples_per_epoch(self):
  29. """Returns the number of examples in the data set."""
  30. # Bounding box data consists of 615299 bounding boxes for 544546 images.
  31. if self.subset == 'train':
  32. return 1281167
  33. if self.subset == 'validation':
  34. return 50000
  35. def download_message(self):
  36. """Instruction to download and extract the tarball from Flowers website."""
  37. print('Failed to find any ImageNet %s files'% self.subset)
  38. print('')
  39. print('If you have already downloaded and processed the data, then make '
  40. 'sure to set --data_dir to point to the directory containing the '
  41. 'location of the sharded TFRecords.\n')
  42. print('If you have not downloaded and prepared the ImageNet data in the '
  43. 'TFRecord format, you will need to do this at least once. This '
  44. 'process could take several hours depending on the speed of your '
  45. 'computer and network connection\n')
  46. print('Please see README.md for instructions on how to build '
  47. 'the ImageNet dataset using download_and_preprocess_imagenet.\n')
  48. print('Note that the raw data size is 300 GB and the processed data size '
  49. 'is 150 GB. Please ensure you have at least 500GB disk space.')