code: def test_image_classification_parity(self):
      # we can not compare to the Pytorch transformers example, that uses custom preprocessing on the images
      model_name = "douwekiela/resnet-18-finetuned-dogfood"
      dataset_name = "beans"
      max_eval_samples = 120
  
      raw_dataset = load_dataset(dataset_name, split="validation")
      eval_dataset = raw_dataset.select(range(max_eval_samples))
  
      feature_extractor = AutoFeatureExtractor.from_pretrained(
          model_name
      )
      model = AutoModelForImageClassification.from_pretrained(
          model_name
      )
  
      def collate_fn(examples):
          pixel_values = torch.stack(
              [
                  torch.tensor(
                      feature_extractor(example["image"])[
                          "pixel_values"
                      ][0]
                  )
                  for example in examples
              ]
          )
          labels = torch.tensor(
              [example["labels"] for example in examples]
          )
          return {"pixel_values": pixel_values, "labels": labels}
  
      metric = load("accuracy")
      trainer = Trainer(
          model=model,
          args=TrainingArguments(
              output_dir=os.path.join(
                  self.dir_path,
                  "imageclassification_beans_transformers",
              ),
              remove_unused_columns=False,
          ),
          train_dataset=None,
          eval_dataset=eval_dataset,
          compute_metrics=lambda p: metric.compute(
              predictions=np.argmax(p.predictions, axis=1),
              references=p.label_ids,
          ),
          tokenizer=None,
          data_collator=collate_fn,
      )
  
      metrics = trainer.evaluate()
      trainer.save_metrics("eval", metrics)
  
      with open(
          f"{os.path.join(self.dir_path, 'imageclassification_beans_transformers', 'eval_results.json')}",
          "r",
      ) as f:
          transformers_results = json.load(f)
  
      pipe = pipeline(
          task="image-classification",
          model=model_name,
          feature_extractor=model_name,
      )
  
      task_evaluator = evaluator(task="image-classification")
      evaluator_results = task_evaluator.compute(
          model_or_pipeline=pipe,
          data=eval_dataset,
          metric="accuracy",
          input_column="image",
          label_column="labels",
          label_mapping=model.config.label2id,
          strategy="simple",
      )
  
      self.assertEqual(
          transformers_results["eval_accuracy"],
          evaluator_results["accuracy"],
      )
  
imports: import json
  import os
  import shutil
  import subprocess
  import tempfile
  import unittest
  import numpy
  import torch
  import transformers
  from datasets import load_dataset
  from transformers import AutoFeatureExtractor, AutoModelForImageClassification, Trainer, TrainingArguments, pipeline
  from evaluate import evaluator, load
  from .utils import slow
label_desc: Use image node_id 5 for calling the TestEvaluatorTrainerParity obj's underlying member method code with example usage: obj.test_image_classification_parity() and returns: dict