






'''simple docstring'''




from ..utils import DummyObject, requires_backends







class       __lowercase					(metaclass=__lowerCamelCase    ):
 _lowerCamelCase              =  ['''torch''', '''scipy''']

 def __init__(      self   :						List[Any]  ,					*UpperCAmelCase_   :						Any  ,					**UpperCAmelCase_   :						int):
   requires_backends(self  ,					['torch', 'scipy'])

 @classmethod
 def      __UpperCamelCase							(      cls   :						Union[str, Any]  ,					*UpperCAmelCase_   :						Any  ,					**UpperCAmelCase_   :						List[Any]):
   requires_backends(cls  ,					['torch', 'scipy'])





 @classmethod
 def      __UpperCamelCase							(      cls   :						Union[str, Any]  ,					*UpperCAmelCase_   :						Optional[Any]  ,					**UpperCAmelCase_   :						Any):
   requires_backends(cls  ,					['torch', 'scipy'])












'''simple docstring'''




import unittest

from transformers import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device


if is_torch_available():
		import torch

		from transformers import AutoModelForImageClassification

if is_vision_available():
		from transformers import AutoImageProcessor







@require_torch
@require_vision
class       __lowercase					(unittest.TestCase    ):

	@slow
	def      __UpperCamelCase							(      self   :						int):
			UpperCamelCase__				:					Union[str, Any]					=					AutoImageProcessor.from_pretrained('microsoft/dit-base-finetuned-rvlcdip')
			UpperCamelCase__				:					List[str]					=					AutoModelForImageClassification.from_pretrained('microsoft/dit-base-finetuned-rvlcdip')
			model.to(UpperCAmelCase_)

			from datasets import load_dataset

			UpperCamelCase__				:					Optional[Any]					=					load_dataset('nielsr/rvlcdip-demo')

			UpperCamelCase__				:					int					=					dataset['train'][0]['image'].convert('RGB')

			UpperCamelCase__				:					Union[str, Any]					=					image_processor(UpperCAmelCase_  ,					return_tensors='pt').to(UpperCAmelCase_)

			# forward pass
			with torch.no_grad():
					UpperCamelCase__				:					Optional[Any]					=					model(**UpperCAmelCase_)
					UpperCamelCase__				:					Tuple					=					outputs.logits

			UpperCamelCase__				:					str					=					torch.Size((1, 16))
			self.assertEqual(logits.shape  ,					UpperCAmelCase_)

			UpperCamelCase__				:					Tuple					=					torch.tensor(
			    [-0.41_58, -0.40_92, -0.43_47]  ,					device=UpperCAmelCase_  ,					dtype=torch.float  ,					)
			self.assertTrue(torch.allclose(logits[0, :3]  ,					UpperCAmelCase_  ,					atol=1e-4))




