code: def test_dataset_with_image_feature_map(shared_datadir):
      image_path = str(shared_datadir / "test_image_rgb.jpg")
      data = {"image": [image_path], "caption": ["cats sleeping"]}
      features = Features(
          {"image": Image(), "caption": Value("string")}
      )
      dset = Dataset.from_dict(data, features=features)
  
      for item in dset.cast_column("image", Image(decode=False)):
          assert item.keys() == {"image", "caption"}
          assert item == {
              "image": {"path": image_path, "bytes": None},
              "caption": "cats sleeping",
          }
  
      # no decoding
  
      def process_caption(example):
          example["caption"] = "Two " + example["caption"]
          return example
  
      processed_dset = dset.map(process_caption)
      for item in processed_dset.cast_column(
          "image", Image(decode=False)
      ):
          assert item.keys() == {"image", "caption"}
          assert item == {
              "image": {"path": image_path, "bytes": None},
              "caption": "Two cats sleeping",
          }
  
      # decoding example
  
      def process_image_by_example(example):
          example["mode"] = example["image"].mode
          return example
  
      decoded_dset = dset.map(process_image_by_example)
      for item in decoded_dset.cast_column(
          "image", Image(decode=False)
      ):
          assert item.keys() == {"image", "caption", "mode"}
          assert os.path.samefile(item["image"]["path"], image_path)
          assert item["caption"] == "cats sleeping"
          assert item["mode"] == "RGB"
  
      # decoding batch
  
      def process_image_by_batch(batch):
          batch["mode"] = [image.mode for image in batch["image"]]
          return batch
  
      decoded_dset = dset.map(process_image_by_batch, batched=True)
      for item in decoded_dset.cast_column(
          "image", Image(decode=False)
      ):
          assert item.keys() == {"image", "caption", "mode"}
          assert os.path.samefile(item["image"]["path"], image_path)
          assert item["caption"] == "cats sleeping"
          assert item["mode"] == "RGB"
  
imports: import os
  import tarfile
  import warnings
  import numpy
  import pandas
  import pyarrow
  import pytest
  from datasets import Dataset, Features, Image, Sequence, Value, concatenate_datasets, load_dataset
  from datasets.features.image import encode_np_array, image_to_bytes
  from ..utils import require_pil
label_desc: Use image node_id 15 for calling a global function with example usage: test_dataset_with_image_feature_map(shared_datadir) and returns: example, example, batch