






"""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 					_UpperCAmelCase       ( unittest.TestCase							):




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

							from datasets import load_dataset

							lowercase_ : List[str]							       =   load_dataset('''nielsr/rvlcdip-demo'''   )

							lowercase_ : Tuple							       =   dataset['''train'''][0]['''image'''].convert('''RGB'''   )

							lowercase_ : Tuple							       =   image_processor(UpperCamelCase__    ,						return_tensors='''pt'''   ).to(UpperCamelCase__   )

							# forward pass
							with torch.no_grad():
									lowercase_ : Dict							       =   model(**UpperCamelCase__   )
									lowercase_ : List[Any]							       =   outputs.logits

							lowercase_ : Any							       =   torch.Size((1, 16)   )
							self.assertEqual(logits.shape    ,						UpperCamelCase__   )

							lowercase_ : Optional[int]							       =   torch.tensor(
							    [-0.4158, -0.4092, -0.4347]    ,						device=UpperCamelCase__    ,						dtype=torch.float    ,						)
							self.assertTrue(torch.allclose(logits[0, :3]    ,						UpperCamelCase__    ,						atol=1e-4   )   )









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  A		(  unittest.TestCase     ):



		@slow
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  AutoImageProcessor.from_pretrained('''microsoft/dit-base-finetuned-rvlcdip'''   )
								lowerCAmelCase_      			=  AutoModelForImageClassification.from_pretrained('''microsoft/dit-base-finetuned-rvlcdip'''   )
								model.to(UpperCamelCase__   )

								from datasets import load_dataset

								lowerCAmelCase_      			=  load_dataset('''nielsr/rvlcdip-demo'''   )

								lowerCAmelCase_      			=  dataset['''train'''][0]['''image'''].convert('''RGB'''   )

								lowerCAmelCase_      			=  image_processor(UpperCamelCase__,	return_tensors='''pt'''   ).to(UpperCamelCase__   )

								# forward pass
								with torch.no_grad():
														lowerCAmelCase_      			=  model(**UpperCamelCase__   )
														lowerCAmelCase_      			=  outputs.logits

								lowerCAmelCase_      			=  torch.Size((1, 16)   )
								self.assertEqual(logits.shape,	UpperCamelCase__   )

								lowerCAmelCase_      			=  torch.tensor(
								    [-0.4_158, -0.4_092, -0.4_347],	device=UpperCamelCase__,	dtype=torch.float,	)
								self.assertTrue(torch.allclose(logits[0, :3],	UpperCamelCase__,	atol=1E-4   )   )




