




import inspect
import unittest

from transformers import DataaVecVisionConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch
 from torch import nn

 from transformers import (
     MODEL_MAPPING,
     DataaVecVisionForImageClassification,
     DataaVecVisionForSemanticSegmentation,
     DataaVecVisionModel,
 )
 from transformers.models.dataavec.modeling_dataavec_vision import DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
 from PIL import Image

 from transformers import BeitImageProcessor







class 		__UpperCAmelCase:





     """simple docstring"""



     def __init__(   self			:							Optional[int]    ,					A			:							Any    ,					A			:							int=1_00    ,					A			:							Union[str, Any]=13    ,					A			:							Optional[int]=30    ,					A			:							str=2    ,					A			:							Optional[Any]=3    ,					A			:							Optional[Any]=True    ,					A			:							Dict=True    ,					A			:							str=32    ,					A			:							List[Any]=4    ,					A			:							Union[str, Any]=4    ,					A			:							str=37    ,					A			:							Any="gelu"    ,					A			:							Optional[int]=0.1    ,					A			:							str=0.1    ,					A			:							List[str]=10    ,					A			:							str=0.0_2    ,					A			:							Dict=3    ,					A			:							List[Any]=None    ,					A			:							str=[0, 1, 2, 3]    ,					)      ->      List[Any]:






         """simple docstring"""
         a__  			=							parent
         a__  			=							1_00
         a__  			=							batch_size
         a__  			=							image_size
         a__  			=							patch_size
         a__  			=							num_channels
         a__  			=							is_training
         a__  			=							use_labels
         a__  			=							hidden_size
         a__  			=							num_hidden_layers
         a__  			=							num_attention_heads
         a__  			=							intermediate_size
         a__  			=							hidden_act
         a__  			=							hidden_dropout_prob
         a__  			=							attention_probs_dropout_prob
         a__  			=							type_sequence_label_size
         a__  			=							initializer_range
         a__  			=							scope
         a__  			=							out_indices
         a__  			=							num_labels

         # in BeiT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
         a__  			=							(image_size // patch_size) ** 2
         a__  			=							num_patches + 1

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Tuple     )      ->      Optional[int]:






         """simple docstring"""
         a__  			=							floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

         a__  			=							None
         a__  			=							None
         if self.use_labels:
             a__  			=							ids_tensor([self.batch_size]    ,					self.type_sequence_label_size     )
             a__  			=							ids_tensor([self.batch_size, self.image_size, self.image_size]    ,					self.num_labels     )

         a__  			=							self.get_config()

         return config, pixel_values, labels, pixel_labels

     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[Any]     )      ->      Optional[Any]:






         """simple docstring"""
         return DataaVecVisionConfig(
             vocab_size=self.vocab_size    ,					image_size=self.image_size    ,					patch_size=self.patch_size    ,					num_channels=self.num_channels    ,					hidden_size=self.hidden_size    ,					num_hidden_layers=self.num_hidden_layers    ,					num_attention_heads=self.num_attention_heads    ,					intermediate_size=self.intermediate_size    ,					hidden_act=self.hidden_act    ,					hidden_dropout_prob=self.hidden_dropout_prob    ,					attention_probs_dropout_prob=self.attention_probs_dropout_prob    ,					is_decoder=_snake_case    ,					initializer_range=self.initializer_range    ,					out_indices=self.out_indices    ,					)

     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[str]    ,					A			:							List[Any]    ,					A			:							Dict    ,					A			:							int    ,					A			:							Optional[Any]     )      ->      Optional[Any]:






         """simple docstring"""
         a__  			=							DataaVecVisionModel(config=_snake_case     )
         model.to(_snake_case     )
         model.eval()
         a__  			=							model(_snake_case     )
         # expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
         a__  			=							(self.image_size // self.patch_size) ** 2
         self.parent.assertEqual(result.last_hidden_state.shape    ,					(self.batch_size, num_patches + 1, self.hidden_size)     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[Any]    ,					A			:							Tuple    ,					A			:							List[Any]    ,					A			:							str    ,					A			:							Dict     )      ->      List[Any]:






         """simple docstring"""
         a__  			=							self.type_sequence_label_size
         a__  			=							DataaVecVisionForImageClassification(_snake_case     )
         model.to(_snake_case     )
         model.eval()
         a__  			=							model(_snake_case    ,					labels=_snake_case     )
         self.parent.assertEqual(result.logits.shape    ,					(self.batch_size, self.type_sequence_label_size)     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Optional[int]    ,					A			:							Optional[Any]    ,					A			:							Union[str, Any]    ,					A			:							str    ,					A			:							Any     )      ->      Optional[Any]:






         """simple docstring"""
         a__  			=							self.num_labels
         a__  			=							DataaVecVisionForSemanticSegmentation(_snake_case     )
         model.to(_snake_case     )
         model.eval()
         a__  			=							model(_snake_case     )
         self.parent.assertEqual(
             result.logits.shape    ,					(self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)     )
         a__  			=							model(_snake_case    ,					labels=_snake_case     )
         self.parent.assertEqual(
             result.logits.shape    ,					(self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)     )






     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[str]     )      ->      Union[str, Any]:






         """simple docstring"""
         a__  			=							self.prepare_config_and_inputs()
         a__			,		a__			,		a__			,		a__  			=							config_and_inputs
         a__  			=							{"""pixel_values""": pixel_values}
         return config, inputs_dict







@require_torch
class 		__UpperCAmelCase(		lowercase__							,						lowercase__							,						unittest.TestCase			):





     """simple docstring"""



     __UpperCAmelCase						:			Union[str, Any]							=     (
         (DataaVecVisionModel, DataaVecVisionForImageClassification, DataaVecVisionForSemanticSegmentation)
         if is_torch_available()
         else ()
     )
     __UpperCAmelCase						:			Dict							=     (
         {
             '''feature-extraction''': DataaVecVisionModel,
             '''image-classification''': DataaVecVisionForImageClassification,
             '''image-segmentation''': DataaVecVisionForSemanticSegmentation,
         }
         if is_torch_available()
         else {}
     )

     __UpperCAmelCase						:			List[Any]							=     False
     __UpperCAmelCase						:			int							=     False
     __UpperCAmelCase						:			int							=     False

     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[Any]     )      ->      List[str]:






         """simple docstring"""
         a__  			=							DataaVecVisionModelTester(self     )
         a__  			=							ConfigTester(
             self    ,					config_class=_snake_case    ,					has_text_modality=_snake_case    ,					hidden_size=37     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Any     )      ->      List[str]:






         """simple docstring"""
         self.config_tester.run_common_tests()

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Tuple     )      ->      int:






         """simple docstring"""
         pass

     @require_torch_multi_gpu
     @unittest.skip(
         reason="""Data2VecVision has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`"""     )
     def 					__SCREAMING_SNAKE_CASE		(   self			:							Optional[Any]     )      ->      Union[str, Any]:






         """simple docstring"""
         pass

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Any     )      ->      List[str]:






         """simple docstring"""
         a__			,		a__  			=							self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
             a__  			=							model_class(_snake_case     )
             self.assertIsInstance(model.get_input_embeddings()    ,					(nn.Module)     )
             a__  			=							model.get_output_embeddings()
             self.assertTrue(x is None or isinstance(_snake_case    ,					nn.Linear     )     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Optional[Any]     )      ->      Optional[int]:






         """simple docstring"""
         a__			,		a__  			=							self.model_tester.prepare_config_and_inputs_for_common()

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

             a__  			=							["""pixel_values"""]
             self.assertListEqual(arg_names[:1]    ,					_snake_case     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Tuple     )      ->      List[Any]:






         """simple docstring"""
         a__  			=							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*_snake_case     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							int     )      ->      Tuple:






         """simple docstring"""
         a__  			=							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_image_segmentation(*_snake_case     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Tuple     )      ->      Optional[int]:






         """simple docstring"""


         if not self.model_tester.is_training:
             return

         a__			,		a__  			=							self.model_tester.prepare_config_and_inputs_for_common()
         a__  			=							True

         for model_class in self.all_model_classes:
             if model_class in [*get_values(_snake_case     )]:
                 continue

             a__  			=							model_class(_snake_case     )
             model.to(_snake_case     )
             model.train()
             a__  			=							self._prepare_for_class(_snake_case    ,					_snake_case    ,					return_labels=_snake_case     )
             a__  			=							model(**_snake_case     ).loss
             loss.backward()

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Optional[int]     )      ->      Any:






         """simple docstring"""
         a__			,		a__  			=							self.model_tester.prepare_config_and_inputs_for_common()
         if not self.model_tester.is_training:
             return

         a__  			=							False
         a__  			=							True

         for model_class in self.all_model_classes:
             if model_class in [*get_values(_snake_case     )] or not model_class.supports_gradient_checkpointing:
                 continue
             # TODO: remove the following 3 lines once we have a MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING
             # this can then be incorporated into _prepare_for_class in test_modeling_common.py
             elif model_class.__name__ == "Data2VecVisionForSemanticSegmentation":
                 a__			,		a__			,		a__			,		a__  			=							inputs_dict["""pixel_values"""].shape
                 a__  			=							torch.zeros(
                     [self.model_tester.batch_size, height, width]    ,					device=_snake_case     ).long()
             a__  			=							model_class(_snake_case     )
             model.gradient_checkpointing_enable()
             model.to(_snake_case     )
             model.train()
             a__  			=							self._prepare_for_class(_snake_case    ,					_snake_case    ,					return_labels=_snake_case     )
             a__  			=							model(**_snake_case     ).loss
             loss.backward()

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Optional[int]     )      ->      Dict:






         """simple docstring"""
         a__			,		a__  			=							self.model_tester.prepare_config_and_inputs_for_common()

         a__  			=							_config_zero_init(_snake_case     )
         for model_class in self.all_model_classes:
             a__  			=							model_class(config=_snake_case     )
             for name, param in model.named_parameters():
                 # we skip lambda parameters as these require special initial values
                 # determined by config.layer_scale_init_value
                 if "lambda" in name:
                     continue
                 if param.requires_grad:
                     self.assertIn(
                         ((param.data.mean() * 1E9).round() / 1E9).item()    ,					[0.0, 1.0]    ,					msg=f"""Parameter {name} of model {model_class} seems not properly initialized"""    ,					)

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Optional[int]    ,					A			:							Union[str, Any]    ,					A			:							Union[str, Any]    ,					A			:							Optional[Any]    ,					A			:							List[str]=2E-4    ,					A			:							Optional[int]="outputs"    ,					A			:							Union[str, Any]=None     )      ->      int:






         """simple docstring"""
         super().check_pt_tf_outputs(_snake_case    ,					_snake_case    ,					_snake_case    ,					_snake_case    ,					_snake_case    ,					_snake_case     )

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Optional[int]     )      ->      List[str]:






         """simple docstring"""
         a__  			=							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_image_classification(*_snake_case     )






     @slow
     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[Any]     )      ->      Dict:






         """simple docstring"""


         for model_name in DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             a__  			=							DataaVecVisionModel.from_pretrained(_snake_case     )
             self.assertIsNotNone(_snake_case     )






def 							__lowerCAmelCase			():
    a__  			=							Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""		)
    return image







@require_torch
@require_vision
class 		__UpperCAmelCase(		unittest.TestCase			):





     """simple docstring"""



     @cached_property
     def 					__SCREAMING_SNAKE_CASE		(   self			:							List[Any]     )      ->      Tuple:






         """simple docstring"""
         return (
             BeitImageProcessor.from_pretrained("""facebook/data2vec-vision-base-ft1k"""     ) if is_vision_available() else None
         )






     @slow
     def 					__SCREAMING_SNAKE_CASE		(   self			:							Tuple     )      ->      Any:






         """simple docstring"""
         a__  			=							DataaVecVisionForImageClassification.from_pretrained("""facebook/data2vec-vision-base-ft1k"""     ).to(
             _snake_case     )

         a__  			=							self.default_image_processor
         a__  			=							prepare_img()
         a__  			=							image_processor(images=_snake_case    ,					return_tensors="""pt"""     ).to(_snake_case     )

         # forward pass
         with torch.no_grad():
             a__  			=							model(**_snake_case     )
         a__  			=							outputs.logits

         # verify the logits
         a__  			=							torch.Size((1, 10_00)     )
         self.assertEqual(logits.shape    ,					_snake_case     )

         a__  			=							torch.tensor([0.3_2_7_7, -0.1_3_9_5, 0.0_9_1_1]     ).to(_snake_case     )

         self.assertTrue(torch.allclose(logits[0, :3]    ,					_snake_case    ,					atol=1E-4     )     )

         a__  			=							[model.config.labelaid[i] for i in ["""remote control, remote""", """tabby, tabby cat"""]]
         self.assertEqual(logits[0].topk(2     ).indices.cpu().tolist()    ,					_snake_case     )












import gc
import random
import unittest

import numpy as np
import torch
from PIL import Image
from transformers import CLIPImageProcessor, CLIPVisionConfig

from diffusers import AutoencoderKL, PaintByExamplePipeline, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.paint_by_example import PaintByExampleImageEncoder
from diffusers.utils import floats_tensor, load_image, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import IMAGE_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, IMAGE_GUIDED_IMAGE_INPAINTING_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()







class __snake_case     (     a					,    unittest.TestCase						):
   UpperCAmelCase__    :       str		=    PaintByExamplePipeline
   UpperCAmelCase__    :       Tuple		=    IMAGE_GUIDED_IMAGE_INPAINTING_PARAMS
   UpperCAmelCase__    :       Any		=    IMAGE_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
   UpperCAmelCase__    :       Union[str, Any]		=    frozenset([]						)  # TO_DO: update the image_prams once refactored VaeImageProcessor.preprocess







   def lowerCamelCase		( self						:		Optional[Any]):

        """simple docstring"""


        torch.manual_seed(0)
        UpperCAmelCase_		=				UNetaDConditionModel(
            block_out_channels=(32, 64)   ,		layers_per_block=2   ,		sample_size=32   ,		in_channels=9   ,		out_channels=4   ,		down_block_types=('''DownBlock2D''', '''CrossAttnDownBlock2D''')   ,		up_block_types=('''CrossAttnUpBlock2D''', '''UpBlock2D''')   ,		cross_attention_dim=32   ,		)
        UpperCAmelCase_		=				PNDMScheduler(skip_prk_steps=_snake_case)
        torch.manual_seed(0)
        UpperCAmelCase_		=				AutoencoderKL(
            block_out_channels=[32, 64]   ,		in_channels=3   ,		out_channels=3   ,		down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D''']   ,		up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D''']   ,		latent_channels=4   ,		)
        torch.manual_seed(0)
        UpperCAmelCase_		=				CLIPVisionConfig(
            hidden_size=32   ,		projection_dim=32   ,		intermediate_size=37   ,		layer_norm_eps=1e-05   ,		num_attention_heads=4   ,		num_hidden_layers=5   ,		image_size=32   ,		patch_size=4   ,		)
        UpperCAmelCase_		=				PaintByExampleImageEncoder(_snake_case   ,		proj_size=32)
        UpperCAmelCase_		=				CLIPImageProcessor(crop_size=32   ,		size=32)

        UpperCAmelCase_		=				{
            '''unet''': unet,
            '''scheduler''': scheduler,
            '''vae''': vae,
            '''image_encoder''': image_encoder,
            '''safety_checker''': None,
            '''feature_extractor''': feature_extractor,
        }
        return components







   def lowerCamelCase		( self						:		Optional[Any]   ,		_snake_case						:		List[str]):

        """simple docstring"""


        UpperCAmelCase_		=				np.array(image.convert('''RGB'''))
        UpperCAmelCase_		=				image[None].transpose(0   ,		3   ,		1   ,		2)
        UpperCAmelCase_		=				torch.from_numpy(_snake_case).to(dtype=torch.floataa) / 1_2_7.5 - 1.0
        return image







   def lowerCamelCase		( self						:		Tuple   ,		_snake_case						:		Dict="cpu"   ,		_snake_case						:		int=0):

        """simple docstring"""


        UpperCAmelCase_		=				floats_tensor((1, 3, 32, 32)   ,		rng=random.Random(_snake_case)).to(_snake_case)
        UpperCAmelCase_		=				image.cpu().permute(0   ,		2   ,		3   ,		1)[0]
        UpperCAmelCase_		=				Image.fromarray(np.uinta(_snake_case)).convert('''RGB''').resize((64, 64))
        UpperCAmelCase_		=				Image.fromarray(np.uinta(image + 4)).convert('''RGB''').resize((64, 64))
        UpperCAmelCase_		=				Image.fromarray(np.uinta(_snake_case)).convert('''RGB''').resize((32, 32))

        if str(_snake_case).startswith('''mps'''):
             UpperCAmelCase_		=				torch.manual_seed(_snake_case)
        else:
             UpperCAmelCase_		=				torch.Generator(device=_snake_case).manual_seed(_snake_case)
        UpperCAmelCase_		=				{
            '''example_image''': example_image,
            '''image''': init_image,
            '''mask_image''': mask_image,
            '''generator''': generator,
            '''num_inference_steps''': 2,
            '''guidance_scale''': 6.0,
            '''output_type''': '''numpy''',
        }
        return inputs







   def lowerCamelCase		( self						:		Any):

        """simple docstring"""


        UpperCAmelCase_		=				self.get_dummy_components()

        # make sure here that pndm scheduler skips prk
        UpperCAmelCase_		=				PaintByExamplePipeline(**_snake_case)
        UpperCAmelCase_		=				pipe.to('''cpu''')
        pipe.set_progress_bar_config(disable=_snake_case)

        UpperCAmelCase_		=				self.get_dummy_inputs()
        UpperCAmelCase_		=				pipe(**_snake_case)
        UpperCAmelCase_		=				output.images

        UpperCAmelCase_		=				image[0, -3:, -3:, -1]

        assert image.shape == (1, 64, 64, 3)
        UpperCAmelCase_		=				np.array([0.4_6_8_6, 0.5_6_8_7, 0.4_0_0_7, 0.5_2_1_8, 0.5_7_4_1, 0.4_4_8_2, 0.4_9_4_0, 0.4_6_2_9, 0.4_5_0_3])

        assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2







   def lowerCamelCase		( self						:		Optional[Any]):

        """simple docstring"""


        UpperCAmelCase_		=				'''cpu'''
        UpperCAmelCase_		=				self.get_dummy_inputs()
        inputs.pop('''mask_image''')
        UpperCAmelCase_		=				self.convert_to_pt(inputs.pop('''image'''))
        UpperCAmelCase_		=				image.clamp(0   ,		1) / 2

        # make sure here that pndm scheduler skips prk
        UpperCAmelCase_		=				PaintByExamplePipeline(**self.get_dummy_components())
        UpperCAmelCase_		=				pipe.to(_snake_case)
        pipe.set_progress_bar_config(disable=_snake_case)

        UpperCAmelCase_		=				pipe(image=_snake_case   ,		mask_image=mask_image[:, 0]   ,		**_snake_case)
        UpperCAmelCase_		=				output.images

        UpperCAmelCase_		=				image.cpu().permute(0   ,		2   ,		3   ,		1)[0]
        UpperCAmelCase_		=				mask_image.cpu().permute(0   ,		2   ,		3   ,		1)[0]

        UpperCAmelCase_		=				Image.fromarray(np.uinta(_snake_case)).convert('''RGB''')
        UpperCAmelCase_		=				Image.fromarray(np.uinta(_snake_case)).convert('''RGB''')

        UpperCAmelCase_		=				pipe(**self.get_dummy_inputs())
        UpperCAmelCase_		=				output.images

        assert out_a.shape == (1, 64, 64, 3)
        assert np.abs(out_a.flatten() - out_a.flatten()).max() < 5e-2







   def lowerCamelCase		( self						:		Any):

        """simple docstring"""


        super().test_inference_batch_single_identical(expected_max_diff=3e-3)







@slow
@require_torch_gpu
class __snake_case     (     unittest.TestCase						):







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

        """simple docstring"""


        super().tearDown()
        gc.collect()
        torch.cuda.empty_cache()







   def lowerCamelCase		( self						:		Tuple):

        """simple docstring"""


        UpperCAmelCase_		=				load_image(
            '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
            '''/paint_by_example/dog_in_bucket.png''')
        UpperCAmelCase_		=				load_image(
            '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
            '''/paint_by_example/mask.png''')
        UpperCAmelCase_		=				load_image(
            '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
            '''/paint_by_example/panda.jpg''')

        UpperCAmelCase_		=				PaintByExamplePipeline.from_pretrained('''Fantasy-Studio/Paint-by-Example''')
        UpperCAmelCase_		=				pipe.to(_snake_case)
        pipe.set_progress_bar_config(disable=_snake_case)

        UpperCAmelCase_		=				torch.manual_seed(321)
        UpperCAmelCase_		=				pipe(
            image=_snake_case   ,		mask_image=_snake_case   ,		example_image=_snake_case   ,		generator=_snake_case   ,		guidance_scale=5.0   ,		num_inference_steps=50   ,		output_type='''np'''   ,		)

        UpperCAmelCase_		=				output.images

        UpperCAmelCase_		=				image[0, -3:, -3:, -1]

        assert image.shape == (1, 512, 512, 3)
        UpperCAmelCase_		=				np.array([0.4_8_3_4, 0.4_8_1_1, 0.4_8_7_4, 0.5_1_2_2, 0.5_0_8_1, 0.5_1_4_4, 0.5_2_9_1, 0.5_2_9_0, 0.5_3_7_4])

        assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2






