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







				"""simple docstring"""






				@slow
				def 		_lowerCAmelCase		(      self							:							str):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Any			  =    AutoImageProcessor.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip""")
											_SCREAMING_SNAKE_CASE		:						str			  =    AutoModelForImageClassification.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip""")
											model.to(_A)

											from datasets import load_dataset

											_SCREAMING_SNAKE_CASE		:						Any			  =    load_dataset("""nielsr/rvlcdip-demo""")

											_SCREAMING_SNAKE_CASE		:						Any			  =    dataset["""train"""][0]["""image"""].convert("""RGB""")

											_SCREAMING_SNAKE_CASE		:						str			  =    image_processor(_A      ,    return_tensors="""pt""").to(_A)

											# forward pass
											with torch.no_grad():
																		_SCREAMING_SNAKE_CASE		:						Any			  =    model(**_A)
																		_SCREAMING_SNAKE_CASE		:						List[Any]			  =    outputs.logits

											_SCREAMING_SNAKE_CASE		:						List[str]			  =    torch.Size((1, 1_6))
											self.assertEqual(logits.shape      ,    _A)

											_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    torch.tensor(
											    [-0.4_158, -0.4_092, -0.4_347]      ,    device=_A      ,    dtype=torch.float      ,    )
											self.assertTrue(torch.allclose(logits[0, :3]      ,    _A      ,    atol=1e-4))



"""simple docstring"""





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCAmelCase_     =	{
    '''configuration_clipseg''': [
        '''CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''CLIPSegConfig''',
        '''CLIPSegTextConfig''',
        '''CLIPSegVisionConfig''',
    ],
    '''processing_clipseg''': ['''CLIPSegProcessor'''],
}

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			lowerCAmelCase_     =	[
			    '''CLIPSEG_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''CLIPSegModel''',
			    '''CLIPSegPreTrainedModel''',
			    '''CLIPSegTextModel''',
			    '''CLIPSegVisionModel''',
			    '''CLIPSegForImageSegmentation''',
			]

if TYPE_CHECKING:
			from .configuration_clipseg import (
			    CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP,
			    CLIPSegConfig,
			    CLIPSegTextConfig,
			    CLIPSegVisionConfig,
			)
			from .processing_clipseg import CLIPSegProcessor

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_clipseg import (
						    CLIPSEG_PRETRAINED_MODEL_ARCHIVE_LIST,
						    CLIPSegForImageSegmentation,
						    CLIPSegModel,
						    CLIPSegPreTrainedModel,
						    CLIPSegTextModel,
						    CLIPSegVisionModel,
						)

else:
			import sys

			lowerCAmelCase_     =	_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


