


'''simple docstring'''







import json
import pathlib
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision, slow
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
   import torch

if is_vision_available():
   from PIL import Image

   from transformers import YolosImageProcessor







class A__       (						unittest.TestCase      ):






      def __init__( self			:int     ,						SCREAMING_SNAKE_CASE			:int     ,						SCREAMING_SNAKE_CASE			:Dict=7     ,						SCREAMING_SNAKE_CASE			:Optional[Any]=3     ,						SCREAMING_SNAKE_CASE			:List[str]=3_0     ,						SCREAMING_SNAKE_CASE			:str=4_0_0     ,						SCREAMING_SNAKE_CASE			:Tuple=True     ,						SCREAMING_SNAKE_CASE			:Optional[int]=None     ,						SCREAMING_SNAKE_CASE			:Tuple=True     ,						SCREAMING_SNAKE_CASE			:Tuple=[0.5, 0.5, 0.5]     ,						SCREAMING_SNAKE_CASE			:Dict=[0.5, 0.5, 0.5]     ,						SCREAMING_SNAKE_CASE			:List[Any]=True     ,						SCREAMING_SNAKE_CASE			:str=1 / 2_5_5     ,						SCREAMING_SNAKE_CASE			:Optional[int]=True     ,						)       ->					Dict:




             '''simple docstring'''
             # by setting size["longest_edge"] > max_resolution we're effectively not testing this :p
             _a    : Union[str, Any]     					=size if size is not None else {"""shortest_edge""": 1_8, """longest_edge""": 1_3_3_3}
             _a    : int     					=parent
             _a    : str     					=batch_size
             _a    : Union[str, Any]     					=num_channels
             _a    : Union[str, Any]     					=min_resolution
             _a    : Dict     					=max_resolution
             _a    : List[str]     					=do_resize
             _a    : str     					=size
             _a    : Any     					=do_normalize
             _a    : Dict     					=image_mean
             _a    : str     					=image_std
             _a    : Dict     					=do_rescale
             _a    : Optional[int]     					=rescale_factor
             _a    : Optional[Any]     					=do_pad






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




             '''simple docstring'''
             return {
                 "do_resize": self.do_resize,
                 "size": self.size,
                 "do_normalize": self.do_normalize,
                 "image_mean": self.image_mean,
                 "image_std": self.image_std,
                 "do_rescale": self.do_rescale,
                 "rescale_factor": self.rescale_factor,
                 "do_pad": self.do_pad,
             }






      def __UpperCAmelCase       ( self			:List[Any]     ,						SCREAMING_SNAKE_CASE			:List[str]     ,						SCREAMING_SNAKE_CASE			:Optional[int]=False	)       ->					Tuple:




             '''simple docstring'''
             if not batched:
                    _a    : Dict     					=image_inputs[0]
                    if isinstance(SCREAMING_SNAKE_CASE     ,						Image.Image	):
                           _a					,    _a    : Optional[Any]     					=image.size
                    else:
                           _a					,    _a    : Optional[Any]     					=image.shape[1], image.shape[2]
                    if w < h:
                           _a    : str     					=int(self.size["""shortest_edge"""] * h / w	)
                           _a    : Union[str, Any]     					=self.size["""shortest_edge"""]
                    elif w > h:
                           _a    : Dict     					=self.size["""shortest_edge"""]
                           _a    : Tuple     					=int(self.size["""shortest_edge"""] * w / h	)
                    else:
                           _a    : List[str]     					=self.size["""shortest_edge"""]
                           _a    : Tuple     					=self.size["""shortest_edge"""]

             else:
                    _a    : Optional[int]     					=[]
                    for image in image_inputs:
                           _a					,    _a    : List[Any]     					=self.get_expected_values([image]	)
                           expected_values.append((expected_height, expected_width)	)
                    _a    : Optional[Any]     					=max(SCREAMING_SNAKE_CASE     ,						key=lambda SCREAMING_SNAKE_CASE	: item[0]	)[0]
                    _a    : Any     					=max(SCREAMING_SNAKE_CASE     ,						key=lambda SCREAMING_SNAKE_CASE	: item[1]	)[1]

             return expected_height, expected_width







@require_torch
@require_vision
class A__       (						UpperCAmelCase__ ,     unittest.TestCase      ):
      __UpperCamelCase       :  List[str]	       =							YolosImageProcessor if is_vision_available() else None






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




             '''simple docstring'''
             _a    : List[str]     					=YolosImageProcessingTester(self	)






      @property
      def __UpperCAmelCase       ( self			:List[str]	)       ->					Union[str, Any]:




             '''simple docstring'''
             return self.image_processor_tester.prepare_image_processor_dict()






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




             '''simple docstring'''
             _a    : str     					=self.image_processing_class(**self.image_processor_dict	)
             self.assertTrue(hasattr(SCREAMING_SNAKE_CASE     ,						"""image_mean"""	)	)
             self.assertTrue(hasattr(SCREAMING_SNAKE_CASE     ,						"""image_std"""	)	)
             self.assertTrue(hasattr(SCREAMING_SNAKE_CASE     ,						"""do_normalize"""	)	)
             self.assertTrue(hasattr(SCREAMING_SNAKE_CASE     ,						"""do_resize"""	)	)
             self.assertTrue(hasattr(SCREAMING_SNAKE_CASE     ,						"""size"""	)	)






      def __UpperCAmelCase       ( self			:Dict	)       ->					Optional[Any]:




             '''simple docstring'''
             _a    : List[str]     					=self.image_processing_class.from_dict(self.image_processor_dict	)
             self.assertEqual(image_processor.size     ,						{"""shortest_edge""": 1_8, """longest_edge""": 1_3_3_3}	)
             self.assertEqual(image_processor.do_pad     ,						SCREAMING_SNAKE_CASE	)

             _a    : Tuple     					=self.image_processing_class.from_dict(
                 self.image_processor_dict     ,						size=4_2     ,						max_size=8_4     ,						pad_and_return_pixel_mask=SCREAMING_SNAKE_CASE	)
             self.assertEqual(image_processor.size     ,						{"""shortest_edge""": 4_2, """longest_edge""": 8_4}	)
             self.assertEqual(image_processor.do_pad     ,						SCREAMING_SNAKE_CASE	)






      def __UpperCAmelCase       ( self			:Any	)       ->					int:




             '''simple docstring'''
             pass






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




             '''simple docstring'''
             # Initialize image_processing
             _a    : Tuple     					=self.image_processing_class(**self.image_processor_dict	)
             # create random PIL images
             _a    : Union[str, Any]     					=prepare_image_inputs(self.image_processor_tester     ,						equal_resolution=SCREAMING_SNAKE_CASE	)
             for image in image_inputs:
                    self.assertIsInstance(SCREAMING_SNAKE_CASE     ,						Image.Image	)

             # Test not batched input
             _a    : str     					=image_processing(image_inputs[0]     ,						return_tensors="""pt"""	).pixel_values

             _a					,    _a    : Dict     					=self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE	)

             self.assertEqual(
                 encoded_images.shape     ,						(1, self.image_processor_tester.num_channels, expected_height, expected_width)     ,						)

             # Test batched
             _a					,    _a    : List[Any]     					=self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE     ,						batched=SCREAMING_SNAKE_CASE	)

             _a    : Dict     					=image_processing(SCREAMING_SNAKE_CASE     ,						return_tensors="""pt"""	).pixel_values
             self.assertEqual(
                 encoded_images.shape     ,						(
                     self.image_processor_tester.batch_size,
                     self.image_processor_tester.num_channels,
                     expected_height,
                     expected_width,
                 )     ,						)






      def __UpperCAmelCase       ( self			:Optional[int]	)       ->					Optional[int]:




             '''simple docstring'''
             # Initialize image_processing
             _a    : List[str]     					=self.image_processing_class(**self.image_processor_dict	)
             # create random numpy tensors
             _a    : Union[str, Any]     					=prepare_image_inputs(self.image_processor_tester     ,						equal_resolution=SCREAMING_SNAKE_CASE     ,						numpify=SCREAMING_SNAKE_CASE	)
             for image in image_inputs:
                    self.assertIsInstance(SCREAMING_SNAKE_CASE     ,						np.ndarray	)

             # Test not batched input
             _a    : Optional[Any]     					=image_processing(image_inputs[0]     ,						return_tensors="""pt"""	).pixel_values

             _a					,    _a    : int     					=self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE	)

             self.assertEqual(
                 encoded_images.shape     ,						(1, self.image_processor_tester.num_channels, expected_height, expected_width)     ,						)

             # Test batched
             _a    : Tuple     					=image_processing(SCREAMING_SNAKE_CASE     ,						return_tensors="""pt"""	).pixel_values

             _a					,    _a    : Tuple     					=self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE     ,						batched=SCREAMING_SNAKE_CASE	)

             self.assertEqual(
                 encoded_images.shape     ,						(
                     self.image_processor_tester.batch_size,
                     self.image_processor_tester.num_channels,
                     expected_height,
                     expected_width,
                 )     ,						)






      def __UpperCAmelCase       ( self			:Tuple	)       ->					int:




             '''simple docstring'''
             # Initialize image_processing
             _a    : str     					=self.image_processing_class(**self.image_processor_dict	)
             # create random PyTorch tensors
             _a    : List[Any]     					=prepare_image_inputs(self.image_processor_tester     ,						equal_resolution=SCREAMING_SNAKE_CASE     ,						torchify=SCREAMING_SNAKE_CASE	)
             for image in image_inputs:
                    self.assertIsInstance(SCREAMING_SNAKE_CASE     ,						torch.Tensor	)

             # Test not batched input
             _a    : Optional[Any]     					=image_processing(image_inputs[0]     ,						return_tensors="""pt"""	).pixel_values

             _a					,    _a    : str     					=self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE	)

             self.assertEqual(
                 encoded_images.shape     ,						(1, self.image_processor_tester.num_channels, expected_height, expected_width)     ,						)

             # Test batched
             _a    : List[str]     					=image_processing(SCREAMING_SNAKE_CASE     ,						return_tensors="""pt"""	).pixel_values

             _a					,    _a    : List[str]     					=self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE     ,						batched=SCREAMING_SNAKE_CASE	)

             self.assertEqual(
                 encoded_images.shape     ,						(
                     self.image_processor_tester.batch_size,
                     self.image_processor_tester.num_channels,
                     expected_height,
                     expected_width,
                 )     ,						)






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




             '''simple docstring'''
             # Initialize image_processings
             _a    : int     					=self.image_processing_class(**self.image_processor_dict	)
             _a    : Tuple     					=self.image_processing_class(do_resize=SCREAMING_SNAKE_CASE     ,						do_normalize=SCREAMING_SNAKE_CASE     ,						do_rescale=SCREAMING_SNAKE_CASE	)
             # create random PyTorch tensors
             _a    : Tuple     					=prepare_image_inputs(self.image_processor_tester     ,						equal_resolution=SCREAMING_SNAKE_CASE     ,						torchify=SCREAMING_SNAKE_CASE	)
             for image in image_inputs:
                    self.assertIsInstance(SCREAMING_SNAKE_CASE     ,						torch.Tensor	)

             # Test whether the method "pad" and calling the image processor return the same tensors
             _a    : List[Any]     					=image_processing_a.pad(SCREAMING_SNAKE_CASE     ,						return_tensors="""pt"""	)
             _a    : List[str]     					=image_processing_a(SCREAMING_SNAKE_CASE     ,						return_tensors="""pt"""	)

             self.assertTrue(
                 torch.allclose(encoded_images_with_method["""pixel_values"""]     ,						encoded_images["""pixel_values"""]     ,						atol=1e-4	)	)






      @slow
      def __UpperCAmelCase       ( self			:List[Any]	)       ->					Tuple:




             '''simple docstring'''
             # prepare image and target
             _a    : List[str]     					=Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""	)
             with open("""./tests/fixtures/tests_samples/COCO/coco_annotations.txt"""     ,						"""r"""	) as f:
                    _a    : int     					=json.loads(f.read()	)

             _a    : List[str]     					={"""image_id""": 3_9_7_6_9, """annotations""": target}

             # encode them
             _a    : Union[str, Any]     					=YolosImageProcessor.from_pretrained("""hustvl/yolos-small"""	)
             _a    : Union[str, Any]     					=image_processing(images=SCREAMING_SNAKE_CASE     ,						annotations=SCREAMING_SNAKE_CASE     ,						return_tensors="""pt"""	)

             # verify pixel values
             _a    : int     					=torch.Size([1, 3, 8_0_0, 1_0_6_6]	)
             self.assertEqual(encoding["""pixel_values"""].shape     ,						SCREAMING_SNAKE_CASE	)

             _a    : List[str]     					=torch.tensor([0.2_796, 0.3_138, 0.3_481]	)
             self.assertTrue(torch.allclose(encoding["""pixel_values"""][0, 0, 0, :3]     ,						SCREAMING_SNAKE_CASE     ,						atol=1e-4	)	)

             # verify area
             _a    : int     					=torch.tensor([5_887.9_600, 11_250.2_061, 489_353.8_438, 837_122.7_500, 147_967.5_156, 165_732.3_438]	)
             self.assertTrue(torch.allclose(encoding["""labels"""][0]["""area"""]     ,						SCREAMING_SNAKE_CASE	)	)
             # verify boxes
             _a    : Optional[Any]     					=torch.Size([6, 4]	)
             self.assertEqual(encoding["""labels"""][0]["""boxes"""].shape     ,						SCREAMING_SNAKE_CASE	)
             _a    : str     					=torch.tensor([0.5_503, 0.2_765, 0.0_604, 0.2_215]	)
             self.assertTrue(torch.allclose(encoding["""labels"""][0]["""boxes"""][0]     ,						SCREAMING_SNAKE_CASE     ,						atol=1e-3	)	)
             # verify image_id
             _a    : Optional[Any]     					=torch.tensor([3_9_7_6_9]	)
             self.assertTrue(torch.allclose(encoding["""labels"""][0]["""image_id"""]     ,						SCREAMING_SNAKE_CASE	)	)
             # verify is_crowd
             _a    : str     					=torch.tensor([0, 0, 0, 0, 0, 0]	)
             self.assertTrue(torch.allclose(encoding["""labels"""][0]["""iscrowd"""]     ,						SCREAMING_SNAKE_CASE	)	)
             # verify class_labels
             _a    : Union[str, Any]     					=torch.tensor([7_5, 7_5, 6_3, 6_5, 1_7, 1_7]	)
             self.assertTrue(torch.allclose(encoding["""labels"""][0]["""class_labels"""]     ,						SCREAMING_SNAKE_CASE	)	)
             # verify orig_size
             _a    : Optional[int]     					=torch.tensor([4_8_0, 6_4_0]	)
             self.assertTrue(torch.allclose(encoding["""labels"""][0]["""orig_size"""]     ,						SCREAMING_SNAKE_CASE	)	)
             # verify size
             _a    : List[Any]     					=torch.tensor([8_0_0, 1_0_6_6]	)
             self.assertTrue(torch.allclose(encoding["""labels"""][0]["""size"""]     ,						SCREAMING_SNAKE_CASE	)	)






      @slow
      def __UpperCAmelCase       ( self			:Optional[Any]	)       ->					Optional[Any]:




             '''simple docstring'''
             # prepare image, target and masks_path
             _a    : Dict     					=Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""	)
             with open("""./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt"""     ,						"""r"""	) as f:
                    _a    : List[str]     					=json.loads(f.read()	)

             _a    : Tuple     					={"""file_name""": """000000039769.png""", """image_id""": 3_9_7_6_9, """segments_info""": target}

             _a    : Union[str, Any]     					=pathlib.Path("""./tests/fixtures/tests_samples/COCO/coco_panoptic"""	)

             # encode them
             _a    : Tuple     					=YolosImageProcessor(format="""coco_panoptic"""	)
             _a    : int     					=image_processing(images=SCREAMING_SNAKE_CASE     ,						annotations=SCREAMING_SNAKE_CASE     ,						masks_path=SCREAMING_SNAKE_CASE     ,						return_tensors="""pt"""	)

             # verify pixel values
             _a    : int     					=torch.Size([1, 3, 8_0_0, 1_0_6_6]	)
             self.assertEqual(encoding["""pixel_values"""].shape     ,						SCREAMING_SNAKE_CASE	)

             _a    : Union[str, Any]     					=torch.tensor([0.2_796, 0.3_138, 0.3_481]	)
             self.assertTrue(torch.allclose(encoding["""pixel_values"""][0, 0, 0, :3]     ,						SCREAMING_SNAKE_CASE     ,						atol=1e-4	)	)

             # verify area
             _a    : int     					=torch.tensor([147_979.6_875, 165_527.0_469, 484_638.5_938, 11_292.9_375, 5_879.6_562, 7_634.1_147]	)
             self.assertTrue(torch.allclose(encoding["""labels"""][0]["""area"""]     ,						SCREAMING_SNAKE_CASE	)	)
             # verify boxes
             _a    : Union[str, Any]     					=torch.Size([6, 4]	)
             self.assertEqual(encoding["""labels"""][0]["""boxes"""].shape     ,						SCREAMING_SNAKE_CASE	)
             _a    : Dict     					=torch.tensor([0.2_625, 0.5_437, 0.4_688, 0.8_625]	)
             self.assertTrue(torch.allclose(encoding["""labels"""][0]["""boxes"""][0]     ,						SCREAMING_SNAKE_CASE     ,						atol=1e-3	)	)
             # verify image_id
             _a    : Any     					=torch.tensor([3_9_7_6_9]	)
             self.assertTrue(torch.allclose(encoding["""labels"""][0]["""image_id"""]     ,						SCREAMING_SNAKE_CASE	)	)
             # verify is_crowd
             _a    : Tuple     					=torch.tensor([0, 0, 0, 0, 0, 0]	)
             self.assertTrue(torch.allclose(encoding["""labels"""][0]["""iscrowd"""]     ,						SCREAMING_SNAKE_CASE	)	)
             # verify class_labels
             _a    : Dict     					=torch.tensor([1_7, 1_7, 6_3, 7_5, 7_5, 9_3]	)
             self.assertTrue(torch.allclose(encoding["""labels"""][0]["""class_labels"""]     ,						SCREAMING_SNAKE_CASE	)	)
             # verify masks
             _a    : str     					=8_2_2_8_7_3
             self.assertEqual(encoding["""labels"""][0]["""masks"""].sum().item()     ,						SCREAMING_SNAKE_CASE	)
             # verify orig_size
             _a    : str     					=torch.tensor([4_8_0, 6_4_0]	)
             self.assertTrue(torch.allclose(encoding["""labels"""][0]["""orig_size"""]     ,						SCREAMING_SNAKE_CASE	)	)
             # verify size
             _a    : List[str]     					=torch.tensor([8_0_0, 1_0_6_6]	)
             self.assertTrue(torch.allclose(encoding["""labels"""][0]["""size"""]     ,						SCREAMING_SNAKE_CASE	)	)






'''simple docstring'''







from dataclasses import dataclass
from typing import Optional, Tuple, Union

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, apply_forward_hook
from .modeling_utils import ModelMixin
from .vae import Decoder, DecoderOutput, Encoder, VectorQuantizer







@dataclass
class A__       (						UpperCAmelCase__      ):
      __UpperCamelCase       :  torch.FloatTensor







class A__       (						UpperCAmelCase__ ,     UpperCAmelCase__      ):






      @register_to_config
      def __init__( self			:Optional[Any]     ,						SCREAMING_SNAKE_CASE			:int = 3     ,						SCREAMING_SNAKE_CASE			:int = 3     ,						SCREAMING_SNAKE_CASE			:Tuple[str] = ("DownEncoderBlock2D",)     ,						SCREAMING_SNAKE_CASE			:Tuple[str] = ("UpDecoderBlock2D",)     ,						SCREAMING_SNAKE_CASE			:Tuple[int] = (6_4,)     ,						SCREAMING_SNAKE_CASE			:int = 1     ,						SCREAMING_SNAKE_CASE			:str = "silu"     ,						SCREAMING_SNAKE_CASE			:int = 3     ,						SCREAMING_SNAKE_CASE			:int = 3_2     ,						SCREAMING_SNAKE_CASE			:int = 2_5_6     ,						SCREAMING_SNAKE_CASE			:int = 3_2     ,						SCREAMING_SNAKE_CASE			:Optional[int] = None     ,						SCREAMING_SNAKE_CASE			:float = 0.18_215     ,						SCREAMING_SNAKE_CASE			:str = "group"     ,						)       ->					Optional[int]:




             '''simple docstring'''
             super().__init__()

             # pass init params to Encoder
             _a    : Union[str, Any]     					=Encoder(
                 in_channels=SCREAMING_SNAKE_CASE     ,						out_channels=SCREAMING_SNAKE_CASE     ,						down_block_types=SCREAMING_SNAKE_CASE     ,						block_out_channels=SCREAMING_SNAKE_CASE     ,						layers_per_block=SCREAMING_SNAKE_CASE     ,						act_fn=SCREAMING_SNAKE_CASE     ,						norm_num_groups=SCREAMING_SNAKE_CASE     ,						double_z=SCREAMING_SNAKE_CASE     ,						)

             _a    : Optional[int]     					=vq_embed_dim if vq_embed_dim is not None else latent_channels

             _a    : Optional[int]     					=nn.Convad(SCREAMING_SNAKE_CASE     ,						SCREAMING_SNAKE_CASE     ,						1	)
             _a    : str     					=VectorQuantizer(SCREAMING_SNAKE_CASE     ,						SCREAMING_SNAKE_CASE     ,						beta=0.25     ,						remap=SCREAMING_SNAKE_CASE     ,						sane_index_shape=SCREAMING_SNAKE_CASE	)
             _a    : List[str]     					=nn.Convad(SCREAMING_SNAKE_CASE     ,						SCREAMING_SNAKE_CASE     ,						1	)

             # pass init params to Decoder
             _a    : List[str]     					=Decoder(
                 in_channels=SCREAMING_SNAKE_CASE     ,						out_channels=SCREAMING_SNAKE_CASE     ,						up_block_types=SCREAMING_SNAKE_CASE     ,						block_out_channels=SCREAMING_SNAKE_CASE     ,						layers_per_block=SCREAMING_SNAKE_CASE     ,						act_fn=SCREAMING_SNAKE_CASE     ,						norm_num_groups=SCREAMING_SNAKE_CASE     ,						norm_type=SCREAMING_SNAKE_CASE     ,						)






      @apply_forward_hook
      def __UpperCAmelCase       ( self			:Optional[Any]     ,						SCREAMING_SNAKE_CASE			:torch.FloatTensor     ,						SCREAMING_SNAKE_CASE			:bool = True	)       ->					VQEncoderOutput:




             '''simple docstring'''
             _a    : Optional[int]     					=self.encoder(SCREAMING_SNAKE_CASE	)
             _a    : int     					=self.quant_conv(SCREAMING_SNAKE_CASE	)

             if not return_dict:
                    return (h,)

             return VQEncoderOutput(latents=SCREAMING_SNAKE_CASE	)






      @apply_forward_hook
      def __UpperCAmelCase       ( self			:List[Any]     ,						SCREAMING_SNAKE_CASE			:torch.FloatTensor     ,						SCREAMING_SNAKE_CASE			:bool = False     ,						SCREAMING_SNAKE_CASE			:bool = True	)       ->					Union[DecoderOutput, torch.FloatTensor]:




             '''simple docstring'''
             # also go through quantization layer
             if not force_not_quantize:
                    _a					,    _a					,    _a    : Tuple     					=self.quantize(SCREAMING_SNAKE_CASE	)
             else:
                    _a    : str     					=h
             _a    : Dict     					=self.post_quant_conv(SCREAMING_SNAKE_CASE	)
             _a    : Union[str, Any]     					=self.decoder(SCREAMING_SNAKE_CASE     ,						quant if self.config.norm_type == """spatial""" else None	)

             if not return_dict:
                    return (dec,)

             return DecoderOutput(sample=SCREAMING_SNAKE_CASE	)






      def __UpperCAmelCase       ( self			:Optional[Any]     ,						SCREAMING_SNAKE_CASE			:torch.FloatTensor     ,						SCREAMING_SNAKE_CASE			:bool = True	)       ->					Union[DecoderOutput, torch.FloatTensor]:




             '''simple docstring'''
             _a    : Tuple     					=sample
             _a    : int     					=self.encode(SCREAMING_SNAKE_CASE	).latents
             _a    : List[Any]     					=self.decode(SCREAMING_SNAKE_CASE	).sample

             if not return_dict:
                    return (dec,)

             return DecoderOutput(sample=SCREAMING_SNAKE_CASE	)


