
"""simple docstring"""



from typing import Dict, List, Optional, Tuple, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    flip_channel_order,
    get_resize_output_image_size,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, is_vision_available, logging


if is_vision_available():
	import PIL

if is_torch_available():
	import torch


_snake_case          =						logging.get_logger(__name__)
class        _SCREAMING_SNAKE_CASE  (  UpperCAmelCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							Dict							=					["pixel_values"]


				def __init__(					self	:			Dict				,     UpperCAmelCase_	:			bool = True				,     UpperCAmelCase_	:			Dict[str, int] = None				,     UpperCAmelCase_	:			PILImageResampling = PILImageResampling.BILINEAR				,     UpperCAmelCase_	:			bool = True				,     UpperCAmelCase_	:			Union[int, float] = 1 / 255				,     UpperCAmelCase_	:			bool = True				,     UpperCAmelCase_	:			Dict[str, int] = None				,     UpperCAmelCase_	:			bool = True				,     **UpperCAmelCase_	:			Union[str, Any]				,     )		->  None:







											"""simple docstring"""




											super().__init__(**UpperCAmelCase_  )
											_lowerCAmelCase  	=			size if size is not None else {'shortest_edge': 224}
											_lowerCAmelCase  	=			get_size_dict(UpperCAmelCase_				,     default_to_square=UpperCAmelCase_  )
											_lowerCAmelCase  	=			crop_size if crop_size is not None else {'height': 256, 'width': 256}
											_lowerCAmelCase  	=			get_size_dict(UpperCAmelCase_				,     param_name='crop_size'  )

											_lowerCAmelCase  	=			do_resize
											_lowerCAmelCase  	=			size
											_lowerCAmelCase  	=			resample
											_lowerCAmelCase  	=			do_rescale
											_lowerCAmelCase  	=			rescale_factor
											_lowerCAmelCase  	=			do_center_crop
											_lowerCAmelCase  	=			crop_size
											_lowerCAmelCase  	=			do_flip_channel_order


				def 				__lowerCamelCase	(					self	:			List[Any]				,     UpperCAmelCase_	:			np.ndarray				,     UpperCAmelCase_	:			Dict[str, int]				,     UpperCAmelCase_	:			PILImageResampling = PIL.Image.BILINEAR				,     UpperCAmelCase_	:			Optional[Union[str, ChannelDimension]] = None				,     **UpperCAmelCase_	:			Optional[Any]				,     )		->  np.ndarray:







											"""simple docstring"""




											_lowerCAmelCase  	=			get_size_dict(UpperCAmelCase_				,     default_to_square=UpperCAmelCase_  )
											if "shortest_edge" not in size:
																		raise ValueError(F"""The `size` dictionary must contain the key `shortest_edge`. Got {size.keys()}"""  )
											_lowerCAmelCase  	=			get_resize_output_image_size(UpperCAmelCase_				,     size=size['shortest_edge']				,     default_to_square=UpperCAmelCase_  )
											return resize(UpperCAmelCase_				,     size=UpperCAmelCase_				,     resample=UpperCAmelCase_				,     data_format=UpperCAmelCase_				,     **UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Dict				,     UpperCAmelCase_	:			np.ndarray				,     UpperCAmelCase_	:			Dict[str, int]				,     UpperCAmelCase_	:			Optional[Union[str, ChannelDimension]] = None				,     **UpperCAmelCase_	:			Dict				,     )		->  np.ndarray:







											"""simple docstring"""




											_lowerCAmelCase  	=			get_size_dict(UpperCAmelCase_  )
											if "height" not in size or "width" not in size:
																		raise ValueError(F"""The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}"""  )
											return center_crop(UpperCAmelCase_				,     size=(size['height'], size['width'])				,     data_format=UpperCAmelCase_				,     **UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Optional[int]				,     UpperCAmelCase_	:			np.ndarray				,     UpperCAmelCase_	:			Union[int, float]				,     UpperCAmelCase_	:			Optional[Union[str, ChannelDimension]] = None				,     **UpperCAmelCase_	:			int				,     )		->  Optional[Any]:







											"""simple docstring"""




											return rescale(UpperCAmelCase_				,     scale=UpperCAmelCase_				,     data_format=UpperCAmelCase_				,     **UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Union[str, Any]				,     UpperCAmelCase_	:			np.ndarray				,     UpperCAmelCase_	:			Optional[Union[str, ChannelDimension]] = None  )		->  np.ndarray:







											"""simple docstring"""




											return flip_channel_order(UpperCAmelCase_				,     data_format=UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Any				,     UpperCAmelCase_	:			ImageInput				,     UpperCAmelCase_	:			bool = None				,     UpperCAmelCase_	:			Dict[str, int] = None				,     UpperCAmelCase_	:			PILImageResampling = None				,     UpperCAmelCase_	:			bool = None				,     UpperCAmelCase_	:			float = None				,     UpperCAmelCase_	:			bool = None				,     UpperCAmelCase_	:			Dict[str, int] = None				,     UpperCAmelCase_	:			bool = None				,     UpperCAmelCase_	:			Optional[Union[str, TensorType]] = None				,     UpperCAmelCase_	:			ChannelDimension = ChannelDimension.FIRST				,     **UpperCAmelCase_	:			Tuple				,     )		->  PIL.Image.Image:







											"""simple docstring"""




											_lowerCAmelCase  	=			do_resize if do_resize is not None else self.do_resize
											_lowerCAmelCase  	=			resample if resample is not None else self.resample
											_lowerCAmelCase  	=			do_rescale if do_rescale is not None else self.do_rescale
											_lowerCAmelCase  	=			rescale_factor if rescale_factor is not None else self.rescale_factor
											_lowerCAmelCase  	=			do_center_crop if do_center_crop is not None else self.do_center_crop
											_lowerCAmelCase  	=			(
											    do_flip_channel_order if do_flip_channel_order is not None else self.do_flip_channel_order
											)

											_lowerCAmelCase  	=			size if size is not None else self.size
											_lowerCAmelCase  	=			get_size_dict(UpperCAmelCase_				,     default_to_square=UpperCAmelCase_  )
											_lowerCAmelCase  	=			crop_size if crop_size is not None else self.crop_size
											_lowerCAmelCase  	=			get_size_dict(UpperCAmelCase_				,     param_name='crop_size'  )

											_lowerCAmelCase  	=			make_list_of_images(UpperCAmelCase_  )

											if not valid_images(UpperCAmelCase_  ):
																		raise ValueError(
																		    'Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '
																		    'torch.Tensor, tf.Tensor or jax.ndarray.'  )

											if do_resize and size is None:
																		raise ValueError('Size must be specified if do_resize is True.'  )

											if do_rescale and rescale_factor is None:
																		raise ValueError('Rescale factor must be specified if do_rescale is True.'  )

											if do_center_crop and crop_size is None:
																		raise ValueError('Crop size must be specified if do_center_crop is True.'  )

											# All transformations expect numpy arrays.
											_lowerCAmelCase  	=			[to_numpy_array(UpperCAmelCase_  ) for image in images]

											if do_resize:
																		_lowerCAmelCase  	=			[self.resize(image=UpperCAmelCase_				,     size=UpperCAmelCase_				,     resample=UpperCAmelCase_  ) for image in images]

											if do_center_crop:
																		_lowerCAmelCase  	=			[self.center_crop(image=UpperCAmelCase_				,     size=UpperCAmelCase_  ) for image in images]

											if do_rescale:
																		_lowerCAmelCase  	=			[self.rescale(image=UpperCAmelCase_				,     scale=UpperCAmelCase_  ) for image in images]

											# the pretrained checkpoints assume images are BGR, not RGB
											if do_flip_channel_order:
																		_lowerCAmelCase  	=			[self.flip_channel_order(image=UpperCAmelCase_  ) for image in images]

											_lowerCAmelCase  	=			[to_channel_dimension_format(UpperCAmelCase_				,     UpperCAmelCase_  ) for image in images]

											_lowerCAmelCase  	=			{'pixel_values': images}
											return BatchFeature(data=UpperCAmelCase_				,     tensor_type=UpperCAmelCase_  )







				def 				__lowerCamelCase	(					self	:			List[str]				,     UpperCAmelCase_	:			Optional[int]				,     UpperCAmelCase_	:			List[Tuple] = None  )		->  str:







											"""simple docstring"""




											_lowerCAmelCase  	=			outputs.logits

											# Resize logits and compute semantic segmentation maps
											if target_sizes is not None:
																		if len(UpperCAmelCase_  ) != len(UpperCAmelCase_  ):
																									raise ValueError(
																									    'Make sure that you pass in as many target sizes as the batch dimension of the logits'  )

																		if is_torch_tensor(UpperCAmelCase_  ):
																									_lowerCAmelCase  	=			target_sizes.numpy()

																		_lowerCAmelCase  	=			[]

																		for idx in range(len(UpperCAmelCase_  )  ):
																									_lowerCAmelCase  	=			torch.nn.functional.interpolate(
																									    logits[idx].unsqueeze(dim=0  )				,     size=target_sizes[idx]				,     mode='bilinear'				,     align_corners=UpperCAmelCase_  )
																									_lowerCAmelCase  	=			resized_logits[0].argmax(dim=0  )
																									semantic_segmentation.append(UpperCAmelCase_  )
											else:
																		_lowerCAmelCase  	=			logits.argmax(dim=1  )
																		_lowerCAmelCase  	=			[semantic_segmentation[i] for i in range(semantic_segmentation.shape[0]  )]

											return semantic_segmentation








"""simple docstring"""



from ...configuration_utils import PretrainedConfig
from ...utils import logging


_snake_case          =						logging.get_logger(__name__)

_snake_case          =						{
    '''abeja/gpt-neox-japanese-2.7b''': '''https://huggingface.co/abeja/gpt-neox-japanese-2.7b/resolve/main/config.json''',
}
class        _SCREAMING_SNAKE_CASE  (  UpperCAmelCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							Dict							=					"gpt_neox_japanese"


				def __init__(					self	:			Optional[Any]				,     UpperCAmelCase_	:			Any=32_000				,     UpperCAmelCase_	:			Dict=2_560				,     UpperCAmelCase_	:			Union[str, Any]=32				,     UpperCAmelCase_	:			Any=32				,     UpperCAmelCase_	:			Optional[Any]=4				,     UpperCAmelCase_	:			int="gelu"				,     UpperCAmelCase_	:			Union[str, Any]=1.00				,     UpperCAmelCase_	:			Any=10_000				,     UpperCAmelCase_	:			Optional[int]=2_048				,     UpperCAmelCase_	:			Optional[Any]=0.02				,     UpperCAmelCase_	:			Tuple=1E-5				,     UpperCAmelCase_	:			int=True				,     UpperCAmelCase_	:			Tuple=31_996				,     UpperCAmelCase_	:			List[Any]=31_999				,     UpperCAmelCase_	:			str=0.1				,     UpperCAmelCase_	:			List[Any]=0.0				,     **UpperCAmelCase_	:			str				,     )		->  int:







											"""simple docstring"""




											super().__init__(bos_token_id=UpperCAmelCase_				,     eos_token_id=UpperCAmelCase_				,     **UpperCAmelCase_  )
											_lowerCAmelCase  	=			vocab_size
											_lowerCAmelCase  	=			max_position_embeddings
											_lowerCAmelCase  	=			hidden_size
											_lowerCAmelCase  	=			num_hidden_layers
											_lowerCAmelCase  	=			num_attention_heads
											_lowerCAmelCase  	=			intermediate_multiple_size
											_lowerCAmelCase  	=			hidden_act
											_lowerCAmelCase  	=			rotary_pct
											_lowerCAmelCase  	=			rotary_emb_base
											_lowerCAmelCase  	=			initializer_range
											_lowerCAmelCase  	=			layer_norm_eps
											_lowerCAmelCase  	=			use_cache
											_lowerCAmelCase  	=			attention_dropout
											_lowerCAmelCase  	=			hidden_dropout






