'''simple docstring'''
import tempfile
import unittest
from pathlib import Path
from shutil import copyfile

from transformers import BatchEncoding, MarianTokenizer
from transformers.testing_utils import get_tests_dir, require_sentencepiece, slow
from transformers.utils import is_sentencepiece_available, is_tf_available, is_torch_available


if is_sentencepiece_available():
      from transformers.models.marian.tokenization_marian import VOCAB_FILES_NAMES, save_json

from ...test_tokenization_common import TokenizerTesterMixin


lowercase__  :      int        =					get_tests_dir("fixtures/test_sentencepiece.model")

lowercase__  :      Optional[Any]        =					{"target_lang": "fi", "source_lang": "en"}
lowercase__  :      Any        =					">>zh<<"
lowercase__  :      Optional[int]        =					"Helsinki-NLP/"

if is_torch_available():
      lowercase__  :      Optional[Any]        =					"pt"
elif is_tf_available():
      lowercase__  :      Tuple        =					"tf"
else:
      lowercase__  :      int        =					"jax"







@require_sentencepiece
class lowerCamelCase							(	lowerCamelCase     ,		unittest.TestCase					):




  '''simple docstring'''



  lowerCAmelCase__										=	MarianTokenizer
  lowerCAmelCase__										=	False
  lowerCAmelCase__										=	True






  def  lowerCAmelCase__ (      self			:       List[Any]  )				->int:
        super().setUp()
        UpperCAmelCase_            =  ['''</s>''', '''<unk>''', '''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est''', '''\u0120''', '''<pad>''']
        UpperCAmelCase_            =  dict(zip(UpperCAmelCase__  ,							range(len(UpperCAmelCase__  )  )  )  )
        UpperCAmelCase_            =  Path(self.tmpdirname  )
        save_json(UpperCAmelCase__  ,							save_dir / VOCAB_FILES_NAMES['''vocab''']  )
        save_json(UpperCAmelCase__  ,							save_dir / VOCAB_FILES_NAMES['''tokenizer_config_file''']  )
        if not (save_dir / VOCAB_FILES_NAMES["source_spm"]).exists():
              copyfile(UpperCAmelCase__  ,							save_dir / VOCAB_FILES_NAMES['''source_spm''']  )
              copyfile(UpperCAmelCase__  ,							save_dir / VOCAB_FILES_NAMES['''target_spm''']  )

        UpperCAmelCase_            =  MarianTokenizer.from_pretrained(self.tmpdirname  )
        tokenizer.save_pretrained(self.tmpdirname  )






  def  lowerCAmelCase__ (      self			:       str  ,							**UpperCAmelCase__			:       int  )				->MarianTokenizer:
        return MarianTokenizer.from_pretrained(self.tmpdirname  ,							**UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       Tuple  ,							UpperCAmelCase__			:       List[str]  )				->int:
        return (
            "This is a test",
            "This is a test",
        )






  def  lowerCAmelCase__ (      self			:       Any  )				->int:
        UpperCAmelCase_            =  '''</s>'''
        UpperCAmelCase_            =  0

        self.assertEqual(self.get_tokenizer()._convert_token_to_id(UpperCAmelCase__  )  ,							UpperCAmelCase__  )
        self.assertEqual(self.get_tokenizer()._convert_id_to_token(UpperCAmelCase__  )  ,							UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       Any  )				->Union[str, Any]:
        UpperCAmelCase_            =  list(self.get_tokenizer().get_vocab().keys()  )

        self.assertEqual(vocab_keys[0]  ,							'''</s>'''  )
        self.assertEqual(vocab_keys[1]  ,							'''<unk>'''  )
        self.assertEqual(vocab_keys[-1]  ,							'''<pad>'''  )
        self.assertEqual(len(UpperCAmelCase__  )  ,							9  )






  def  lowerCAmelCase__ (      self			:       Optional[int]  )				->List[Any]:
        self.assertEqual(self.get_tokenizer().vocab_size  ,							9  )






  def  lowerCAmelCase__ (      self			:       str  )				->str:
        UpperCAmelCase_            =  MarianTokenizer.from_pretrained(f"""{ORG_NAME}opus-mt-en-de"""  )
        UpperCAmelCase_            =  en_de_tokenizer(['''I am a small frog''']  ,							return_tensors=UpperCAmelCase__  )
        self.assertIsInstance(UpperCAmelCase__  ,							UpperCAmelCase__  )
        UpperCAmelCase_            =  [38, 121, 14, 697, 3_8848, 0]
        self.assertListEqual(UpperCAmelCase__  ,							batch.input_ids[0]  )

        UpperCAmelCase_            =  tempfile.mkdtemp()
        en_de_tokenizer.save_pretrained(UpperCAmelCase__  )
        UpperCAmelCase_            =  [x.name for x in Path(UpperCAmelCase__  ).glob('''*'''  )]
        self.assertIn('''source.spm'''  ,							UpperCAmelCase__  )
        MarianTokenizer.from_pretrained(UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       Union[str, Any]  )				->List[str]:
        UpperCAmelCase_            =  self.get_tokenizer()

        UpperCAmelCase_            =  tok(
            ['''I am a small frog''' * 1000, '''I am a small frog''']  ,							padding=UpperCAmelCase__  ,							truncation=UpperCAmelCase__  ,							return_tensors=UpperCAmelCase__  )
        self.assertIsInstance(UpperCAmelCase__  ,							UpperCAmelCase__  )
        self.assertEqual(batch.input_ids.shape  ,							(2, 512)  )






  def  lowerCAmelCase__ (      self			:       Any  )				->Optional[Any]:
        UpperCAmelCase_            =  self.get_tokenizer()
        UpperCAmelCase_            =  tok(['''I am a tiny frog''', '''I am a small frog''']  ,							padding=UpperCAmelCase__  ,							return_tensors=UpperCAmelCase__  )
        self.assertIsInstance(UpperCAmelCase__  ,							UpperCAmelCase__  )
        self.assertEqual(batch_smaller.input_ids.shape  ,							(2, 10)  )






  @slow
  def  lowerCAmelCase__ (      self			:       int  )				->Any:
        # fmt: off
        UpperCAmelCase_            =  {'''input_ids''': [[4_3495, 462, 20, 4_2164, 1369, 52, 464, 132, 1703, 492, 13, 7491, 3_8999, 6, 8, 464, 132, 1703, 492, 13, 4669, 3_7867, 13, 7525, 27, 1593, 988, 13, 3_3972, 7029, 6, 20, 8251, 383, 2, 270, 5866, 3788, 2, 2353, 8251, 1_2338, 2, 1_3958, 387, 2, 3629, 6953, 188, 2900, 2, 1_3958, 8011, 1_1501, 23, 8460, 4073, 3_4009, 20, 435, 1_1439, 27, 8, 8460, 4073, 6004, 20, 9988, 375, 27, 33, 266, 1945, 1076, 1350, 3_7867, 3288, 5, 577, 1076, 4374, 8, 5082, 5, 2_6453, 257, 556, 403, 2, 242, 132, 383, 316, 492, 8, 1_0767, 6, 316, 304, 4239, 3, 0], [148, 1_5722, 19, 1839, 12, 1350, 13, 2_2327, 5082, 5418, 4_7567, 3_5938, 59, 318, 1_9552, 108, 2183, 54, 1_4976, 4835, 32, 547, 1114, 8, 315, 2417, 5, 92, 1_9088, 3, 0, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100], [36, 6395, 1_2570, 3_9147, 1_1597, 6, 266, 4, 4_5405, 7296, 3, 0, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100, 5_8100]], '''attention_mask''': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
        # fmt: on

        self.tokenizer_integration_test_util(
            expected_encoding=UpperCAmelCase__  ,							model_name='''Helsinki-NLP/opus-mt-en-de'''  ,							revision='''1a8c2263da11e68e50938f97e10cd57820bd504c'''  ,							decode_kwargs={'''use_source_tokenizer''': True}  ,							)






  def  lowerCAmelCase__ (      self			:       int  )				->Any:
        UpperCAmelCase_            =  MarianTokenizer.from_pretrained('''hf-internal-testing/test-marian-two-vocabs'''  )

        UpperCAmelCase_            =  '''Tämä on testi'''
        UpperCAmelCase_            =  '''This is a test'''

        UpperCAmelCase_            =  [76, 7, 2047, 2]
        UpperCAmelCase_            =  [69, 12, 11, 940, 2]

        UpperCAmelCase_            =  tokenizer(UpperCAmelCase__  ).input_ids
        self.assertListEqual(UpperCAmelCase__  ,							UpperCAmelCase__  )

        UpperCAmelCase_            =  tokenizer(text_target=UpperCAmelCase__  ).input_ids
        self.assertListEqual(UpperCAmelCase__  ,							UpperCAmelCase__  )

        UpperCAmelCase_            =  tokenizer.decode(UpperCAmelCase__  ,							skip_special_tokens=UpperCAmelCase__  )
        self.assertEqual(UpperCAmelCase__  ,							UpperCAmelCase__  )






'''simple docstring'''
import math
from typing import Dict, Iterable, List, Optional, Tuple, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    get_image_size,
    is_torch_available,
    is_torch_tensor,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_torch_available():
      import torch

if is_vision_available():
      import PIL


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



def  __lowerCamelCase       (      _UpperCamelCase  :  np.ndarray							,    _UpperCamelCase  :  Union[int, Iterable[int]]							,    _UpperCamelCase  :  bool							,    _UpperCamelCase  :  int					):


      '''simple docstring'''


      def constraint_to_multiple_of(_UpperCamelCase  :  int							,    _UpperCamelCase  :  Tuple							,    _UpperCamelCase  :  Optional[int]=0							,    _UpperCamelCase  :  str=None					):
            UpperCAmelCase_            =  round(val / multiple					) * multiple

            if max_val is not None and x > max_val:
                  UpperCAmelCase_            =  math.floor(val / multiple					) * multiple

            if x < min_val:
                  UpperCAmelCase_            =  math.ceil(val / multiple					) * multiple

            return x

      UpperCAmelCase_            =  (output_size, output_size) if isinstance(_UpperCamelCase							,    _UpperCamelCase					) else output_size

      UpperCAmelCase_      ,		UpperCAmelCase_            =  get_image_size(_UpperCamelCase					)
      UpperCAmelCase_      ,		UpperCAmelCase_            =  output_size

      # determine new height and width
      UpperCAmelCase_            =  output_height / input_height
      UpperCAmelCase_            =  output_width / input_width

      if keep_aspect_ratio:
            # scale as little as possible
            if abs(1 - scale_width					) < abs(1 - scale_height					):
                  # fit width
                  UpperCAmelCase_            =  scale_width
            else:
                  # fit height
                  UpperCAmelCase_            =  scale_height

      UpperCAmelCase_            =  constraint_to_multiple_of(scale_height * input_height							,    multiple=_UpperCamelCase					)
      UpperCAmelCase_            =  constraint_to_multiple_of(scale_width * input_width							,    multiple=_UpperCamelCase					)

      return (new_height, new_width)







class lowerCamelCase							(	lowerCamelCase					):




  '''simple docstring'''



  lowerCAmelCase__										=	['''pixel_values''']






  def __init__(      self			:       Any  ,							UpperCAmelCase__			:       bool = True  ,							UpperCAmelCase__			:       Dict[str, int] = None  ,							UpperCAmelCase__			:       PILImageResampling = PILImageResampling.BILINEAR  ,							UpperCAmelCase__			:       bool = False  ,							UpperCAmelCase__			:       int = 1  ,							UpperCAmelCase__			:       bool = True  ,							UpperCAmelCase__			:       Union[int, float] = 1 / 255  ,							UpperCAmelCase__			:       bool = True  ,							UpperCAmelCase__			:       Optional[Union[float, List[float]]] = None  ,							UpperCAmelCase__			:       Optional[Union[float, List[float]]] = None  ,							**UpperCAmelCase__			:       str  ,							)				->None:
        super().__init__(**UpperCAmelCase__  )
        UpperCAmelCase_            =  size if size is not None else {'''height''': 384, '''width''': 384}
        UpperCAmelCase_            =  get_size_dict(UpperCAmelCase__  )
        UpperCAmelCase_            =  do_resize
        UpperCAmelCase_            =  size
        UpperCAmelCase_            =  keep_aspect_ratio
        UpperCAmelCase_            =  ensure_multiple_of
        UpperCAmelCase_            =  resample
        UpperCAmelCase_            =  do_rescale
        UpperCAmelCase_            =  rescale_factor
        UpperCAmelCase_            =  do_normalize
        UpperCAmelCase_            =  image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
        UpperCAmelCase_            =  image_std if image_std is not None else IMAGENET_STANDARD_STD






  def  lowerCAmelCase__ (      self			:       Union[str, Any]  ,							UpperCAmelCase__			:       np.ndarray  ,							UpperCAmelCase__			:       Dict[str, int]  ,							UpperCAmelCase__			:       bool = False  ,							UpperCAmelCase__			:       int = 1  ,							UpperCAmelCase__			:       PILImageResampling = PILImageResampling.BICUBIC  ,							UpperCAmelCase__			:       Optional[Union[str, ChannelDimension]] = None  ,							**UpperCAmelCase__			:       List[str]  ,							)				->np.ndarray:
        UpperCAmelCase_            =  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()}"""  )
        UpperCAmelCase_            =  get_resize_output_image_size(
            UpperCAmelCase__  ,							output_size=(size['''height'''], size['''width'''])  ,							keep_aspect_ratio=UpperCAmelCase__  ,							multiple=UpperCAmelCase__  ,							)
        return resize(UpperCAmelCase__  ,							size=UpperCAmelCase__  ,							resample=UpperCAmelCase__  ,							data_format=UpperCAmelCase__  ,							**UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       int  ,							UpperCAmelCase__			:       np.ndarray  ,							UpperCAmelCase__			:       Union[int, float]  ,							UpperCAmelCase__			:       Optional[Union[str, ChannelDimension]] = None  ,							**UpperCAmelCase__			:       Optional[Any]  ,							)				->Any:
        return rescale(UpperCAmelCase__  ,							scale=UpperCAmelCase__  ,							data_format=UpperCAmelCase__  ,							**UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       List[Any]  ,							UpperCAmelCase__			:       np.ndarray  ,							UpperCAmelCase__			:       Union[float, List[float]]  ,							UpperCAmelCase__			:       Union[float, List[float]]  ,							UpperCAmelCase__			:       Optional[Union[str, ChannelDimension]] = None  ,							**UpperCAmelCase__			:       Optional[int]  ,							)				->np.ndarray:
        return normalize(UpperCAmelCase__  ,							mean=UpperCAmelCase__  ,							std=UpperCAmelCase__  ,							data_format=UpperCAmelCase__  ,							**UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       str  ,							UpperCAmelCase__			:       ImageInput  ,							UpperCAmelCase__			:       bool = None  ,							UpperCAmelCase__			:       int = None  ,							UpperCAmelCase__			:       bool = None  ,							UpperCAmelCase__			:       int = None  ,							UpperCAmelCase__			:       PILImageResampling = None  ,							UpperCAmelCase__			:       bool = None  ,							UpperCAmelCase__			:       float = None  ,							UpperCAmelCase__			:       bool = None  ,							UpperCAmelCase__			:       Optional[Union[float, List[float]]] = None  ,							UpperCAmelCase__			:       Optional[Union[float, List[float]]] = None  ,							UpperCAmelCase__			:       Optional[Union[str, TensorType]] = None  ,							UpperCAmelCase__			:       ChannelDimension = ChannelDimension.FIRST  ,							**UpperCAmelCase__			:       Any  ,							)				->PIL.Image.Image:
        UpperCAmelCase_            =  do_resize if do_resize is not None else self.do_resize
        UpperCAmelCase_            =  size if size is not None else self.size
        UpperCAmelCase_            =  get_size_dict(UpperCAmelCase__  )
        UpperCAmelCase_            =  keep_aspect_ratio if keep_aspect_ratio is not None else self.keep_aspect_ratio
        UpperCAmelCase_            =  ensure_multiple_of if ensure_multiple_of is not None else self.ensure_multiple_of
        UpperCAmelCase_            =  resample if resample is not None else self.resample
        UpperCAmelCase_            =  do_rescale if do_rescale is not None else self.do_rescale
        UpperCAmelCase_            =  rescale_factor if rescale_factor is not None else self.rescale_factor
        UpperCAmelCase_            =  do_normalize if do_normalize is not None else self.do_normalize
        UpperCAmelCase_            =  image_mean if image_mean is not None else self.image_mean
        UpperCAmelCase_            =  image_std if image_std is not None else self.image_std

        UpperCAmelCase_            =  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 or resample is None:
              raise ValueError('''Size and resample 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_normalize and (image_mean is None or image_std is None):
              raise ValueError('''Image mean and std must be specified if do_normalize is True.'''  )

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

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

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

        if do_normalize:
              UpperCAmelCase_            =  [self.normalize(image=UpperCAmelCase__  ,							mean=UpperCAmelCase__  ,							std=UpperCAmelCase__  ) for image in images]

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

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






  def  lowerCAmelCase__ (      self			:       List[str]  ,							UpperCAmelCase__			:       List[Any]  ,							UpperCAmelCase__			:       List[Tuple] = None  )				->Optional[Any]:
        UpperCAmelCase_            =  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__  ):
                    UpperCAmelCase_            =  target_sizes.numpy()

              UpperCAmelCase_            =  []

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

        return semantic_segmentation





