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







	@slow
	def  snake_case__     (     self      :List[str]			)		->      List[Any]:







				"""simple docstring"""






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

				from datasets import load_dataset

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

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

				SCREAMING_SNAKE_CASE     						= image_processor(__UpperCamelCase   ,     return_tensors='''pt'''			).to(__UpperCamelCase			)

				# forward pass
				with torch.no_grad():
							SCREAMING_SNAKE_CASE     						= model(**__UpperCamelCase			)
							SCREAMING_SNAKE_CASE     						= outputs.logits

				SCREAMING_SNAKE_CASE     						= torch.Size((1, 1_6)			)
				self.assertEqual(logits.shape   ,     __UpperCamelCase			)

				SCREAMING_SNAKE_CASE     						= 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			)			)
import numpy as np






def     lowerCAmelCase_			(   _SCREAMING_SNAKE_CASE     :				np.array			):
						return (2 / (1 + np.exp(-2 * vector			))) - 1


if __name__ == "__main__":
	import doctest

	doctest.testmod()






