import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import DetrConfig, MaskFormerConfig, SwinConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import MaskFormerForInstanceSegmentation, MaskFormerModel

		if is_vision_available():
				from transformers import MaskFormerImageProcessor

if is_vision_available():
		from PIL import Image






class 		a__						:

					def __init__(    self      :       Union[str, Any],_A      :       str,_A      :       int=2,_A      :       Tuple=True,_A      :       str=False,_A      :       Union[str, Any]=10,_A      :       Optional[int]=3,_A      :       Union[str, Any]=32 * 4,_A      :       List[str]=32 * 6,_A      :       Any=4,_A      :       Optional[Any]=32,):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_  :		List[str]				      =    parent
							SCREAMING_SNAKE_CASE_  :		int				      =    batch_size
							SCREAMING_SNAKE_CASE_  :		List[Any]				      =    is_training
							SCREAMING_SNAKE_CASE_  :		Tuple				      =    use_auxiliary_loss
							SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    num_queries
							SCREAMING_SNAKE_CASE_  :		int				      =    num_channels
							SCREAMING_SNAKE_CASE_  :		Any				      =    min_size
							SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    max_size
							SCREAMING_SNAKE_CASE_  :		str				      =    num_labels
							SCREAMING_SNAKE_CASE_  :		Any				      =    mask_feature_size

					def 				__UpperCamelCase   (    self      :       Optional[Any]    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_  :		List[str]				      =    floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]    ).to(
							    _A    )

							SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    torch.ones([self.batch_size, self.min_size, self.max_size],device=_A    )

							SCREAMING_SNAKE_CASE_  :		Tuple				      =    (
							    torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size],device=_A    ) > 0.5
							).float()
							SCREAMING_SNAKE_CASE_  :		List[str]				      =    (torch.rand((self.batch_size, self.num_labels),device=_A    ) > 0.5).long()

							SCREAMING_SNAKE_CASE_  :		str				      =    self.get_config()
							return config, pixel_values, pixel_mask, mask_labels, class_labels

					def 				__UpperCamelCase   (    self      :       List[Any]    ):







							"""simple docstring"""






							return MaskFormerConfig.from_backbone_and_decoder_configs(
							    backbone_config=SwinConfig(
							        depths=[1, 1, 1, 1],),decoder_config=DetrConfig(
							        decoder_ffn_dim=128,num_queries=self.num_queries,decoder_attention_heads=2,d_model=self.mask_feature_size,),mask_feature_size=self.mask_feature_size,fpn_feature_size=self.mask_feature_size,num_channels=self.num_channels,num_labels=self.num_labels,)

					def 				__UpperCamelCase   (    self      :       Any    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_  :		str				      =    self.prepare_config_and_inputs()
							SCREAMING_SNAKE_CASE_  :		Any				      =    {"pixel_values": pixel_values, "pixel_mask": pixel_mask}
							return config, inputs_dict

					def 				__UpperCamelCase   (    self      :       Tuple,_A      :       Dict,_A      :       Any    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_  :		int				      =    output.encoder_hidden_states
							SCREAMING_SNAKE_CASE_  :		str				      =    output.pixel_decoder_hidden_states
							SCREAMING_SNAKE_CASE_  :		int				      =    output.transformer_decoder_hidden_states

							self.parent.assertTrue(len(_A    ),len(config.backbone_config.depths    )    )
							self.parent.assertTrue(len(_A    ),len(config.backbone_config.depths    )    )
							self.parent.assertTrue(len(_A    ),config.decoder_config.decoder_layers    )

					def 				__UpperCamelCase   (    self      :       Tuple,_A      :       Any,_A      :       Optional[Any],_A      :       Tuple,_A      :       Tuple=False    ):







							"""simple docstring"""






							with torch.no_grad():
									SCREAMING_SNAKE_CASE_  :		Dict				      =    MaskFormerModel(config=_A    )
									model.to(_A    )
									model.eval()

									SCREAMING_SNAKE_CASE_  :		int				      =    model(pixel_values=_A,pixel_mask=_A    )
									SCREAMING_SNAKE_CASE_  :		List[str]				      =    model(_A,output_hidden_states=_A    )
							# the correct shape of output.transformer_decoder_hidden_states ensure the correcteness of the
							# encoder and pixel decoder
							self.parent.assertEqual(
							    output.transformer_decoder_last_hidden_state.shape,(self.batch_size, self.num_queries, self.mask_feature_size),)
							# let's ensure the other two hidden state exists
							self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None    )
							self.parent.assertTrue(output.encoder_last_hidden_state is not None    )

							if output_hidden_states:
									self.check_output_hidden_state(_A,_A    )






					def 				__UpperCamelCase   (    self      :       int,_A      :       Optional[int],_A      :       Optional[int],_A      :       List[Any],_A      :       Any,_A      :       List[Any]    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    MaskFormerForInstanceSegmentation(config=_A    )
							model.to(_A    )
							model.eval()

							def comm_check_on_output(_A      :       Optional[int]    ):
									# let's still check that all the required stuff is there
									self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None    )
									self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None    )
									self.parent.assertTrue(result.encoder_last_hidden_state is not None    )
									# okay, now we need to check the logits shape
									# due to the encoder compression, masks have a //4 spatial size
									self.parent.assertEqual(
									    result.masks_queries_logits.shape,(self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4),)
									# + 1 for null class
									self.parent.assertEqual(
									    result.class_queries_logits.shape,(self.batch_size, self.num_queries, self.num_labels + 1)    )

							with torch.no_grad():
									SCREAMING_SNAKE_CASE_  :		List[str]				      =    model(pixel_values=_A,pixel_mask=_A    )
									SCREAMING_SNAKE_CASE_  :		str				      =    model(_A    )

									comm_check_on_output(_A    )

									SCREAMING_SNAKE_CASE_  :		Dict				      =    model(
									    pixel_values=_A,pixel_mask=_A,mask_labels=_A,class_labels=_A    )

							comm_check_on_output(_A    )

							self.parent.assertTrue(result.loss is not None    )
							self.parent.assertEqual(result.loss.shape,torch.Size([1]    )    )







@require_torch
class 		a__						(					A__    ,		A__    ,		unittest.TestCase					):
					A	       =							(MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
					A	       =							(
					    {'feature-extraction': MaskFormerModel, 'image-segmentation': MaskFormerForInstanceSegmentation}
					    if is_torch_available()
					    else {}
					)

					A	       =							False
					A	       =							False
					A	       =							False
					A	       =							False

					def 				__UpperCamelCase   (    self      :       List[Any]    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_  :		str				      =    MaskFormerModelTester(self    )
							SCREAMING_SNAKE_CASE_  :		Dict				      =    ConfigTester(self,config_class=_A,has_text_modality=_A    )

					def 				__UpperCamelCase   (    self      :       List[str]    ):







							"""simple docstring"""






							self.config_tester.run_common_tests()

					def 				__UpperCamelCase   (    self      :       List[str]    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_  :		List[str]				      =    self.model_tester.prepare_config_and_inputs_for_common()
							self.model_tester.create_and_check_maskformer_model(_A,**_A,output_hidden_states=_A    )

					def 				__UpperCamelCase   (    self      :       Tuple    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_  :		List[Any]				      =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*_A    )

					@unittest.skip(reason="MaskFormer does not use inputs_embeds"    )
					def 				__UpperCamelCase   (    self      :       str    ):







							"""simple docstring"""






							pass

					@unittest.skip(reason="MaskFormer does not have a get_input_embeddings method"    )
					def 				__UpperCamelCase   (    self      :       int    ):







							"""simple docstring"""






							pass

					@unittest.skip(reason="MaskFormer is not a generative model"    )
					def 				__UpperCamelCase   (    self      :       Optional[int]    ):







							"""simple docstring"""






							pass

					@unittest.skip(reason="MaskFormer does not use token embeddings"    )
					def 				__UpperCamelCase   (    self      :       Any    ):







							"""simple docstring"""






							pass

					@require_torch_multi_gpu
					@unittest.skip(
					    reason="MaskFormer has some layers using `add_module` which doesn't work well with `nn.DataParallel`"    )
					def 				__UpperCamelCase   (    self      :       Optional[int]    ):







							"""simple docstring"""






							pass

					@unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."    )
					def 				__UpperCamelCase   (    self      :       int    ):







							"""simple docstring"""






							pass

					def 				__UpperCamelCase   (    self      :       Dict    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_  :		List[str]				      =    self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
									SCREAMING_SNAKE_CASE_  :		Tuple				      =    model_class(_A    )
									SCREAMING_SNAKE_CASE_  :		Tuple				      =    inspect.signature(model.forward    )
									# signature.parameters is an OrderedDict => so arg_names order is deterministic
									SCREAMING_SNAKE_CASE_  :		int				      =    [*signature.parameters.keys()]

									SCREAMING_SNAKE_CASE_  :		Any				      =    ["pixel_values"]
									self.assertListEqual(arg_names[:1],_A    )

					@slow
					def 				__UpperCamelCase   (    self      :       List[str]    ):







							"""simple docstring"""






							for model_name in ["facebook/maskformer-swin-small-coco"]:
									SCREAMING_SNAKE_CASE_  :		Optional[Any]				      =    MaskFormerModel.from_pretrained(_A    )
									self.assertIsNotNone(_A    )

					def 				__UpperCamelCase   (    self      :       int    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_  :		List[str]				      =    (self.model_tester.min_size,) * 2
							SCREAMING_SNAKE_CASE_  :		Union[str, Any]				      =    {
							    "pixel_values": torch.randn((2, 3, *size),device=_A    ),
							    "mask_labels": torch.randn((2, 10, *size),device=_A    ),
							    "class_labels": torch.zeros(2,10,device=_A    ).long(),
							}

							SCREAMING_SNAKE_CASE_  :		Dict				      =    MaskFormerForInstanceSegmentation(MaskFormerConfig()    ).to(_A    )
							SCREAMING_SNAKE_CASE_  :		Optional[Any]				      =    model(**_A    )
							self.assertTrue(outputs.loss is not None    )

					def 				__UpperCamelCase   (    self      :       Union[str, Any]    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_  :		Tuple				      =    self.model_tester.prepare_config_and_inputs_for_common()
							self.model_tester.create_and_check_maskformer_model(_A,**_A,output_hidden_states=_A    )

					def 				__UpperCamelCase   (    self      :       Tuple    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
									SCREAMING_SNAKE_CASE_  :		int				      =    model_class(_A    ).to(_A    )
									SCREAMING_SNAKE_CASE_  :		Dict				      =    model(**_A,output_attentions=_A    )
									self.assertTrue(outputs.attentions is not None    )

					def 				__UpperCamelCase   (    self      :       int    ):







							"""simple docstring"""






							if not self.model_tester.is_training:
									return
							# only MaskFormerForInstanceSegmentation has the loss
							SCREAMING_SNAKE_CASE_  :		int				      =    self.all_model_classes[1]
							SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_  :		List[Any]				      =    self.model_tester.prepare_config_and_inputs()

							SCREAMING_SNAKE_CASE_  :		Dict				      =    model_class(_A    )
							model.to(_A    )
							model.train()

							SCREAMING_SNAKE_CASE_  :		Union[str, Any]				      =    model(_A,mask_labels=_A,class_labels=_A    ).loss
							loss.backward()






					def 				__UpperCamelCase   (    self      :       Optional[int]    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_  :		List[str]				      =    self.all_model_classes[1]
							SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_  :		Tuple				      =    self.model_tester.prepare_config_and_inputs()
							SCREAMING_SNAKE_CASE_  :		Dict				      =    True
							SCREAMING_SNAKE_CASE_  :		Tuple				      =    True

							SCREAMING_SNAKE_CASE_  :		Dict				      =    model_class(_A    )
							model.to(_A    )
							model.train()

							SCREAMING_SNAKE_CASE_  :		Tuple				      =    model(_A,mask_labels=_A,class_labels=_A    )

							SCREAMING_SNAKE_CASE_  :		List[Any]				      =    outputs.encoder_hidden_states[0]
							encoder_hidden_states.retain_grad()

							SCREAMING_SNAKE_CASE_  :		Any				      =    outputs.pixel_decoder_hidden_states[0]
							pixel_decoder_hidden_states.retain_grad()
							# we requires_grad=True in inputs_embeds (line 2152), the original implementation don't
							SCREAMING_SNAKE_CASE_  :		List[Any]				      =    outputs.transformer_decoder_hidden_states[0]
							transformer_decoder_hidden_states.retain_grad()

							SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    outputs.attentions[0]
							attentions.retain_grad()

							outputs.loss.backward(retain_graph=_A    )

							self.assertIsNotNone(encoder_hidden_states.grad    )
							self.assertIsNotNone(pixel_decoder_hidden_states.grad    )
							self.assertIsNotNone(transformer_decoder_hidden_states.grad    )
							self.assertIsNotNone(attentions.grad    )







__lowerCamelCase					:	Dict       =  1E-4




def       _snake_case	(   ):
		"""simple docstring"""







		SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"	)
		return image







@require_vision
@slow
class 		a__						(					unittest.TestCase					):

					@cached_property
					def 				__UpperCamelCase   (    self      :       str    ):







							"""simple docstring"""






							return (
							    MaskFormerImageProcessor.from_pretrained("facebook/maskformer-swin-small-coco"    )
							    if is_vision_available()
							    else None
							)

					def 				__UpperCamelCase   (    self      :       str    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    MaskFormerModel.from_pretrained("facebook/maskformer-swin-small-coco"    ).to(_A    )
							SCREAMING_SNAKE_CASE_  :		Union[str, Any]				      =    self.default_image_processor
							SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    prepare_img()
							SCREAMING_SNAKE_CASE_  :		Union[str, Any]				      =    image_processor(_A,return_tensors="pt"    ).to(_A    )
							SCREAMING_SNAKE_CASE_  :		str				      =    inputs["pixel_values"].shape
							# check size is divisible by 32
							self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0    )
							# check size
							self.assertEqual(_A,(1, 3, 800, 1088)    )

							with torch.no_grad():
									SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    model(**_A    )

							SCREAMING_SNAKE_CASE_  :		List[str]				      =    torch.tensor(
							    [[-0.0482, 0.9228, 0.4951], [-0.2547, 0.8017, 0.8527], [-0.0069, 0.3385, -0.0089]]    ).to(_A    )
							self.assertTrue(
							    torch.allclose(
							        outputs.encoder_last_hidden_state[0, 0, :3, :3],_A,atol=_A    )    )

							SCREAMING_SNAKE_CASE_  :		Optional[Any]				      =    torch.tensor(
							    [[-0.8422, -0.8434, -0.9718], [-1.0144, -0.5565, -0.4195], [-1.0038, -0.4484, -0.1961]]    ).to(_A    )
							self.assertTrue(
							    torch.allclose(
							        outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3],_A,atol=_A    )    )

							SCREAMING_SNAKE_CASE_  :		List[str]				      =    torch.tensor(
							    [[0.2852, -0.0159, 0.9735], [0.6254, 0.1858, 0.8529], [-0.0680, -0.4116, 1.8413]]    ).to(_A    )
							self.assertTrue(
							    torch.allclose(
							        outputs.transformer_decoder_last_hidden_state[0, :3, :3],_A,atol=_A    )    )

					def 				__UpperCamelCase   (    self      :       Optional[int]    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_  :		Tuple				      =    (
							    MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-small-coco"    )
							    .to(_A    )
							    .eval()
							)
							SCREAMING_SNAKE_CASE_  :		Any				      =    self.default_image_processor
							SCREAMING_SNAKE_CASE_  :		Dict				      =    prepare_img()
							SCREAMING_SNAKE_CASE_  :		str				      =    image_processor(_A,return_tensors="pt"    ).to(_A    )
							SCREAMING_SNAKE_CASE_  :		Optional[Any]				      =    inputs["pixel_values"].shape
							# check size is divisible by 32
							self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0    )
							# check size
							self.assertEqual(_A,(1, 3, 800, 1088)    )

							with torch.no_grad():
									SCREAMING_SNAKE_CASE_  :		Tuple				      =    model(**_A    )
							# masks_queries_logits
							SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    outputs.masks_queries_logits
							self.assertEqual(
							    masks_queries_logits.shape,(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4),)
							SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    [
							    [-1.3737124, -1.7724937, -1.9364233],
							    [-1.5977281, -1.9867939, -2.1523695],
							    [-1.5795398, -1.9269832, -2.093942],
							]
							SCREAMING_SNAKE_CASE_  :		Tuple				      =    torch.tensor(_A    ).to(_A    )
							self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3],_A,atol=_A    )    )
							# class_queries_logits
							SCREAMING_SNAKE_CASE_  :		Union[str, Any]				      =    outputs.class_queries_logits
							self.assertEqual(
							    class_queries_logits.shape,(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)    )
							SCREAMING_SNAKE_CASE_  :		Optional[Any]				      =    torch.tensor(
							    [
							        [1.65_12E00, -5.25_72E00, -3.35_19E00],
							        [3.61_69E-02, -5.90_25E00, -2.93_13E00],
							        [1.07_66E-04, -7.76_30E00, -5.12_63E00],
							    ]    ).to(_A    )
							self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3],_A,atol=_A    )    )

					def 				__UpperCamelCase   (    self      :       int    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_  :		List[str]				      =    (
							    MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-resnet101-coco-stuff"    )
							    .to(_A    )
							    .eval()
							)
							SCREAMING_SNAKE_CASE_  :		Any				      =    self.default_image_processor
							SCREAMING_SNAKE_CASE_  :		Tuple				      =    prepare_img()
							SCREAMING_SNAKE_CASE_  :		Dict				      =    image_processor(_A,return_tensors="pt"    ).to(_A    )
							SCREAMING_SNAKE_CASE_  :		List[str]				      =    inputs["pixel_values"].shape
							# check size is divisible by 32
							self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0    )
							# check size
							self.assertEqual(_A,(1, 3, 800, 1088)    )

							with torch.no_grad():
									SCREAMING_SNAKE_CASE_  :		List[Any]				      =    model(**_A    )
							# masks_queries_logits
							SCREAMING_SNAKE_CASE_  :		Dict				      =    outputs.masks_queries_logits
							self.assertEqual(
							    masks_queries_logits.shape,(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4),)
							SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    [[-0.9046, -2.6366, -4.6062], [-3.4179, -5.7890, -8.8057], [-4.9179, -7.6560, -10.7711]]
							SCREAMING_SNAKE_CASE_  :		str				      =    torch.tensor(_A    ).to(_A    )
							self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3],_A,atol=_A    )    )
							# class_queries_logits
							SCREAMING_SNAKE_CASE_  :		Dict				      =    outputs.class_queries_logits
							self.assertEqual(
							    class_queries_logits.shape,(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)    )
							SCREAMING_SNAKE_CASE_  :		List[Any]				      =    torch.tensor(
							    [[4.7188, -3.2585, -2.8857], [6.6871, -2.9181, -1.2487], [7.2449, -2.2764, -2.1874]]    ).to(_A    )
							self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3],_A,atol=_A    )    )






					def 				__UpperCamelCase   (    self      :       Tuple    ):







							"""simple docstring"""






							SCREAMING_SNAKE_CASE_  :		Optional[Any]				      =    (
							    MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-small-coco"    )
							    .to(_A    )
							    .eval()
							)
							SCREAMING_SNAKE_CASE_  :		Any				      =    self.default_image_processor

							SCREAMING_SNAKE_CASE_  :		Union[str, Any]				      =    image_processor(
							    [np.zeros((3, 800, 1333)    ), np.zeros((3, 800, 1333)    )],segmentation_maps=[np.zeros((384, 384)    ).astype(np.floataa    ), np.zeros((384, 384)    ).astype(np.floataa    )],return_tensors="pt",)

							SCREAMING_SNAKE_CASE_  :		Optional[Any]				      =    inputs["pixel_values"].to(_A    )
							SCREAMING_SNAKE_CASE_  :		Optional[Any]				      =    [el.to(_A    ) for el in inputs["mask_labels"]]
							SCREAMING_SNAKE_CASE_  :		int				      =    [el.to(_A    ) for el in inputs["class_labels"]]

							with torch.no_grad():
									SCREAMING_SNAKE_CASE_  :		Union[str, Any]				      =    model(**_A    )

							self.assertTrue(outputs.loss is not None    )

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


__lowerCamelCase					:	Union[str, Any]       =  {
    '''configuration_chinese_clip''': [
        '''CHINESE_CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''ChineseCLIPConfig''',
        '''ChineseCLIPOnnxConfig''',
        '''ChineseCLIPTextConfig''',
        '''ChineseCLIPVisionConfig''',
    ],
    '''processing_chinese_clip''': ['''ChineseCLIPProcessor'''],
}

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCamelCase					:	Any       =  ['''ChineseCLIPFeatureExtractor''']
		__lowerCamelCase					:	Optional[int]       =  ['''ChineseCLIPImageProcessor''']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCamelCase					:	int       =  [
		    '''CHINESE_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''ChineseCLIPModel''',
		    '''ChineseCLIPPreTrainedModel''',
		    '''ChineseCLIPTextModel''',
		    '''ChineseCLIPVisionModel''',
		]

if TYPE_CHECKING:
		from .configuration_chinese_clip import (
		    CHINESE_CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    ChineseCLIPConfig,
		    ChineseCLIPOnnxConfig,
		    ChineseCLIPTextConfig,
		    ChineseCLIPVisionConfig,
		)
		from .processing_chinese_clip import ChineseCLIPProcessor

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .feature_extraction_chinese_clip import ChineseCLIPFeatureExtractor, ChineseCLIPImageProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_chinese_clip import (
				    CHINESE_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ChineseCLIPModel,
				    ChineseCLIPPreTrainedModel,
				    ChineseCLIPTextModel,
				    ChineseCLIPVisionModel,
				)

else:
		import sys

		__lowerCamelCase					:	Any       =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
