


'''simple docstring'''







from typing import List, Union

import numpy as np

from ..utils import add_end_docstrings, is_torch_available, is_vision_available, logging, requires_backends
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
   from PIL import Image

   from ..image_utils import load_image

if is_torch_available():
   import torch

   from ..models.auto.modeling_auto import MODEL_FOR_DEPTH_ESTIMATION_MAPPING

A__:    Optional[int]					    =       logging.get_logger(__name__)







@add_end_docstrings(UpperCAmelCase__      )
class A__       (						UpperCAmelCase__      ):






      def __init__( self			:List[Any]     ,						*SCREAMING_SNAKE_CASE			:Optional[int]     ,						**SCREAMING_SNAKE_CASE			:Tuple	)       ->					str:




             '''simple docstring'''
             super().__init__(*SCREAMING_SNAKE_CASE     ,						**SCREAMING_SNAKE_CASE	)
             requires_backends(self     ,						"""vision"""	)
             self.check_model_type(SCREAMING_SNAKE_CASE	)






      def __call__( self			:int     ,						SCREAMING_SNAKE_CASE			:Union[str, List[str], "Image.Image", List["Image.Image"]]     ,						**SCREAMING_SNAKE_CASE			:Union[str, Any]	)       ->					Any:




             '''simple docstring'''
             return super().__call__(SCREAMING_SNAKE_CASE     ,						**SCREAMING_SNAKE_CASE	)






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




             '''simple docstring'''
             return {}, {}, {}






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




             '''simple docstring'''
             _a    : Dict     					=load_image(SCREAMING_SNAKE_CASE	)
             _a    : str     					=image.size
             _a    : Tuple     					=self.image_processor(images=SCREAMING_SNAKE_CASE     ,						return_tensors=self.framework	)
             return model_inputs






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




             '''simple docstring'''
             _a    : int     					=self.model(**SCREAMING_SNAKE_CASE	)
             return model_outputs






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




             '''simple docstring'''
             _a    : List[str]     					=model_outputs.predicted_depth
             _a    : Optional[int]     					=torch.nn.functional.interpolate(
                 predicted_depth.unsqueeze(1	)     ,						size=self.image_size[::-1]     ,						mode="""bicubic"""     ,						align_corners=SCREAMING_SNAKE_CASE	)
             _a    : Optional[Any]     					=prediction.squeeze().cpu().numpy()
             _a    : Tuple     					=(output * 2_5_5 / np.max(SCREAMING_SNAKE_CASE	)).astype("""uint8"""	)
             _a    : List[str]     					=Image.fromarray(SCREAMING_SNAKE_CASE	)
             _a    : List[Any]     					={}
             _a    : List[str]     					=predicted_depth
             _a    : int     					=depth
             return output_dict






'''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	)


