


"""simple docstring"""


import unittest

from transformers import LayoutLMConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import (
		    LayoutLMForMaskedLM,
		    LayoutLMForQuestionAnswering,
		    LayoutLMForSequenceClassification,
		    LayoutLMForTokenClassification,
		    LayoutLMModel,
		)
class snake_case   :







		def __init__(       self   :							Dict     , a__   :							int     , a__   :							Any=13     , a__   :							List[str]=7     , a__   :							Optional[Any]=True     , a__   :							str=True     , a__   :							List[Any]=True     , a__   :							Optional[int]=True     , a__   :							List[str]=99     , a__   :							List[Any]=32     , a__   :							Any=5     , a__   :							List[Any]=4     , a__   :							str=37     , a__   :							Dict="gelu"     , a__   :							Tuple=0.1     , a__   :							List[Any]=0.1     , a__   :							List[Any]=5_12     , a__   :							Optional[int]=16     , a__   :							str=2     , a__   :							Union[str, Any]=0.0_2     , a__   :							Optional[Any]=3     , a__   :							Optional[int]=4     , a__   :							Tuple=None     , a__   :							Optional[Any]=10_00     , )							->    Optional[Any]:





						'''simple docstring'''







						_A       	=      parent
						_A       	=      batch_size
						_A       	=      seq_length
						_A       	=      is_training
						_A       	=      use_input_mask
						_A       	=      use_token_type_ids
						_A       	=      use_labels
						_A       	=      vocab_size
						_A       	=      hidden_size
						_A       	=      num_hidden_layers
						_A       	=      num_attention_heads
						_A       	=      intermediate_size
						_A       	=      hidden_act
						_A       	=      hidden_dropout_prob
						_A       	=      attention_probs_dropout_prob
						_A       	=      max_position_embeddings
						_A       	=      type_vocab_size
						_A       	=      type_sequence_label_size
						_A       	=      initializer_range
						_A       	=      num_labels
						_A       	=      num_choices
						_A       	=      scope
						_A       	=      range_bbox







		def 			a_			(       self   :							str		)							->    str:





						'''simple docstring'''







						_A       	=      ids_tensor([self.batch_size, self.seq_length]     , self.vocab_size		)

						_A       	=      ids_tensor([self.batch_size, self.seq_length, 4]     , self.range_bbox		)
						# Ensure that bbox is legal
						for i in range(bbox.shape[0]		):
										for j in range(bbox.shape[1]		):
														if bbox[i, j, 3] < bbox[i, j, 1]:
																		_A       	=      bbox[i, j, 3]
																		_A       	=      bbox[i, j, 1]
																		_A       	=      t
														if bbox[i, j, 2] < bbox[i, j, 0]:
																		_A       	=      bbox[i, j, 2]
																		_A       	=      bbox[i, j, 0]
																		_A       	=      t

						_A       	=      None
						if self.use_input_mask:
										_A       	=      ids_tensor([self.batch_size, self.seq_length]     , vocab_size=2		)

						_A       	=      None
						if self.use_token_type_ids:
										_A       	=      ids_tensor([self.batch_size, self.seq_length]     , self.type_vocab_size		)

						_A       	=      None
						_A       	=      None
						_A       	=      None
						if self.use_labels:
										_A       	=      ids_tensor([self.batch_size]     , self.type_sequence_label_size		)
										_A       	=      ids_tensor([self.batch_size, self.seq_length]     , self.num_labels		)
										_A       	=      ids_tensor([self.batch_size]     , self.num_choices		)

						_A       	=      self.get_config()

						return config, input_ids, bbox, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels







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





						'''simple docstring'''







						return LayoutLMConfig(
						    vocab_size=self.vocab_size     , hidden_size=self.hidden_size     , num_hidden_layers=self.num_hidden_layers     , num_attention_heads=self.num_attention_heads     , intermediate_size=self.intermediate_size     , hidden_act=self.hidden_act     , hidden_dropout_prob=self.hidden_dropout_prob     , attention_probs_dropout_prob=self.attention_probs_dropout_prob     , max_position_embeddings=self.max_position_embeddings     , type_vocab_size=self.type_vocab_size     , initializer_range=self.initializer_range     , )







		def 			a_			(       self   :							Optional[Any]     , a__   :							str     , a__   :							Optional[int]     , a__   :							Tuple     , a__   :							Dict     , a__   :							List[Any]     , a__   :							Tuple     , a__   :							Dict     , a__   :							Optional[int]		)							->    Dict:





						'''simple docstring'''







						_A       	=      LayoutLMModel(config=a__		)
						model.to(a__		)
						model.eval()
						_A       	=      model(a__     , a__     , attention_mask=a__     , token_type_ids=a__		)
						_A       	=      model(a__     , a__     , token_type_ids=a__		)
						_A       	=      model(a__     , a__		)
						self.parent.assertEqual(result.last_hidden_state.shape     , (self.batch_size, self.seq_length, self.hidden_size)		)
						self.parent.assertEqual(result.pooler_output.shape     , (self.batch_size, self.hidden_size)		)







		def 			a_			(       self   :							Tuple     , a__   :							Optional[Any]     , a__   :							List[str]     , a__   :							List[str]     , a__   :							int     , a__   :							List[str]     , a__   :							Optional[Any]     , a__   :							int     , a__   :							Union[str, Any]		)							->    Any:





						'''simple docstring'''







						_A       	=      LayoutLMForMaskedLM(config=a__		)
						model.to(a__		)
						model.eval()
						_A       	=      model(a__     , a__     , attention_mask=a__     , token_type_ids=a__     , labels=a__		)
						self.parent.assertEqual(result.logits.shape     , (self.batch_size, self.seq_length, self.vocab_size)		)







		def 			a_			(       self   :							int     , a__   :							List[str]     , a__   :							int     , a__   :							Union[str, Any]     , a__   :							Optional[Any]     , a__   :							int     , a__   :							Tuple     , a__   :							Tuple     , a__   :							Optional[int]		)							->    Any:





						'''simple docstring'''







						_A       	=      self.num_labels
						_A       	=      LayoutLMForSequenceClassification(a__		)
						model.to(a__		)
						model.eval()
						_A       	=      model(
						    a__     , a__     , attention_mask=a__     , token_type_ids=a__     , labels=a__		)
						self.parent.assertEqual(result.logits.shape     , (self.batch_size, self.num_labels)		)







		def 			a_			(       self   :							Optional[Any]     , a__   :							Dict     , a__   :							Optional[int]     , a__   :							List[Any]     , a__   :							int     , a__   :							Optional[int]     , a__   :							List[str]     , a__   :							Tuple     , a__   :							int		)							->    List[str]:





						'''simple docstring'''







						_A       	=      self.num_labels
						_A       	=      LayoutLMForTokenClassification(config=a__		)
						model.to(a__		)
						model.eval()
						_A       	=      model(a__     , a__     , attention_mask=a__     , token_type_ids=a__     , labels=a__		)
						self.parent.assertEqual(result.logits.shape     , (self.batch_size, self.seq_length, self.num_labels)		)







		def 			a_			(       self   :							Union[str, Any]     , a__   :							Union[str, Any]     , a__   :							Tuple     , a__   :							int     , a__   :							Tuple     , a__   :							Optional[int]     , a__   :							Any     , a__   :							Union[str, Any]     , a__   :							Optional[Any]		)							->    str:





						'''simple docstring'''







						_A       	=      LayoutLMForQuestionAnswering(config=a__		)
						model.to(a__		)
						model.eval()
						_A       	=      model(
						    a__     , bbox=a__     , attention_mask=a__     , token_type_ids=a__     , start_positions=a__     , end_positions=a__     , )
						self.parent.assertEqual(result.start_logits.shape     , (self.batch_size, self.seq_length)		)
						self.parent.assertEqual(result.end_logits.shape     , (self.batch_size, self.seq_length)		)







		def 			a_			(       self   :							str		)							->    Dict:





						'''simple docstring'''







						_A       	=      self.prepare_config_and_inputs()
						(
						    (
						    _A
						)	,		(
						    _A
						)	,		(
						    _A
						)	,		(
						    _A
						)	,		(
						    _A
						)	,		(
						    _A
						)	,		(
						    _A
						)	,		(
						    _A
						)	,		
						)       	=      config_and_inputs
						_A       	=      {
						    "input_ids": input_ids,
						    "bbox": bbox,
						    "token_type_ids": token_type_ids,
						    "attention_mask": input_mask,
						}
						return config, inputs_dict





@require_torch
class snake_case   (	_UpperCamelCase  ,					_UpperCamelCase  ,					unittest.TestCase):
		__UpperCamelCase							     =      (
		    (
		        LayoutLMModel,
		        LayoutLMForMaskedLM,
		        LayoutLMForSequenceClassification,
		        LayoutLMForTokenClassification,
		        LayoutLMForQuestionAnswering,
		    )
		    if is_torch_available()
		    else None
		)
		__UpperCamelCase							     =      (
		    {
		        'document-question-answering': LayoutLMForQuestionAnswering,
		        'feature-extraction': LayoutLMModel,
		        'fill-mask': LayoutLMForMaskedLM,
		        'text-classification': LayoutLMForSequenceClassification,
		        'token-classification': LayoutLMForTokenClassification,
		        'zero-shot': LayoutLMForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)
		__UpperCamelCase							     =      True







		def 			a_			(       self   :							Any		)							->    Dict:





						'''simple docstring'''







						_A       	=      LayoutLMModelTester(self		)
						_A       	=      ConfigTester(self     , config_class=a__     , hidden_size=37		)







		def 			a_			(       self   :							int		)							->    Dict:





						'''simple docstring'''







						self.config_tester.run_common_tests()







		def 			a_			(       self   :							Tuple		)							->    Tuple:





						'''simple docstring'''







						_A       	=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*a__		)







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





						'''simple docstring'''







						_A       	=      self.model_tester.prepare_config_and_inputs()
						for type in ["absolute", "relative_key", "relative_key_query"]:
										_A       	=      type
										self.model_tester.create_and_check_model(*a__		)







		def 			a_			(       self   :							str		)							->    Optional[Any]:





						'''simple docstring'''







						_A       	=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*a__		)







		def 			a_			(       self   :							int		)							->    str:





						'''simple docstring'''







						_A       	=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*a__		)







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





						'''simple docstring'''







						_A       	=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*a__		)







		def 			a_			(       self   :							int		)							->    int:





						'''simple docstring'''







						_A       	=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*a__		)







		@unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."		)
		def 			a_			(       self   :							List[Any]		)							->    Union[str, Any]:





						'''simple docstring'''







						pass






def   a__			(					)						->						Any:
				# Here we prepare a batch of 2 sequences to test a LayoutLM forward pass on:
				# fmt: off
				_A       	=      torch.tensor([[101,1019,1014,1016,1037,1_2849,4747,1004,1_4246,2278,5439,4524,5002,2930,2193,2930,4341,3208,1005,1055,2171,2848,1_1300,3531,102],[101,4070,4034,7020,1024,3058,1015,1013,2861,1013,6070,1_9274,2772,6205,2_7814,1_6147,1_6147,4343,2047,1_0283,1_0969,1_4389,1012,2338,102]]  ,      device=__lowercase )  # noqa: E231
				_A       	=      torch.tensor([[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],]  ,      device=__lowercase )  # noqa: E231
				_A       	=      torch.tensor([[[0,0,0,0],[423,237,440,251],[427,272,441,287],[419,115,437,129],[961,885,992,912],[256,38,330,58],[256,38,330,58],[336,42,353,57],[360,39,401,56],[360,39,401,56],[411,39,471,59],[479,41,528,59],[533,39,630,60],[67,113,134,131],[141,115,209,132],[68,149,133,166],[141,149,187,164],[195,148,287,165],[195,148,287,165],[195,148,287,165],[295,148,349,165],[441,149,492,166],[497,149,546,164],[64,201,125,218],[1000,1000,1000,1000]],[[0,0,0,0],[662,150,754,166],[665,199,742,211],[519,213,554,228],[519,213,554,228],[134,433,187,454],[130,467,204,480],[130,467,204,480],[130,467,204,480],[130,467,204,480],[130,467,204,480],[314,469,376,482],[504,684,582,706],[941,825,973,900],[941,825,973,900],[941,825,973,900],[941,825,973,900],[610,749,652,765],[130,659,168,672],[176,657,237,672],[238,657,312,672],[443,653,628,672],[443,653,628,672],[716,301,825,317],[1000,1000,1000,1000]]]  ,      device=__lowercase )  # noqa: E231
				_A       	=      torch.tensor([[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]]  ,      device=__lowercase )  # noqa: E231
				# these are sequence labels (i.e. at the token level)
				_A       	=      torch.tensor([[-100,10,10,10,9,1,-100,7,7,-100,7,7,4,2,5,2,8,8,-100,-100,5,0,3,2,-100],[-100,12,12,12,-100,12,10,-100,-100,-100,-100,10,12,9,-100,-100,-100,10,10,10,9,12,-100,10,-100]]  ,      device=__lowercase )  # noqa: E231
				# fmt: on

				return input_ids, attention_mask, bbox, token_type_ids, labels




@require_torch
class snake_case   (	unittest.TestCase):







		@slow
		def 			a_			(       self   :							int		)							->    str:





						'''simple docstring'''







						_A       	=      LayoutLMModel.from_pretrained("microsoft/layoutlm-base-uncased"		).to(a__		)

						_A	,		_A	,		_A	,		_A	,		_A       	=      prepare_layoutlm_batch_inputs()

						# forward pass
						_A       	=      model(input_ids=a__     , bbox=a__     , attention_mask=a__     , token_type_ids=a__		)

						# test the sequence output on [0, :3, :3]
						_A       	=      torch.tensor(
						    [[0.1_7_8_5, -0.1_9_4_7, -0.0_4_2_5], [-0.3_2_5_4, -0.2_8_0_7, 0.2_5_5_3], [-0.5_3_9_1, -0.3_3_2_2, 0.3_3_6_4]]     , device=a__     , )

						self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3]     , a__     , atol=1E-3		)		)

						# test the pooled output on [1, :3]
						_A       	=      torch.tensor([-0.6_5_8_0, -0.0_2_1_4, 0.8_5_5_2]     , device=a__		)

						self.assertTrue(torch.allclose(outputs.pooler_output[1, :3]     , a__     , atol=1E-3		)		)







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





						'''simple docstring'''







						_A       	=      LayoutLMForSequenceClassification.from_pretrained("microsoft/layoutlm-base-uncased"     , num_labels=2		).to(
						    a__		)

						_A	,		_A	,		_A	,		_A	,		_A       	=      prepare_layoutlm_batch_inputs()

						# forward pass
						_A       	=      model(
						    input_ids=a__     , bbox=a__     , attention_mask=a__     , token_type_ids=a__     , labels=torch.tensor([1, 1]     , device=a__		)     , )

						# test whether we get a loss as a scalar
						_A       	=      outputs.loss
						_A       	=      torch.Size([]		)
						self.assertEqual(loss.shape     , a__		)

						# test the shape of the logits
						_A       	=      outputs.logits
						_A       	=      torch.Size((2, 2)		)
						self.assertEqual(logits.shape     , a__		)







		@slow
		def 			a_			(       self   :							List[Any]		)							->    Union[str, Any]:





						'''simple docstring'''







						_A       	=      LayoutLMForTokenClassification.from_pretrained("microsoft/layoutlm-base-uncased"     , num_labels=13		).to(
						    a__		)

						_A	,		_A	,		_A	,		_A	,		_A       	=      prepare_layoutlm_batch_inputs()

						# forward pass
						_A       	=      model(
						    input_ids=a__     , bbox=a__     , attention_mask=a__     , token_type_ids=a__     , labels=a__		)

						# test the loss calculation to be around 2.65
						# expected_loss = torch.tensor(2.65, device=torch_device)

						# The loss is currently somewhat random and can vary between 0.1-0.3 atol.
						# self.assertTrue(torch.allclose(outputs.loss, expected_loss, atol=0.1))

						# test the shape of the logits
						_A       	=      outputs.logits
						_A       	=      torch.Size((2, 25, 13)		)
						self.assertEqual(logits.shape     , a__		)







		@slow
		def 			a_			(       self   :							List[str]		)							->    List[Any]:





						'''simple docstring'''







						_A       	=      LayoutLMForQuestionAnswering.from_pretrained("microsoft/layoutlm-base-uncased"		).to(a__		)

						_A	,		_A	,		_A	,		_A	,		_A       	=      prepare_layoutlm_batch_inputs()

						# forward pass
						_A       	=      model(input_ids=a__     , bbox=a__     , attention_mask=a__     , token_type_ids=a__		)

						# test the shape of the logits
						_A       	=      torch.Size((2, 25)		)
						self.assertEqual(outputs.start_logits.shape     , a__		)
						self.assertEqual(outputs.end_logits.shape     , a__		)



"""simple docstring"""


import colorsys
import io

import cva
import matplotlib as mpl
import matplotlib.colors as mplc
import matplotlib.figure as mplfigure
import numpy as np
import torch
from matplotlib.backends.backend_agg import FigureCanvasAgg

from utils import img_tensorize


a_											=     10_00
class snake_case   :







		def __init__(       self   :							Optional[int]     , a__   :							int     , a__   :							List[str]=1.2     , a__   :							int="g"     , a__   :							List[Any]=0.5     , a__   :							Tuple="-"     , a__   :							Optional[int]="test_out.jpg"     , a__   :							Tuple=True     , a__   :							List[str]=False     , a__   :							Dict=None     , a__   :							Optional[Any]=None     , a__   :							Optional[int]=0.7     , )							->    Union[str, Any]:





						'''simple docstring'''







						if isinstance(a__     , torch.Tensor		):
										_A       	=      img.numpy().astype("np.uint8"		)
						if isinstance(a__     , a__		):
										_A       	=      img_tensorize(a__		)
						assert isinstance(a__     , np.ndarray		)

						_A	,		_A       	=      img.shape[1], img.shape[0]
						_A       	=      mplfigure.Figure(frameon=a__		)
						_A       	=      fig.get_dpi()
						_A       	=      (width * scale + 1E-2) / dpi
						_A       	=      (height * scale + 1E-2) / dpi
						fig.set_size_inches(a__     , a__		)
						_A       	=      fig.add_axes([0.0, 0.0, 1.0, 1.0]		)
						ax.axis("off"		)
						ax.set_xlim(0.0     , a__		)
						ax.set_ylim(a__		)

						_A       	=      saveas
						_A       	=      rgb
						_A       	=      pynb
						_A       	=      img
						_A       	=      edgecolor
						_A       	=      0.5
						_A       	=      linestyle
						_A       	=      int(np.sqrt(min(a__     , a__		)		) * scale // 3		)
						_A       	=      width
						_A       	=      height
						_A       	=      scale
						_A       	=      fig
						_A       	=      ax
						_A       	=      pad
						_A       	=      idaobj
						_A       	=      idaattr
						_A       	=      FigureCanvasAgg(a__		)







		def 			a_			(       self   :							List[Any]     , a__   :							Union[str, Any]     , a__   :							Tuple=None		)							->    Tuple:





						'''simple docstring'''







						if color is None:
										_A       	=      self.edgecolor
						((_A)	,		(_A)	,		(_A)	,		(_A))       	=      box
						_A       	=      xa - xa
						_A       	=      ya - ya
						self.ax.add_patch(
						    mpl.patches.Rectangle(
						        (xa, ya)     , a__     , a__     , fill=a__     , edgecolor=a__     , linewidth=self.font_size // 3     , alpha=self.alpha     , linestyle=self.linestyle     , )		)







		def 			a_			(       self   :							Union[str, Any]     , a__   :							Dict     , a__   :							List[Any]=None     , a__   :							int=None     , a__   :							str=None     , a__   :							Optional[int]=None		)							->    List[str]:





						'''simple docstring'''







						if len(boxes.shape		) > 2:
										_A       	=      boxes[0]
						if len(obj_ids.shape		) > 1:
										_A       	=      obj_ids[0]
						if len(obj_scores.shape		) > 1:
										_A       	=      obj_scores[0]
						if len(attr_ids.shape		) > 1:
										_A       	=      attr_ids[0]
						if len(attr_scores.shape		) > 1:
										_A       	=      attr_scores[0]
						if isinstance(a__     , torch.Tensor		):
										_A       	=      boxes.numpy()
						if isinstance(a__     , a__		):
										_A       	=      np.array(a__		)
						assert isinstance(a__     , np.ndarray		)
						_A       	=      np.prod(boxes[:, 2:] - boxes[:, :2]     , axis=1		)
						_A       	=      np.argsort(-areas		).tolist()
						_A       	=      boxes[sorted_idxs] if boxes is not None else None
						_A       	=      obj_ids[sorted_idxs] if obj_ids is not None else None
						_A       	=      obj_scores[sorted_idxs] if obj_scores is not None else None
						_A       	=      attr_ids[sorted_idxs] if attr_ids is not None else None
						_A       	=      attr_scores[sorted_idxs] if attr_scores is not None else None

						_A       	=      [self._random_color(maximum=1		) for _ in range(len(a__		)		)]
						_A       	=      [assigned_colors[idx] for idx in sorted_idxs]
						if obj_ids is not None:
										_A       	=      self._create_text_labels_attr(a__     , a__     , a__     , a__		)
										for i in range(len(a__		)		):
														_A       	=      assigned_colors[i]
														self.add_box(boxes[i]     , a__		)
														self.draw_labels(labels[i]     , boxes[i]     , a__		)







		def 			a_			(       self   :							List[str]     , a__   :							Any     , a__   :							List[str]     , a__   :							Tuple		)							->    int:





						'''simple docstring'''







						_A	,		_A	,		_A	,		_A       	=      box
						_A       	=      (xa, ya)
						_A       	=      (ya - ya) * (xa - xa)
						_A       	=      _SMALL_OBJ * self.scale
						if instance_area < small or ya - ya < 40 * self.scale:
										if ya >= self.height - 5:
														_A       	=      (xa, ya)
										else:
														_A       	=      (xa, ya)

						_A       	=      (ya - ya) / np.sqrt(self.height * self.width		)
						_A       	=      self._change_color_brightness(a__     , brightness_factor=0.7		)
						_A       	=      np.clip((height_ratio - 0.0_2) / 0.0_8 + 1     , 1.2     , 2		)
						font_size *= 0.7_5 * self.font_size

						self.draw_text(
						    text=a__     , position=a__     , color=a__     , )







		def 			a_			(       self   :							str     , a__   :							Optional[int]     , a__   :							Optional[int]     , a__   :							Any="g"     , a__   :							Optional[int]="left"     , )							->    Dict:





						'''simple docstring'''







						_A       	=      0
						_A       	=      self.font_size
						_A       	=      np.maximum(list(mplc.to_rgb(a__		)		)     , 0.2		)
						_A       	=      max(0.8     , np.max(a__		)		)
						_A       	=      {
						    "facecolor": "black",
						    "alpha": self.alpha,
						    "pad": self.pad,
						    "edgecolor": "none",
						}
						_A	,		_A       	=      position
						self.ax.text(
						    a__     , a__     , a__     , size=font_size * self.scale     , family="sans-serif"     , bbox=a__     , verticalalignment="top"     , horizontalalignment=a__     , color=a__     , zorder=10     , rotation=a__     , )







		def 			a_			(       self   :							List[str]     , a__   :							str=None		)							->    Optional[int]:





						'''simple docstring'''







						if saveas is None:
										_A       	=      self.saveas
						if saveas.lower().endswith(".jpg"		) or saveas.lower().endswith(".png"		):
										cva.imwrite(
										    a__     , self._get_buffer()[:, :, ::-1]     , )
						else:
										self.fig.savefig(a__		)







		def 			a_			(       self   :							Union[str, Any]     , a__   :							Optional[Any]     , a__   :							List[Any]     , a__   :							Tuple     , a__   :							List[str]		)							->    Optional[int]:





						'''simple docstring'''







						_A       	=      [self.idaobj[i] for i in classes]
						_A       	=      [self.idaattr[i] for i in attr_classes]
						_A       	=      [
						    F"""{label} {score:.2f} {attr} {attr_score:.2f}"""
						    for label, score, attr, attr_score in zip(a__     , a__     , a__     , a__		)
						]
						return labels







		def 			a_			(       self   :							Any     , a__   :							Dict     , a__   :							Tuple		)							->    Dict:





						'''simple docstring'''







						_A       	=      [self.idaobj[i] for i in classes]
						if scores is not None:
										if labels is None:
														_A       	=      ["{:.0f}%".format(s * 1_00		) for s in scores]
										else:
														_A       	=      ["{} {:.0f}%".format(a__     , s * 1_00		) for li, s in zip(a__     , a__		)]
						return labels







		def 			a_			(       self   :							List[Any]     , a__   :							Optional[Any]=2_55		)							->    str:





						'''simple docstring'''







						_A       	=      np.random.randint(0     , len(_COLORS		)		)
						_A       	=      _COLORS[idx] * maximum
						if not self.rgb:
										_A       	=      ret[::-1]
						return ret







		def 			a_			(       self   :							int		)							->    Dict:





						'''simple docstring'''







						if not self.pynb:
										_A	,		_A       	=      self.canvas.print_to_buffer()
										if (width, height) != (self.width, self.height):
														_A       	=      cva.resize(self.img     , (width, height)		)
										else:
														_A       	=      self.img
						else:
										_A       	=      io.BytesIO()  # works for cairo backend
										self.canvas.print_rgba(a__		)
										_A	,		_A       	=      self.width, self.height
										_A       	=      buf.getvalue()
										_A       	=      self.img

						_A       	=      np.frombuffer(a__     , dtype="uint8"		)
						_A       	=      buffer.reshape(a__     , a__     , 4		)
						_A	,		_A       	=      np.split(a__     , [3]     , axis=2		)

						try:
										import numexpr as ne  # fuse them with numexpr

										_A       	=      ne.evaluate("img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)"		)
						except ImportError:
										_A       	=      alpha.astype("float32"		) / 2_5_5.0
										_A       	=      img * (1 - alpha) + rgb * alpha

						return visualized_image.astype("uint8"		)







		def 			a_			(       self   :							Optional[int]     , a__   :							str     , a__   :							Union[str, Any]		)							->    str:





						'''simple docstring'''







						assert brightness_factor >= -1.0 and brightness_factor <= 1.0
						_A       	=      mplc.to_rgb(a__		)
						_A       	=      colorsys.rgb_to_hls(*mplc.to_rgb(a__		)		)
						_A       	=      polygon_color[1] + (brightness_factor * polygon_color[1])
						_A       	=      0.0 if modified_lightness < 0.0 else modified_lightness
						_A       	=      1.0 if modified_lightness > 1.0 else modified_lightness
						_A       	=      colorsys.hls_to_rgb(polygon_color[0]     , a__     , polygon_color[2]		)
						return modified_color





a_											=     (
    np.array(
        [
            0.0_00,
            0.4_47,
            0.7_41,
            0.8_50,
            0.3_25,
            0.0_98,
            0.9_29,
            0.6_94,
            0.1_25,
            0.4_94,
            0.1_84,
            0.5_56,
            0.4_66,
            0.6_74,
            0.1_88,
            0.3_01,
            0.7_45,
            0.9_33,
            0.6_35,
            0.0_78,
            0.1_84,
            0.3_00,
            0.3_00,
            0.3_00,
            0.6_00,
            0.6_00,
            0.6_00,
            1.0_00,
            0.0_00,
            0.0_00,
            1.0_00,
            0.5_00,
            0.0_00,
            0.7_49,
            0.7_49,
            0.0_00,
            0.0_00,
            1.0_00,
            0.0_00,
            0.0_00,
            0.0_00,
            1.0_00,
            0.6_67,
            0.0_00,
            1.0_00,
            0.3_33,
            0.3_33,
            0.0_00,
            0.3_33,
            0.6_67,
            0.0_00,
            0.3_33,
            1.0_00,
            0.0_00,
            0.6_67,
            0.3_33,
            0.0_00,
            0.6_67,
            0.6_67,
            0.0_00,
            0.6_67,
            1.0_00,
            0.0_00,
            1.0_00,
            0.3_33,
            0.0_00,
            1.0_00,
            0.6_67,
            0.0_00,
            1.0_00,
            1.0_00,
            0.0_00,
            0.0_00,
            0.3_33,
            0.5_00,
            0.0_00,
            0.6_67,
            0.5_00,
            0.0_00,
            1.0_00,
            0.5_00,
            0.3_33,
            0.0_00,
            0.5_00,
            0.3_33,
            0.3_33,
            0.5_00,
            0.3_33,
            0.6_67,
            0.5_00,
            0.3_33,
            1.0_00,
            0.5_00,
            0.6_67,
            0.0_00,
            0.5_00,
            0.6_67,
            0.3_33,
            0.5_00,
            0.6_67,
            0.6_67,
            0.5_00,
            0.6_67,
            1.0_00,
            0.5_00,
            1.0_00,
            0.0_00,
            0.5_00,
            1.0_00,
            0.3_33,
            0.5_00,
            1.0_00,
            0.6_67,
            0.5_00,
            1.0_00,
            1.0_00,
            0.5_00,
            0.0_00,
            0.3_33,
            1.0_00,
            0.0_00,
            0.6_67,
            1.0_00,
            0.0_00,
            1.0_00,
            1.0_00,
            0.3_33,
            0.0_00,
            1.0_00,
            0.3_33,
            0.3_33,
            1.0_00,
            0.3_33,
            0.6_67,
            1.0_00,
            0.3_33,
            1.0_00,
            1.0_00,
            0.6_67,
            0.0_00,
            1.0_00,
            0.6_67,
            0.3_33,
            1.0_00,
            0.6_67,
            0.6_67,
            1.0_00,
            0.6_67,
            1.0_00,
            1.0_00,
            1.0_00,
            0.0_00,
            1.0_00,
            1.0_00,
            0.3_33,
            1.0_00,
            1.0_00,
            0.6_67,
            1.0_00,
            0.3_33,
            0.0_00,
            0.0_00,
            0.5_00,
            0.0_00,
            0.0_00,
            0.6_67,
            0.0_00,
            0.0_00,
            0.8_33,
            0.0_00,
            0.0_00,
            1.0_00,
            0.0_00,
            0.0_00,
            0.0_00,
            0.1_67,
            0.0_00,
            0.0_00,
            0.3_33,
            0.0_00,
            0.0_00,
            0.5_00,
            0.0_00,
            0.0_00,
            0.6_67,
            0.0_00,
            0.0_00,
            0.8_33,
            0.0_00,
            0.0_00,
            1.0_00,
            0.0_00,
            0.0_00,
            0.0_00,
            0.1_67,
            0.0_00,
            0.0_00,
            0.3_33,
            0.0_00,
            0.0_00,
            0.5_00,
            0.0_00,
            0.0_00,
            0.6_67,
            0.0_00,
            0.0_00,
            0.8_33,
            0.0_00,
            0.0_00,
            1.0_00,
            0.0_00,
            0.0_00,
            0.0_00,
            0.1_43,
            0.1_43,
            0.1_43,
            0.8_57,
            0.8_57,
            0.8_57,
            1.0_00,
            1.0_00,
            1.0_00,
        ]
    )
    .astype(np.floataa)
    .reshape(-1, 3)
)