class_docstr: Tests for ImageFolder functions.
docstr: Test with decoders (e.g., SkipDecoding).
docstr_tok: ["Test","with","decoders","(","e.g.",",","SkipDecoding",")","."]
code: def test_decoders(self):
      """Test with decoders (e.g., SkipDecoding)."""
      images = [
          "root_dir/train/label1/img1.png",
          "root_dir/train/label3/img3.png",
          "root_dir/train/label3/img1.png",
          "root_dir/train/label3/img2.png",
          "root_dir/train/label2/img1.png",
          "root_dir/train/label2/img2.png",
      ]
  
      with tfds.testing.MockFs() as fs:
          for file in images:
              fs.add_file(file)
  
          builder = tfds.ImageFolder(
              root_dir="root_dir", dtype=tf.uint8
          )
  
          # Decoded images should be found if passing decoders=None
          ds = builder.as_dataset(split="train", decoders=None)
          self.assertEqual(
              ds.element_spec,
              {
                  "image/filename": tf.TensorSpec(
                      shape=(), dtype=tf.string
                  ),
                  "image": tf.TensorSpec(
                      shape=(None, None, 3), dtype=tf.uint8
                  ),
                  "label": tf.TensorSpec(shape=(), dtype=tf.int64),
              },
          )
  
          # Encoded images should be found if passing decoders=SkipDecoding()
          ds = builder.as_dataset(
              split="train",
              decoders={"image": tfds.decode.SkipDecoding()},
          )
          self.assertEqual(
              ds.element_spec,
              {
                  "image/filename": tf.TensorSpec(
                      shape=(), dtype=tf.string
                  ),
                  "image": tf.TensorSpec(shape=(), dtype=tf.string),
                  "label": tf.TensorSpec(shape=(), dtype=tf.int64),
              },
          )
  
          # Invalid keys should throw ValueError
          with self.assertRaisesWithPredicateMatch(
              ValueError, "Unrecognized keys"
          ):
              builder.as_dataset(
                  split="train",
                  decoders={"invalid_key": tfds.decode.SkipDecoding()},
              )
  
file_path: datasets/tensorflow_datasets/core/folder_dataset/image_folder_test.py
imports: import os
  from unittest import mock
  import tensorflow
  from tensorflow_datasets.core.folder_dataset import image_folder
  import tensorflow_datasets.public_api
label_desc: Use image node_id 2 for calling the ImageFolderFunctionTest obj's underlying member method code with example usage: obj.test_decoders() without return types