






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 						__a					(					self      ):
											_lowercase							:   List[Any] 							=   AutoImageProcessor.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'      )
											_lowercase							:   List[Any] 							=   AutoModelForImageClassification.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'      )
											model.to(_lowerCAmelCase      )

											from datasets import load_dataset

											_lowercase							:   Union[str, Any] 							=   load_dataset('nielsr/rvlcdip-demo'      )

											_lowercase							:   Any 							=   dataset['train'][0]['image'].convert('RGB'      )

											_lowercase							:   List[str] 							=   image_processor(_lowerCAmelCase ,						return_tensors='pt'      ).to(_lowerCAmelCase      )

											# forward pass
											with torch.no_grad():
																		_lowercase							:   Dict 							=   model(**_lowerCAmelCase      )
																		_lowercase							:   Any 							=   outputs.logits

											_lowercase							:   str 							=   torch.Size((1, 1_6)      )
											self.assertEqual(logits.shape ,						_lowerCAmelCase      )

											_lowercase							:   Union[str, Any] 							=   torch.tensor(
											    [-0.41_58, -0.40_92, -0.43_47] ,						device=_lowerCAmelCase ,						dtype=torch.float ,						)
											self.assertTrue(torch.allclose(logits[0, :3] ,						_lowerCAmelCase ,						atol=1E-4      )      )








import numpy as np
def 							UpperCamelCase_(					_A :np.array	)->		np.array:
			return 1 / (1 + np.exp(-vector	))


if __name__ == "__main__":
						import doctest

						doctest.testmod()


