code: 
  
  
  
  import unittest
  
  from transformers import (
      MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
      TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
      PreTrainedTokenizer,
      is_vision_available,
  )
  from transformers.pipelines import ImageClassificationPipeline, pipeline
  from transformers.testing_utils import (
      is_pipeline_test,
      nested_simplify,
      require_tf,
      require_torch,
      require_torch_or_tf,
      require_vision,
      slow,
  )
  
  from .test_pipelines_common import ANY
  
  
  if is_vision_available():
  			from PIL import Image
  else:
  
  			class      UpperCAmelCase_						:
  
  									'''simple docstring'''
  
  
  
  
  									@staticmethod
  									def  _A			(					*_A   ,							**_A	):
  
  
  
  
  
  
  
  																'''simple docstring'''
  
  																pass
  
  @is_pipeline_test
  @require_torch_or_tf
  @require_vision
  class      UpperCAmelCase_						(     unittest.TestCase ):
  
  						'''simple docstring'''
  
  
  
  
  						UpperCamelCase__    :				List[str]       						=						MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
  						UpperCamelCase__    :				Optional[int]       						=						TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
  
  
  
  
  
  
  						def  _A			(					self   ,							_A   ,							_A   ,							_A	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      ImageClassificationPipeline(model=_A   ,							image_processor=_A   ,							top_k=2	)
  													__SCREAMING_SNAKE_CASE								=      [
  													    Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'	),
  													    'http://images.cocodataset.org/val2017/000000039769.jpg',
  													]
  													return image_classifier, examples
  
  
  
  
  
  
  						def  _A			(					self   ,							_A   ,							_A	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      image_classifier('./tests/fixtures/tests_samples/COCO/000000039769.png'	)
  
  													self.assertEqual(
  													    _A   ,							[
  													        {'score': ANY(_A	), 'label': ANY(_A	)},
  													        {'score': ANY(_A	), 'label': ANY(_A	)},
  													    ]   ,							)
  
  													import datasets
  
  													__SCREAMING_SNAKE_CASE								=      datasets.load_dataset('hf-internal-testing/fixtures_image_utils'   ,							'image'   ,							split='test'	)
  
  													# Accepts URL + PIL.Image + lists
  													__SCREAMING_SNAKE_CASE								=      image_classifier(
  													    [
  													        Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'	),
  													        'http://images.cocodataset.org/val2017/000000039769.jpg',
  													        # RGBA
  													        dataset[0]['file'],
  													        # LA
  													        dataset[1]['file'],
  													        # L
  													        dataset[2]['file'],
  													    ]	)
  													self.assertEqual(
  													    _A   ,							[
  													        [
  													            {'score': ANY(_A	), 'label': ANY(_A	)},
  													            {'score': ANY(_A	), 'label': ANY(_A	)},
  													        ],
  													        [
  													            {'score': ANY(_A	), 'label': ANY(_A	)},
  													            {'score': ANY(_A	), 'label': ANY(_A	)},
  													        ],
  													        [
  													            {'score': ANY(_A	), 'label': ANY(_A	)},
  													            {'score': ANY(_A	), 'label': ANY(_A	)},
  													        ],
  													        [
  													            {'score': ANY(_A	), 'label': ANY(_A	)},
  													            {'score': ANY(_A	), 'label': ANY(_A	)},
  													        ],
  													        [
  													            {'score': ANY(_A	), 'label': ANY(_A	)},
  													            {'score': ANY(_A	), 'label': ANY(_A	)},
  													        ],
  													    ]   ,							)
  
  
  
  
  
  
  						@require_torch
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      'hf-internal-testing/tiny-random-vit'
  													__SCREAMING_SNAKE_CASE								=      pipeline('image-classification'   ,							model=_A	)
  
  													__SCREAMING_SNAKE_CASE								=      image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'	)
  													self.assertEqual(
  													    nested_simplify(_A   ,							decimals=4	)   ,							[{'label': 'LABEL_1', 'score': 0.5_7_4}, {'label': 'LABEL_0', 'score': 0.4_2_6}]   ,							)
  
  													__SCREAMING_SNAKE_CASE								=      image_classifier(
  													    [
  													        'http://images.cocodataset.org/val2017/000000039769.jpg',
  													        'http://images.cocodataset.org/val2017/000000039769.jpg',
  													    ]   ,							top_k=2   ,							)
  													self.assertEqual(
  													    nested_simplify(_A   ,							decimals=4	)   ,							[
  													        [{'label': 'LABEL_1', 'score': 0.5_7_4}, {'label': 'LABEL_0', 'score': 0.4_2_6}],
  													        [{'label': 'LABEL_1', 'score': 0.5_7_4}, {'label': 'LABEL_0', 'score': 0.4_2_6}],
  													    ]   ,							)
  
  
  
  
  
  
  						@require_tf
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      'hf-internal-testing/tiny-random-vit'
  													__SCREAMING_SNAKE_CASE								=      pipeline('image-classification'   ,							model=_A   ,							framework='tf'	)
  
  													__SCREAMING_SNAKE_CASE								=      image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'	)
  													self.assertEqual(
  													    nested_simplify(_A   ,							decimals=4	)   ,							[{'label': 'LABEL_1', 'score': 0.5_7_4}, {'label': 'LABEL_0', 'score': 0.4_2_6}]   ,							)
  
  													__SCREAMING_SNAKE_CASE								=      image_classifier(
  													    [
  													        'http://images.cocodataset.org/val2017/000000039769.jpg',
  													        'http://images.cocodataset.org/val2017/000000039769.jpg',
  													    ]   ,							top_k=2   ,							)
  													self.assertEqual(
  													    nested_simplify(_A   ,							decimals=4	)   ,							[
  													        [{'label': 'LABEL_1', 'score': 0.5_7_4}, {'label': 'LABEL_0', 'score': 0.4_2_6}],
  													        [{'label': 'LABEL_1', 'score': 0.5_7_4}, {'label': 'LABEL_0', 'score': 0.4_2_6}],
  													    ]   ,							)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      PreTrainedTokenizer()
  
  													# Assert that the pipeline can be initialized with a feature extractor that is not in any mapping
  													__SCREAMING_SNAKE_CASE								=      pipeline(
  													    'image-classification'   ,							model='hf-internal-testing/tiny-random-vit'   ,							tokenizer=_A	)
  
  													self.assertIs(image_classifier.tokenizer   ,							_A	)
  
  
  
  
  
  
  						@slow
  						@require_torch
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      pipeline('image-classification'   ,							model='deepmind/vision-perceiver-conv'	)
  													__SCREAMING_SNAKE_CASE								=      image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'	)
  													self.assertEqual(
  													    nested_simplify(_A   ,							decimals=4	)   ,							[
  													        {'score': 0.4_3_8_5, 'label': 'tabby, tabby cat'},
  													        {'score': 0.3_2_1, 'label': 'tiger cat'},
  													        {'score': 0.0_5_0_2, 'label': 'Egyptian cat'},
  													        {'score': 0.0_1_3_7, 'label': 'crib, cot'},
  													        {'score': 0.0_0_7, 'label': 'radiator'},
  													    ]   ,							)
  
  													__SCREAMING_SNAKE_CASE								=      pipeline('image-classification'   ,							model='deepmind/vision-perceiver-fourier'	)
  													__SCREAMING_SNAKE_CASE								=      image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'	)
  													self.assertEqual(
  													    nested_simplify(_A   ,							decimals=4	)   ,							[
  													        {'score': 0.5_6_5_8, 'label': 'tabby, tabby cat'},
  													        {'score': 0.1_3_0_9, 'label': 'tiger cat'},
  													        {'score': 0.0_7_2_2, 'label': 'Egyptian cat'},
  													        {'score': 0.0_7_0_7, 'label': 'remote control, remote'},
  													        {'score': 0.0_0_8_2, 'label': 'computer keyboard, keypad'},
  													    ]   ,							)
  
  													__SCREAMING_SNAKE_CASE								=      pipeline('image-classification'   ,							model='deepmind/vision-perceiver-learned'	)
  													__SCREAMING_SNAKE_CASE								=      image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'	)
  													self.assertEqual(
  													    nested_simplify(_A   ,							decimals=4	)   ,							[
  													        {'score': 0.3_0_2_2, 'label': 'tabby, tabby cat'},
  													        {'score': 0.2_3_6_2, 'label': 'Egyptian cat'},
  													        {'score': 0.1_8_5_6, 'label': 'tiger cat'},
  													        {'score': 0.0_3_2_4, 'label': 'remote control, remote'},
  													        {'score': 0.0_0_9_6, 'label': 'quilt, comforter, comfort, puff'},
  													    ]   ,							)
  
  
  
  
  
  
  
style_context: 
  
  
  
  from __future__ import annotations
  
  from collections.abc import Iterable
  from dataclasses import dataclass
  from typing import Any
  
  class      UpperCAmelCase_						:
  
  						'''simple docstring'''
  
  
  
  
  						UpperCamelCase__    :				List[str]       						=						('''_front''', '''_back''', '''_len''')
  
  						@dataclass
  						class      UpperCAmelCase_						:
  
  												'''simple docstring'''
  
  
  
  
  												UpperCamelCase__    :				Any       						=						None
  												UpperCamelCase__    :				Deque._Node | None       						=						None
  												UpperCamelCase__    :				Deque._Node | None       						=						None
  
  
  
  
  
  
  
  						class      UpperCAmelCase_						:
  
  												'''simple docstring'''
  
  
  
  
  												UpperCamelCase__    :				Optional[int]       						=						('''_cur''',)
  
  
  
  
  
  
  												def __init__(					self   ,							_A	):
  
  
  
  
  
  
  
  																			'''simple docstring'''
  
  																			__SCREAMING_SNAKE_CASE								=      cur
  
  
  
  
  
  
  												def __iter__(					self	):
  
  
  
  
  
  
  
  																			'''simple docstring'''
  
  																			return self
  
  
  
  
  
  
  												def  _A			(					self	):
  
  
  
  
  
  
  
  																			'''simple docstring'''
  
  																			if self._cur is None:
  																										# finished iterating
  																										raise StopIteration
  																			__SCREAMING_SNAKE_CASE								=      self._cur.val
  																			__SCREAMING_SNAKE_CASE								=      self._cur.next_node
  
  																			return val
  
  
  
  
  
  
  
  						def __init__(					self   ,							_A = None	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      None
  													__SCREAMING_SNAKE_CASE								=      None
  													__SCREAMING_SNAKE_CASE								=      0
  
  													if iterable is not None:
  																				# append every value to the deque
  																				for val in iterable:
  																											self.append(_A	)
  
  
  
  
  
  
  						def  _A			(					self   ,							_A	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      self._Node(_A   ,							_A   ,							_A	)
  													if self.is_empty():
  																				# front = back
  																				__SCREAMING_SNAKE_CASE								=      __SCREAMING_SNAKE_CASE								=      node
  																				__SCREAMING_SNAKE_CASE								=      1
  													else:
  																				# connect nodes
  																				__SCREAMING_SNAKE_CASE								=      node
  																				__SCREAMING_SNAKE_CASE								=      self._back
  																				__SCREAMING_SNAKE_CASE								=      node  # assign new back to the new node
  
  																				self._len += 1
  
  																				# make sure there were no errors
  																				assert not self.is_empty(), "Error on appending value."
  
  
  
  
  
  
  						def  _A			(					self   ,							_A	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      self._Node(_A   ,							_A   ,							_A	)
  													if self.is_empty():
  																				# front = back
  																				__SCREAMING_SNAKE_CASE								=      __SCREAMING_SNAKE_CASE								=      node
  																				__SCREAMING_SNAKE_CASE								=      1
  													else:
  																				# connect nodes
  																				__SCREAMING_SNAKE_CASE								=      self._front
  																				__SCREAMING_SNAKE_CASE								=      node
  																				__SCREAMING_SNAKE_CASE								=      node  # assign new front to the new node
  
  																				self._len += 1
  
  																				# make sure there were no errors
  																				assert not self.is_empty(), "Error on appending value."
  
  
  
  
  
  
  						def  _A			(					self   ,							_A	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													for val in iterable:
  																				self.append(_A	)
  
  
  
  
  
  
  						def  _A			(					self   ,							_A	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													for val in iterable:
  																				self.appendleft(_A	)
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													assert not self.is_empty(), "Deque is empty."
  
  													__SCREAMING_SNAKE_CASE								=      self._back
  													__SCREAMING_SNAKE_CASE								=      self._back.prev_node  # set new back
  													# drop the last node - python will deallocate memory automatically
  													__SCREAMING_SNAKE_CASE								=      None
  
  													self._len -= 1
  
  													return topop.val
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													assert not self.is_empty(), "Deque is empty."
  
  													__SCREAMING_SNAKE_CASE								=      self._front
  													__SCREAMING_SNAKE_CASE								=      self._front.next_node  # set new front and drop the first node
  													__SCREAMING_SNAKE_CASE								=      None
  
  													self._len -= 1
  
  													return topop.val
  
  
  
  
  
  
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													return self._front is None
  
  
  
  
  
  
  						def __len__(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													return self._len
  
  
  
  
  
  
  						def __eq__(					self   ,							_A	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													if not isinstance(_A   ,							_A	):
  																				return NotImplemented
  
  													__SCREAMING_SNAKE_CASE								=      self._front
  													__SCREAMING_SNAKE_CASE								=      other._front
  
  													# if the length of the dequeues are not the same, they are not equal
  													if len(self	) != len(_A	):
  																				return False
  
  													while me is not None and oth is not None:
  																				# compare every value
  																				if me.val != oth.val:
  																											return False
  																				__SCREAMING_SNAKE_CASE								=      me.next_node
  																				__SCREAMING_SNAKE_CASE								=      oth.next_node
  
  													return True
  
  
  
  
  
  
  						def __iter__(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													return Deque._Iterator(self._front	)
  
  
  
  
  
  
  						def __repr__(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      []
  													__SCREAMING_SNAKE_CASE								=      self._front
  													while aux is not None:
  																				# append the values in a list to display
  																				values_list.append(aux.val	)
  																				__SCREAMING_SNAKE_CASE								=      aux.next_node
  
  													return f"""[{", ".join(repr(_A	) for val in values_list	)}]"""
  
  
  if __name__ == "__main__":
  			import doctest
  
  			doctest.testmod()
  
  
  
  
  
  
  