def test_abstract(self):
    name = "unregistered_builder"
    self.assertEqual(name, UnregisteredBuilder.name)
    self.assertNotIn(name, registered.list_builders())

    with self.assertRaisesWithPredicateMatch(ValueError, "an abstract class"):
      registered.builder(name)
예제 #2
0
    def test_in_development(self):
        name = "in_development_dataset_builder"
        self.assertEqual(name, InDevelopmentDatasetBuilder.name)
        self.assertNotIn(name, registered.list_builders())

        with self.assertRaisesWithPredicateMatch(
                ValueError,
            ("Dataset %s is under active development and is not available yet."
             ) % name):
            registered.builder(name)
예제 #3
0
    def test_registered(self):
        name = "empty_dataset_builder"
        self.assertEqual(name, EmptyDatasetBuilder.name)
        self.assertIsInstance(registered.builder(name), EmptyDatasetBuilder)
        self.assertIn(name, registered.list_builders())

        nonexistent = "nonexistent_foobar_dataset"
        with self.assertRaisesWithPredicateMatch(ValueError, "not found"):
            registered.builder(nonexistent)
        # Prints registered datasets
        with self.assertRaisesWithPredicateMatch(ValueError, name):
            registered.builder(nonexistent)
예제 #4
0
def main(_):
    builder = registered.builder(FLAGS.dataset_name, data_dir=FLAGS.data_dir)
    builder.download_and_prepare(cache_dir=FLAGS.cache_dir)

    # TODO(rsepassi): Get splits from info
    for split in [splits.Split.TRAIN, splits.Split.TEST]:
        compute_stats(builder, split)
예제 #5
0
 def test_builder_with_kwargs(self):
     name = "empty_dataset_builder"
     name_with_kwargs = name + "/k1=1,k2=1.,k3=foo,k4=True,k5=False"
     builder = registered.builder(name_with_kwargs, data_dir="bar")
     expectations = [("k1", 1), ("k2", 1.), ("k3", u"foo"), ("k4", True),
                     ("k5", False)]
     for k, v in expectations:
         self.assertEqual(type(builder.kwargs[k]), type(v))
         self.assertEqual(builder.kwargs[k], v)
예제 #6
0
def main(_):
    dm = download_manager.DownloadManager(FLAGS.download_dir)
    builder = registered.builder(FLAGS.builder)(data_dir=FLAGS.data_dir,
                                                download_manager=dm)
    builder.download_and_prepare()

    # TODO(rsepassi): Get splits from info
    splits = [dataset_builder.Split.TRAIN, dataset_builder.Split.TEST]
    for split in splits:
        compute_stats(builder, split)
예제 #7
0
 def test_builder_fullname(self):
     fullname = "empty_dataset_builder/conf1-attr:1.0.1/k1=1,k2=2"
     builder = registered.builder(fullname, data_dir="bar")
     expected = {
         "k1": 1,
         "k2": 2,
         "version": "1.0.1",
         "config": "conf1-attr",
         "data_dir": "bar"
     }
     self.assertEqual(expected, builder.kwargs)
예제 #8
0
    def test_notebook_overwrite_dataset(self):
        """Redefining the same builder twice is possible on colab."""

        with mock.patch.object(py_utils, "is_notebook", lambda: True):
            name = "colab_builder"
            self.assertNotIn(name, registered.list_builders())

            @six.add_metaclass(registered.RegisteredDataset)
            class ColabBuilder(object):
                pass

            self.assertIn(name, registered.list_builders())
            self.assertIsInstance(registered.builder(name), ColabBuilder)
            old_colab_class = ColabBuilder

            @six.add_metaclass(registered.RegisteredDataset)  # pylint: disable=function-redefined
            class ColabBuilder(object):
                pass

            self.assertIsInstance(registered.builder(name), ColabBuilder)
            self.assertNotIsInstance(registered.builder(name), old_colab_class)
예제 #9
0
 def test_show_examples(self):
   with testing.mock_data():
     builder = registered.builder('imagenet2012')
     visualization.show_statistics(builder.info)
예제 #10
0
 def test_builder_camel_case(self):
     fullname = "EmptyDatasetBuilder"
     builder = registered.builder(fullname)
     self.assertIsInstance(builder, EmptyDatasetBuilder)