


'''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 	a__       (							unittest.TestCase						):





							'''simple docstring'''






							def __init__(	self      ,					lowerCamelCase_      ,					lowerCamelCase_=7      ,					lowerCamelCase_=3      ,					lowerCamelCase_=18      ,					lowerCamelCase_=30      ,					lowerCamelCase_=4_00      ,					lowerCamelCase_=True      ,					lowerCamelCase_=None      ,					lowerCamelCase_=True      ,					lowerCamelCase_=None      ,					) ->							int:
														lowerCAmelCase__      =			size if size is not None else {'''shortest_edge''': 20}
														lowerCAmelCase__      =			crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
														lowerCAmelCase__      =			parent
														lowerCAmelCase__      =			batch_size
														lowerCAmelCase__      =			num_channels
														lowerCAmelCase__      =			image_size
														lowerCAmelCase__      =			min_resolution
														lowerCAmelCase__      =			max_resolution
														lowerCAmelCase__      =			do_resize
														lowerCAmelCase__      =			size
														lowerCAmelCase__      =			do_center_crop
														lowerCAmelCase__      =			crop_size







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							int:
														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 	a__       (							__lowerCamelCase       ,       unittest.TestCase						):





							'''simple docstring'''






							lowercase__    :     List[str]					=   MobileNetVaImageProcessor if is_vision_available() else None







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							int:
														lowerCAmelCase__      =			MobileNetVaImageProcessingTester(self     )







							@property
							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							List[str]:
														return self.image_processor_tester.prepare_image_processor_dict()







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							str:
														lowerCAmelCase__      =			self.image_processing_class(**self.image_processor_dict     )
														self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_      ,					'''do_resize'''     )     )
														self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_      ,					'''size'''     )     )
														self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_      ,					'''do_center_crop'''     )     )
														self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_      ,					'''crop_size'''     )     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Union[str, Any]:
														lowerCAmelCase__      =			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}     )

														lowerCAmelCase__      =			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 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Union[str, Any]:
														pass







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							str:
														# Initialize image_processing
														lowerCAmelCase__      =			self.image_processing_class(**self.image_processor_dict     )
														# create random PIL images
														lowerCAmelCase__      =			prepare_image_inputs(self.image_processor_tester      ,					equal_resolution=SCREAMING_SNAKE_CASE_     )
														for image in image_inputs:
																					self.assertIsInstance(SCREAMING_SNAKE_CASE_      ,					Image.Image     )

														# Test not batched input
														lowerCAmelCase__      =			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
														lowerCAmelCase__      =			image_processing(SCREAMING_SNAKE_CASE_      ,					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 						__SCREAMING_SNAKE_CASE							(	self     ) ->							str:
														# Initialize image_processing
														lowerCAmelCase__      =			self.image_processing_class(**self.image_processor_dict     )
														# create random numpy tensors
														lowerCAmelCase__      =			prepare_image_inputs(self.image_processor_tester      ,					equal_resolution=SCREAMING_SNAKE_CASE_      ,					numpify=SCREAMING_SNAKE_CASE_     )
														for image in image_inputs:
																					self.assertIsInstance(SCREAMING_SNAKE_CASE_      ,					np.ndarray     )

														# Test not batched input
														lowerCAmelCase__      =			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
														lowerCAmelCase__      =			image_processing(SCREAMING_SNAKE_CASE_      ,					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 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Any:
														# Initialize image_processing
														lowerCAmelCase__      =			self.image_processing_class(**self.image_processor_dict     )
														# create random PyTorch tensors
														lowerCAmelCase__      =			prepare_image_inputs(self.image_processor_tester      ,					equal_resolution=SCREAMING_SNAKE_CASE_      ,					torchify=SCREAMING_SNAKE_CASE_     )
														for image in image_inputs:
																					self.assertIsInstance(SCREAMING_SNAKE_CASE_      ,					torch.Tensor     )

														# Test not batched input
														lowerCAmelCase__      =			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
														lowerCAmelCase__      =			image_processing(SCREAMING_SNAKE_CASE_      ,					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'''],
														    )      ,					)










'''simple docstring'''






from manim import *




class 	a__       (							a__						):





							'''simple docstring'''






							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							List[str]:
														lowerCAmelCase__      =			Rectangle(height=0.5      ,					width=0.5     )
														lowerCAmelCase__      =			Rectangle(height=0.46      ,					width=0.46     ).set_stroke(width=0     )

														lowerCAmelCase__      =			[mem.copy() for i in range(6     )]
														lowerCAmelCase__      =			[mem.copy() for i in range(6     )]
														lowerCAmelCase__      =			VGroup(*lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0     )
														lowerCAmelCase__      =			VGroup(*lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0     )
														lowerCAmelCase__      =			VGroup(lowerCamelCase_      ,					lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0     )
														lowerCAmelCase__      =			Text('''CPU'''      ,					font_size=24     )
														lowerCAmelCase__      =			Group(lowerCamelCase_      ,					lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0.5      ,					aligned_edge=lowerCamelCase_     )
														cpu.move_to([-2.5, -0.5, 0]     )
														self.add(lowerCamelCase_     )

														lowerCAmelCase__      =			[mem.copy() for i in range(1     )]
														lowerCAmelCase__      =			VGroup(*lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0     )
														lowerCAmelCase__      =			Text('''GPU'''      ,					font_size=24     )
														lowerCAmelCase__      =			Group(lowerCamelCase_      ,					lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0.5      ,					aligned_edge=lowerCamelCase_     )
														gpu.align_to(lowerCamelCase_      ,					lowerCamelCase_     )
														gpu.set_x(gpu.get_x() - 1     )

														self.add(lowerCamelCase_     )

														lowerCAmelCase__      =			[mem.copy() for i in range(6     )]
														lowerCAmelCase__      =			VGroup(*lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0     )

														lowerCAmelCase__      =			Text('''Model'''      ,					font_size=24     )
														lowerCAmelCase__      =			Group(lowerCamelCase_      ,					lowerCamelCase_     ).arrange(lowerCamelCase_      ,					buff=0.5      ,					aligned_edge=lowerCamelCase_     )
														model.move_to([3, -1.0, 0]     )

														self.play(
														    Create(lowerCamelCase_      ,					run_time=1     )      ,					Create(lowerCamelCase_      ,					run_time=1     )      ,					Create(lowerCamelCase_      ,					run_time=1     )      ,					)

														lowerCAmelCase__      =			MarkupText(
														    F"""First, an empty model skeleton is loaded\ninto <span fgcolor='{YELLOW}'>memory</span> without using much RAM."""      ,					font_size=24      ,					)

														lowerCAmelCase__      =			Square(side_length=2.2     )
														key.move_to([-5, 2, 0]     )

														lowerCAmelCase__      =			MarkupText(
														    F"""<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model"""      ,					font_size=18      ,					)

														key_text.move_to([-5, 2.4, 0]     )

														step_a.move_to([2, 2, 0]     )
														self.play(Write(lowerCamelCase_      ,					run_time=2.5     )      ,					Write(lowerCamelCase_     )      ,					Write(lowerCamelCase_     )     )

														self.add(lowerCamelCase_     )

														lowerCAmelCase__      =			[]
														lowerCAmelCase__      =			[]
														lowerCAmelCase__      =			[]
														for i, rect in enumerate(lowerCamelCase_     ):
																					lowerCAmelCase__      =			Rectangle(height=0.46      ,					width=0.46     ).set_stroke(width=0.0     ).set_fill(lowerCamelCase_      ,					opacity=0.7     )
																					cpu_target.move_to(lowerCamelCase_     )
																					cpu_target.generate_target()
																					lowerCAmelCase__      =			0.46 / 4
																					lowerCAmelCase__      =			0.46 / 3

																					if i == 0:
																												cpu_target.target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT     )      ,					buff=0.02      ,					direction=lowerCamelCase_     )
																												cpu_target.target.set_x(cpu_target.target.get_x() + 0.1     )
																					elif i == 3:
																												cpu_target.target.next_to(cpu_targs[0].target      ,					direction=lowerCamelCase_      ,					buff=0.0     )
																					else:
																												cpu_target.target.next_to(cpu_targs[i - 1].target      ,					direction=lowerCamelCase_      ,					buff=0.0     )
																					cpu_targs.append(lowerCamelCase_     )

																					first_animations.append(rect.animate(run_time=0.5     ).set_stroke(lowerCamelCase_     )     )
																					second_animations.append(MoveToTarget(lowerCamelCase_      ,					run_time=1.5     )     )

														self.play(*lowerCamelCase_     )
														self.play(*lowerCamelCase_     )

														self.wait()