






'''simple docstring'''





from dataclasses import dataclass
from typing import Optional

import numpy as np
import torch
import torch.nn as nn

from ..utils import BaseOutput, is_torch_version, randn_tensor
from .attention_processor import SpatialNorm
from .unet_ad_blocks import UNetMidBlockaD, get_down_block, get_up_block


@dataclass
class  snake_case__      (					UpperCamelCase):
					a_        =					42






class  snake_case__      (					nn.Module):




					def __init__(  self  :		str				, _A  :		int=3				, _A  :		List[str]=3				, _A  :		Tuple=("DownEncoderBlock2D",)				, _A  :		Optional[int]=(64,)				, _A  :		Tuple=2				, _A  :		Union[str, Any]=32				, _A  :		Any="silu"				, _A  :		Optional[Any]=True				, )    ->							Optional[Any]:
								super().__init__()
								UpperCAmelCase_      :       Union[str, Any]          =       layers_per_block

								UpperCAmelCase_      :       int          =       torch.nn.Convad(
								    _A				, block_out_channels[0]				, kernel_size=3				, stride=1				, padding=1				, )

								UpperCAmelCase_      :       Dict          =       None
								UpperCAmelCase_      :       Optional[int]          =       nn.ModuleList([]      )

								# down
								UpperCAmelCase_      :       Union[str, Any]          =       block_out_channels[0]
								for i, down_block_type in enumerate(_A      ):
											UpperCAmelCase_      :       str          =       output_channel
											UpperCAmelCase_      :       Optional[Any]          =       block_out_channels[i]
											UpperCAmelCase_      :       Optional[int]          =       i == len(_A      ) - 1

											UpperCAmelCase_      :       List[Any]          =       get_down_block(
											    _A				, num_layers=self.layers_per_block				, in_channels=_A				, out_channels=_A				, add_downsample=not is_final_block				, resnet_eps=1e-6				, downsample_padding=0				, resnet_act_fn=_A				, resnet_groups=_A				, attention_head_dim=_A				, temb_channels=_A				, )
											self.down_blocks.append(_A      )

								# mid
								UpperCAmelCase_      :       int          =       UNetMidBlockaD(
								    in_channels=block_out_channels[-1]				, resnet_eps=1e-6				, resnet_act_fn=_A				, output_scale_factor=1				, resnet_time_scale_shift='''default'''				, attention_head_dim=block_out_channels[-1]				, resnet_groups=_A				, temb_channels=_A				, )

								# out
								UpperCAmelCase_      :       Dict          =       nn.GroupNorm(num_channels=block_out_channels[-1]				, num_groups=_A				, eps=1e-6      )
								UpperCAmelCase_      :       int          =       nn.SiLU()

								UpperCAmelCase_      :       List[str]          =       2 * out_channels if double_z else out_channels
								UpperCAmelCase_      :       str          =       nn.Convad(block_out_channels[-1]				, _A				, 3				, padding=1      )

								UpperCAmelCase_      :       List[Any]          =       False





					def 		A      (  self  :		str				, _A  :		Union[str, Any]      )    ->							List[Any]:
								UpperCAmelCase_      :       Union[str, Any]          =       x
								UpperCAmelCase_      :       Optional[Any]          =       self.conv_in(_A      )

								if self.training and self.gradient_checkpointing:

											def create_custom_forward(_A  :		str      ):
														def custom_forward(*_A  :		Optional[int]      ):
																	return module(*_A      )

														return custom_forward

											# down
											if is_torch_version('''>='''				, '''1.11.0'''      ):
														for down_block in self.down_blocks:
																	UpperCAmelCase_      :       str          =       torch.utils.checkpoint.checkpoint(
																	    create_custom_forward(_A      )				, _A				, use_reentrant=_A      )
														# middle
														UpperCAmelCase_      :       Tuple          =       torch.utils.checkpoint.checkpoint(
														    create_custom_forward(self.mid_block      )				, _A				, use_reentrant=_A      )
											else:
														for down_block in self.down_blocks:
																	UpperCAmelCase_      :       Optional[Any]          =       torch.utils.checkpoint.checkpoint(create_custom_forward(_A      )				, _A      )
														# middle
														UpperCAmelCase_      :       List[str]          =       torch.utils.checkpoint.checkpoint(create_custom_forward(self.mid_block      )				, _A      )

								else:
											# down
											for down_block in self.down_blocks:
														UpperCAmelCase_      :       Union[str, Any]          =       down_block(_A      )

											# middle
											UpperCAmelCase_      :       Optional[Any]          =       self.mid_block(_A      )

								# post-process
								UpperCAmelCase_      :       Optional[int]          =       self.conv_norm_out(_A      )
								UpperCAmelCase_      :       Optional[Any]          =       self.conv_act(_A      )
								UpperCAmelCase_      :       int          =       self.conv_out(_A      )

								return sample






class  snake_case__      (					nn.Module):




					def __init__(  self  :		List[Any]				, _A  :		Dict=3				, _A  :		int=3				, _A  :		Optional[int]=("UpDecoderBlock2D",)				, _A  :		str=(64,)				, _A  :		List[str]=2				, _A  :		Optional[int]=32				, _A  :		str="silu"				, _A  :		Union[str, Any]="group"				, )    ->							Any:
								super().__init__()
								UpperCAmelCase_      :       Optional[Any]          =       layers_per_block

								UpperCAmelCase_      :       List[str]          =       nn.Convad(
								    _A				, block_out_channels[-1]				, kernel_size=3				, stride=1				, padding=1				, )

								UpperCAmelCase_      :       List[str]          =       None
								UpperCAmelCase_      :       Optional[int]          =       nn.ModuleList([]      )

								UpperCAmelCase_      :       int          =       in_channels if norm_type == '''spatial''' else None

								# mid
								UpperCAmelCase_      :       Dict          =       UNetMidBlockaD(
								    in_channels=block_out_channels[-1]				, resnet_eps=1e-6				, resnet_act_fn=_A				, output_scale_factor=1				, resnet_time_scale_shift='''default''' if norm_type == '''group''' else norm_type				, attention_head_dim=block_out_channels[-1]				, resnet_groups=_A				, temb_channels=_A				, )

								# up
								UpperCAmelCase_      :       List[Any]          =       list(reversed(_A      )      )
								UpperCAmelCase_      :       Optional[int]          =       reversed_block_out_channels[0]
								for i, up_block_type in enumerate(_A      ):
											UpperCAmelCase_      :       Optional[Any]          =       output_channel
											UpperCAmelCase_      :       Optional[int]          =       reversed_block_out_channels[i]

											UpperCAmelCase_      :       Union[str, Any]          =       i == len(_A      ) - 1

											UpperCAmelCase_      :       Any          =       get_up_block(
											    _A				, num_layers=self.layers_per_block + 1				, in_channels=_A				, out_channels=_A				, prev_output_channel=_A				, add_upsample=not is_final_block				, resnet_eps=1e-6				, resnet_act_fn=_A				, resnet_groups=_A				, attention_head_dim=_A				, temb_channels=_A				, resnet_time_scale_shift=_A				, )
											self.up_blocks.append(_A      )
											UpperCAmelCase_      :       Union[str, Any]          =       output_channel

								# out
								if norm_type == "spatial":
											UpperCAmelCase_      :       str          =       SpatialNorm(block_out_channels[0]				, _A      )
								else:
											UpperCAmelCase_      :       Union[str, Any]          =       nn.GroupNorm(num_channels=block_out_channels[0]				, num_groups=_A				, eps=1e-6      )
								UpperCAmelCase_      :       str          =       nn.SiLU()
								UpperCAmelCase_      :       Any          =       nn.Convad(block_out_channels[0]				, _A				, 3				, padding=1      )

								UpperCAmelCase_      :       Any          =       False





					def 		A      (  self  :		str				, _A  :		str				, _A  :		Tuple=None      )    ->							Optional[int]:
								UpperCAmelCase_      :       Union[str, Any]          =       z
								UpperCAmelCase_      :       Optional[int]          =       self.conv_in(_A      )

								UpperCAmelCase_      :       int          =       next(iter(self.up_blocks.parameters()      )      ).dtype
								if self.training and self.gradient_checkpointing:

											def create_custom_forward(_A  :		Dict      ):
														def custom_forward(*_A  :		Tuple      ):
																	return module(*_A      )

														return custom_forward

											if is_torch_version('''>='''				, '''1.11.0'''      ):
														# middle
														UpperCAmelCase_      :       Optional[int]          =       torch.utils.checkpoint.checkpoint(
														    create_custom_forward(self.mid_block      )				, _A				, _A				, use_reentrant=_A      )
														UpperCAmelCase_      :       Union[str, Any]          =       sample.to(_A      )

														# up
														for up_block in self.up_blocks:
																	UpperCAmelCase_      :       List[Any]          =       torch.utils.checkpoint.checkpoint(
																	    create_custom_forward(_A      )				, _A				, _A				, use_reentrant=_A      )
											else:
														# middle
														UpperCAmelCase_      :       List[str]          =       torch.utils.checkpoint.checkpoint(
														    create_custom_forward(self.mid_block      )				, _A				, _A      )
														UpperCAmelCase_      :       Optional[Any]          =       sample.to(_A      )

														# up
														for up_block in self.up_blocks:
																	UpperCAmelCase_      :       Optional[int]          =       torch.utils.checkpoint.checkpoint(create_custom_forward(_A      )				, _A				, _A      )
								else:
											# middle
											UpperCAmelCase_      :       List[str]          =       self.mid_block(_A				, _A      )
											UpperCAmelCase_      :       List[Any]          =       sample.to(_A      )

											# up
											for up_block in self.up_blocks:
														UpperCAmelCase_      :       str          =       up_block(_A				, _A      )

        # post-process
								if latent_embeds is None:
											UpperCAmelCase_      :       int          =       self.conv_norm_out(_A      )
								else:
											UpperCAmelCase_      :       List[Any]          =       self.conv_norm_out(_A				, _A      )
								UpperCAmelCase_      :       Any          =       self.conv_act(_A      )
								UpperCAmelCase_      :       str          =       self.conv_out(_A      )

								return sample






class  snake_case__      (					nn.Module):




					def __init__(  self  :		Any				, _A  :		Tuple				, _A  :		str				, _A  :		Optional[Any]				, _A  :		Tuple=None				, _A  :		List[Any]="random"				, _A  :		str=False				, _A  :		Optional[Any]=True      )    ->							Union[str, Any]:
								super().__init__()
								UpperCAmelCase_      :       int          =       n_e
								UpperCAmelCase_      :       Tuple          =       vq_embed_dim
								UpperCAmelCase_      :       int          =       beta
								UpperCAmelCase_      :       str          =       legacy

								UpperCAmelCase_      :       int          =       nn.Embedding(self.n_e				, self.vq_embed_dim      )
								self.embedding.weight.data.uniform_(-1.0 / self.n_e				, 1.0 / self.n_e      )

								UpperCAmelCase_      :       Tuple          =       remap
								if self.remap is not None:
											self.register_buffer('''used'''				, torch.tensor(np.load(self.remap      )      )      )
											UpperCAmelCase_      :       Optional[int]          =       self.used.shape[0]
											UpperCAmelCase_      :       Optional[Any]          =       unknown_index  # "random" or "extra" or integer
											if self.unknown_index == "extra":
														UpperCAmelCase_      :       int          =       self.re_embed
														UpperCAmelCase_      :       Optional[Any]          =       self.re_embed + 1
											print(
											    F"Remapping {self.n_e} indices to {self.re_embed} indices. "
											    F"Using {self.unknown_index} for unknown indices."      )
								else:
											UpperCAmelCase_      :       List[str]          =       n_e

								UpperCAmelCase_      :       Optional[int]          =       sane_index_shape




					def 		A      (  self  :		Optional[Any]				, _A  :		Any      )    ->							Optional[Any]:
								UpperCAmelCase_      :       int          =       inds.shape
								assert len(_A      ) > 1
								UpperCAmelCase_      :       int          =       inds.reshape(ishape[0]				, -1      )
								UpperCAmelCase_      :       List[Any]          =       self.used.to(_A      )
								UpperCAmelCase_      :       List[str]          =       (inds[:, :, None] == used[None, None, ...]).long()
								UpperCAmelCase_      :       Union[str, Any]          =       match.argmax(-1      )
								UpperCAmelCase_      :       Tuple          =       match.sum(2      ) < 1
								if self.unknown_index == "random":
											UpperCAmelCase_      :       Dict          =       torch.randint(0				, self.re_embed				, size=new[unknown].shape      ).to(device=new.device      )
								else:
											UpperCAmelCase_      :       str          =       self.unknown_index
								return new.reshape(_A      )




					def 		A      (  self  :		int				, _A  :		List[Any]      )    ->							List[Any]:
								UpperCAmelCase_      :       Optional[int]          =       inds.shape
								assert len(_A      ) > 1
								UpperCAmelCase_      :       Union[str, Any]          =       inds.reshape(ishape[0]				, -1      )
								UpperCAmelCase_      :       Tuple          =       self.used.to(_A      )
								if self.re_embed > self.used.shape[0]:  # extra token
											UpperCAmelCase_      :       Dict          =       0  # simply set to zero
								UpperCAmelCase_      :       Optional[int]          =       torch.gather(used[None, :][inds.shape[0] * [0], :]				, 1				, _A      )
								return back.reshape(_A      )




					def 		A      (  self  :		int				, _A  :		Any      )    ->							Tuple:
								# reshape z -> (batch, height, width, channel) and flatten
								UpperCAmelCase_      :       Any          =       z.permute(0				, 2				, 3				, 1      ).contiguous()
								UpperCAmelCase_      :       Optional[Any]          =       z.view(-1				, self.vq_embed_dim      )

								# distances from z to embeddings e_j (z - e)^2 = z^2 + e^2 - 2 e * z
								UpperCAmelCase_      :       List[Any]          =       torch.argmin(torch.cdist(_A				, self.embedding.weight      )				, dim=1      )

								UpperCAmelCase_      :       int          =       self.embedding(_A      ).view(z.shape      )
								UpperCAmelCase_      :       Dict          =       None
								UpperCAmelCase_      :       Optional[int]          =       None

								# compute loss for embedding
								if not self.legacy:
											UpperCAmelCase_      :       int          =       self.beta * torch.mean((z_q.detach() - z) ** 2      ) + torch.mean((z_q - z.detach()) ** 2      )
								else:
											UpperCAmelCase_      :       Dict          =       torch.mean((z_q.detach() - z) ** 2      ) + self.beta * torch.mean((z_q - z.detach()) ** 2      )

								# preserve gradients
								UpperCAmelCase_      :       int          =       z + (z_q - z).detach()

								# reshape back to match original input shape
								UpperCAmelCase_      :       List[str]          =       z_q.permute(0				, 3				, 1				, 2      ).contiguous()

								if self.remap is not None:
											UpperCAmelCase_      :       Optional[Any]          =       min_encoding_indices.reshape(z.shape[0]				, -1      )  # add batch axis
											UpperCAmelCase_      :       Any          =       self.remap_to_used(_A      )
											UpperCAmelCase_      :       Dict          =       min_encoding_indices.reshape(-1				, 1      )  # flatten

								if self.sane_index_shape:
											UpperCAmelCase_      :       Dict          =       min_encoding_indices.reshape(z_q.shape[0]				, z_q.shape[2]				, z_q.shape[3]      )

								return z_q, loss, (perplexity, min_encodings, min_encoding_indices)





					def 		A      (  self  :		List[Any]				, _A  :		Tuple				, _A  :		Dict      )    ->							str:
								# shape specifying (batch, height, width, channel)
								if self.remap is not None:
											UpperCAmelCase_      :       Tuple          =       indices.reshape(shape[0]				, -1      )  # add batch axis
											UpperCAmelCase_      :       Tuple          =       self.unmap_to_all(_A      )
											UpperCAmelCase_      :       List[Any]          =       indices.reshape(-1      )  # flatten again

								# get quantized latent vectors
								UpperCAmelCase_      :       Any          =       self.embedding(_A      )

								if shape is not None:
											UpperCAmelCase_      :       Optional[int]          =       z_q.view(_A      )
											# reshape back to match original input shape
											UpperCAmelCase_      :       Tuple          =       z_q.permute(0				, 3				, 1				, 2      ).contiguous()

								return z_q






class  snake_case__      (					UpperCamelCase):




					def __init__(  self  :		str				, _A  :		Optional[int]				, _A  :		str=False      )    ->							Optional[Any]:
								UpperCAmelCase_      :       int          =       parameters
								UpperCAmelCase_    ,      UpperCAmelCase_      :       List[str]          =       torch.chunk(_A				, 2				, dim=1      )
								UpperCAmelCase_      :       int          =       torch.clamp(self.logvar				, -30.0				, 20.0      )
								UpperCAmelCase_      :       Tuple          =       deterministic
								UpperCAmelCase_      :       int          =       torch.exp(0.5 * self.logvar      )
								UpperCAmelCase_      :       Any          =       torch.exp(self.logvar      )
								if self.deterministic:
											UpperCAmelCase_      :       List[Any]          =       torch.zeros_like(
											    self.mean				, device=self.parameters.device				, dtype=self.parameters.dtype      )




					def 		A      (  self  :		Any				, _A  :		Optional[torch.Generator] = None      )    ->							torch.FloatTensor:
								# make sure sample is on the same device as the parameters and has same dtype
								UpperCAmelCase_      :       Union[str, Any]          =       randn_tensor(
								    self.mean.shape				, generator=_A				, device=self.parameters.device				, dtype=self.parameters.dtype      )
								UpperCAmelCase_      :       List[str]          =       self.mean + self.std * sample
								return x




					def 		A      (  self  :		Tuple				, _A  :		str=None      )    ->							Optional[Any]:
								if self.deterministic:
											return torch.Tensor([0.0]      )
								else:
											if other is None:
														return 0.5 * torch.sum(torch.pow(self.mean				, 2      ) + self.var - 1.0 - self.logvar				, dim=[1, 2, 3]      )
											else:
														return 0.5 * torch.sum(
														    torch.pow(self.mean - other.mean				, 2      ) / other.var
														    + self.var / other.var
														    - 1.0
														    - self.logvar
														    + other.logvar				, dim=[1, 2, 3]				, )




					def 		A      (  self  :		int				, _A  :		List[Any]				, _A  :		int=[1, 2, 3]      )    ->							str:
								if self.deterministic:
											return torch.Tensor([0.0]      )
								UpperCAmelCase_      :       int          =       np.log(2.0 * np.pi      )
								return 0.5 * torch.sum(logtwopi + self.logvar + torch.pow(sample - self.mean				, 2      ) / self.var				, dim=_A      )





					def 		A      (  self  :		List[Any]      )    ->							Any:
								return self.mean










'''simple docstring'''





import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
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 MobileNetVaImageProcessor


class  snake_case__      (					unittest.TestCase):




					def __init__(  self  :		Optional[Any]				, _A  :		int				, _A  :		List[Any]=7				, _A  :		Tuple=3				, _A  :		int=18				, _A  :		Union[str, Any]=30				, _A  :		Any=4_00				, _A  :		List[Any]=True				, _A  :		Optional[int]=None				, _A  :		Optional[Any]=True				, _A  :		Union[str, Any]=None				, )    ->							Optional[int]:
								UpperCAmelCase_      :       Optional[Any]          =       size if size is not None else {'''shortest_edge''': 20}
								UpperCAmelCase_      :       Dict          =       crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
								UpperCAmelCase_      :       List[Any]          =       parent
								UpperCAmelCase_      :       List[Any]          =       batch_size
								UpperCAmelCase_      :       Optional[Any]          =       num_channels
								UpperCAmelCase_      :       Optional[Any]          =       image_size
								UpperCAmelCase_      :       Union[str, Any]          =       min_resolution
								UpperCAmelCase_      :       List[str]          =       max_resolution
								UpperCAmelCase_      :       Union[str, Any]          =       do_resize
								UpperCAmelCase_      :       Any          =       size
								UpperCAmelCase_      :       Union[str, Any]          =       do_center_crop
								UpperCAmelCase_      :       Any          =       crop_size





					def 		A      (  self  :		List[Any]      )    ->							List[Any]:
								return {
								    "do_resize": self.do_resize,
								    "size": self.size,
								    "do_center_crop": self.do_center_crop,
								    "crop_size": self.crop_size,
								}






@require_torch
@require_vision
class  snake_case__      (					UpperCamelCase     ,				unittest.TestCase):
					a_        =					MobileNetVaImageProcessor if is_vision_available() else None




					def 		A      (  self  :		List[Any]      )    ->							List[str]:
								UpperCAmelCase_      :       Dict          =       MobileNetVaImageProcessingTester(self      )




					@property
					def 		A      (  self  :		Optional[Any]      )    ->							Any:
								return self.image_processor_tester.prepare_image_processor_dict()




					def 		A      (  self  :		List[str]      )    ->							Dict:
								UpperCAmelCase_      :       int          =       self.image_processing_class(**self.image_processor_dict      )
								self.assertTrue(hasattr(_A				, '''do_resize'''      )      )
								self.assertTrue(hasattr(_A				, '''size'''      )      )
								self.assertTrue(hasattr(_A				, '''do_center_crop'''      )      )
								self.assertTrue(hasattr(_A				, '''crop_size'''      )      )




					def 		A      (  self  :		Tuple      )    ->							Optional[int]:
								UpperCAmelCase_      :       Any          =       self.image_processing_class.from_dict(self.image_processor_dict      )
								self.assertEqual(image_processor.size				, {'''shortest_edge''': 20}      )
								self.assertEqual(image_processor.crop_size				, {'''height''': 18, '''width''': 18}      )

								UpperCAmelCase_      :       List[str]          =       self.image_processing_class.from_dict(self.image_processor_dict				, size=42				, crop_size=84      )
								self.assertEqual(image_processor.size				, {'''shortest_edge''': 42}      )
								self.assertEqual(image_processor.crop_size				, {'''height''': 84, '''width''': 84}      )




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




					def 		A      (  self  :		List[Any]      )    ->							Optional[Any]:
								# Initialize image_processing
								UpperCAmelCase_      :       List[Any]          =       self.image_processing_class(**self.image_processor_dict      )
								# create random PIL images
								UpperCAmelCase_      :       Optional[int]          =       prepare_image_inputs(self.image_processor_tester				, equal_resolution=_A      )
								for image in image_inputs:
											self.assertIsInstance(_A				, Image.Image      )

								# Test not batched input
								UpperCAmelCase_      :       Union[str, Any]          =       image_processing(image_inputs[0]				, return_tensors='''pt'''      ).pixel_values
								self.assertEqual(
								    encoded_images.shape				, (
								        1,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size['''height'''],
								        self.image_processor_tester.crop_size['''width'''],
								    )				, )

								# Test batched
								UpperCAmelCase_      :       List[Any]          =       image_processing(_A				, return_tensors='''pt'''      ).pixel_values
								self.assertEqual(
								    encoded_images.shape				, (
								        self.image_processor_tester.batch_size,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size['''height'''],
								        self.image_processor_tester.crop_size['''width'''],
								    )				, )




					def 		A      (  self  :		str      )    ->							List[str]:
								# Initialize image_processing
								UpperCAmelCase_      :       Tuple          =       self.image_processing_class(**self.image_processor_dict      )
								# create random numpy tensors
								UpperCAmelCase_      :       Any          =       prepare_image_inputs(self.image_processor_tester				, equal_resolution=_A				, numpify=_A      )
								for image in image_inputs:
											self.assertIsInstance(_A				, np.ndarray      )

								# Test not batched input
								UpperCAmelCase_      :       str          =       image_processing(image_inputs[0]				, return_tensors='''pt'''      ).pixel_values
								self.assertEqual(
								    encoded_images.shape				, (
								        1,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size['''height'''],
								        self.image_processor_tester.crop_size['''width'''],
								    )				, )

								# Test batched
								UpperCAmelCase_      :       List[Any]          =       image_processing(_A				, return_tensors='''pt'''      ).pixel_values
								self.assertEqual(
								    encoded_images.shape				, (
								        self.image_processor_tester.batch_size,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size['''height'''],
								        self.image_processor_tester.crop_size['''width'''],
								    )				, )





					def 		A      (  self  :		Optional[int]      )    ->							Dict:
								# Initialize image_processing
								UpperCAmelCase_      :       Dict          =       self.image_processing_class(**self.image_processor_dict      )
								# create random PyTorch tensors
								UpperCAmelCase_      :       Union[str, Any]          =       prepare_image_inputs(self.image_processor_tester				, equal_resolution=_A				, torchify=_A      )
								for image in image_inputs:
											self.assertIsInstance(_A				, torch.Tensor      )

								# Test not batched input
								UpperCAmelCase_      :       Any          =       image_processing(image_inputs[0]				, return_tensors='''pt'''      ).pixel_values
								self.assertEqual(
								    encoded_images.shape				, (
								        1,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size['''height'''],
								        self.image_processor_tester.crop_size['''width'''],
								    )				, )

								# Test batched
								UpperCAmelCase_      :       List[str]          =       image_processing(_A				, return_tensors='''pt'''      ).pixel_values
								self.assertEqual(
								    encoded_images.shape				, (
								        self.image_processor_tester.batch_size,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size['''height'''],
								        self.image_processor_tester.crop_size['''width'''],
								    )				, )


