
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 ConvNextImageProcessor







class   __lowercase						(unittest.TestCase     ):





							"""simple docstring"""







							def __init__(			self ,	lowerCAmelCase__ ,	lowerCAmelCase__=7 ,	lowerCAmelCase__=3 ,	lowerCAmelCase__=1_8 ,	lowerCAmelCase__=3_0 ,	lowerCAmelCase__=4_0_0 ,	lowerCAmelCase__=True ,	lowerCAmelCase__=None ,	lowerCAmelCase__=0.875 ,	lowerCAmelCase__=True ,	lowerCAmelCase__=[0.5, 0.5, 0.5] ,	lowerCAmelCase__=[0.5, 0.5, 0.5] ,	):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:    int 		=				size if size is not None else {'shortest_edge': 2_0}
										SCREAMING_SNAKE_CASE_		:    Union[str, Any] 		=				parent
										SCREAMING_SNAKE_CASE_		:    List[Any] 		=				batch_size
										SCREAMING_SNAKE_CASE_		:    Optional[int] 		=				num_channels
										SCREAMING_SNAKE_CASE_		:    Optional[Any] 		=				image_size
										SCREAMING_SNAKE_CASE_		:    Optional[int] 		=				min_resolution
										SCREAMING_SNAKE_CASE_		:    List[Any] 		=				max_resolution
										SCREAMING_SNAKE_CASE_		:    Any 		=				do_resize
										SCREAMING_SNAKE_CASE_		:    str 		=				size
										SCREAMING_SNAKE_CASE_		:    Dict 		=				crop_pct
										SCREAMING_SNAKE_CASE_		:    List[Any] 		=				do_normalize
										SCREAMING_SNAKE_CASE_		:    str 		=				image_mean
										SCREAMING_SNAKE_CASE_		:    Any 		=				image_std






							def 				UpperCamelCase__    (			self					):





										"""simple docstring"""




										return {
										    "image_mean": self.image_mean,
										    "image_std": self.image_std,
										    "do_normalize": self.do_normalize,
										    "do_resize": self.do_resize,
										    "size": self.size,
										    "crop_pct": self.crop_pct,
										}







@require_torch
@require_vision
class   __lowercase						(__SCREAMING_SNAKE_CASE  ,					unittest.TestCase     ):





							"""simple docstring"""







							_UpperCAmelCase						     =	ConvNextImageProcessor if is_vision_available() else None






							def 				UpperCamelCase__    (			self					):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:    str 		=				ConvNextImageProcessingTester(self					)






							@property
							def 				UpperCamelCase__    (			self					):





										"""simple docstring"""




										return self.image_processor_tester.prepare_image_processor_dict()






							def 				UpperCamelCase__    (			self					):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:    int 		=				self.image_processing_class(**self.image_processor_dict					)
										self.assertTrue(hasattr(lowerCAmelCase__ ,	'do_resize'					)					)
										self.assertTrue(hasattr(lowerCAmelCase__ ,	'size'					)					)
										self.assertTrue(hasattr(lowerCAmelCase__ ,	'crop_pct'					)					)
										self.assertTrue(hasattr(lowerCAmelCase__ ,	'do_normalize'					)					)
										self.assertTrue(hasattr(lowerCAmelCase__ ,	'image_mean'					)					)
										self.assertTrue(hasattr(lowerCAmelCase__ ,	'image_std'					)					)






							def 				UpperCamelCase__    (			self					):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:    Any 		=				self.image_processing_class.from_dict(self.image_processor_dict					)
										self.assertEqual(image_processor.size ,	{'shortest_edge': 2_0}					)

										SCREAMING_SNAKE_CASE_		:    Optional[int] 		=				self.image_processing_class.from_dict(self.image_processor_dict ,	size=4_2					)
										self.assertEqual(image_processor.size ,	{'shortest_edge': 4_2}					)






							def 				UpperCamelCase__    (			self					):





										"""simple docstring"""




										pass






							def 				UpperCamelCase__    (			self					):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:    int 		=				self.image_processing_class(**self.image_processor_dict					)
										# create random PIL images
										SCREAMING_SNAKE_CASE_		:    str 		=				prepare_image_inputs(self.image_processor_tester ,	equal_resolution=lowerCAmelCase__					)
										for image in image_inputs:
													self.assertIsInstance(lowerCAmelCase__ ,	Image.Image					)

										# Test not batched input
										SCREAMING_SNAKE_CASE_		:    int 		=				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.size['shortest_edge'],
										        self.image_processor_tester.size['shortest_edge'],
										    ) ,	)

										# Test batched
										SCREAMING_SNAKE_CASE_		:    int 		=				image_processing(lowerCAmelCase__ ,	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.size['shortest_edge'],
										        self.image_processor_tester.size['shortest_edge'],
										    ) ,	)






							def 				UpperCamelCase__    (			self					):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:    List[Any] 		=				self.image_processing_class(**self.image_processor_dict					)
										# create random numpy tensors
										SCREAMING_SNAKE_CASE_		:    Optional[Any] 		=				prepare_image_inputs(self.image_processor_tester ,	equal_resolution=lowerCAmelCase__ ,	numpify=lowerCAmelCase__					)
										for image in image_inputs:
													self.assertIsInstance(lowerCAmelCase__ ,	np.ndarray					)

										# Test not batched input
										SCREAMING_SNAKE_CASE_		:    List[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.size['shortest_edge'],
										        self.image_processor_tester.size['shortest_edge'],
										    ) ,	)

										# Test batched
										SCREAMING_SNAKE_CASE_		:    Union[str, Any] 		=				image_processing(lowerCAmelCase__ ,	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.size['shortest_edge'],
										        self.image_processor_tester.size['shortest_edge'],
										    ) ,	)






							def 				UpperCamelCase__    (			self					):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:    Optional[int] 		=				self.image_processing_class(**self.image_processor_dict					)
										# create random PyTorch tensors
										SCREAMING_SNAKE_CASE_		:    Tuple 		=				prepare_image_inputs(self.image_processor_tester ,	equal_resolution=lowerCAmelCase__ ,	torchify=lowerCAmelCase__					)
										for image in image_inputs:
													self.assertIsInstance(lowerCAmelCase__ ,	torch.Tensor					)

										# Test not batched input
										SCREAMING_SNAKE_CASE_		:    List[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.size['shortest_edge'],
										        self.image_processor_tester.size['shortest_edge'],
										    ) ,	)

										# Test batched
										SCREAMING_SNAKE_CASE_		:    int 		=				image_processing(lowerCAmelCase__ ,	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.size['shortest_edge'],
										        self.image_processor_tester.size['shortest_edge'],
										    ) ,	)









import unittest
from dataclasses import dataclass
from typing import List, Union

import numpy as np
import PIL.Image

from diffusers.utils.outputs import BaseOutput







@dataclass
class   __lowercase						(__SCREAMING_SNAKE_CASE     ):





							"""simple docstring"""







							_UpperCAmelCase						     =	42







class   __lowercase						(unittest.TestCase     ):





							"""simple docstring"""







							def 				UpperCamelCase__    (			self					):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:    Union[str, Any] 		=				CustomOutput(images=np.random.rand(1 ,	3 ,	4 ,	4					)					)

										# check every way of getting the attribute
										assert isinstance(outputs.images ,	np.ndarray					)
										assert outputs.images.shape == (1, 3, 4, 4)
										assert isinstance(outputs['images'] ,	np.ndarray					)
										assert outputs["images"].shape == (1, 3, 4, 4)
										assert isinstance(outputs[0] ,	np.ndarray					)
										assert outputs[0].shape == (1, 3, 4, 4)

										# test with a non-tensor attribute
										SCREAMING_SNAKE_CASE_		:    Tuple 		=				CustomOutput(images=[PIL.Image.new('RGB' ,	(4, 4)					)]					)

										# check every way of getting the attribute
										assert isinstance(outputs.images ,	lowerCAmelCase__					)
										assert isinstance(outputs.images[0] ,	PIL.Image.Image					)
										assert isinstance(outputs['images'] ,	lowerCAmelCase__					)
										assert isinstance(outputs['images'][0] ,	PIL.Image.Image					)
										assert isinstance(outputs[0] ,	lowerCAmelCase__					)
										assert isinstance(outputs[0][0] ,	PIL.Image.Image					)






							def 				UpperCamelCase__    (			self					):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:    Union[str, Any] 		=				CustomOutput({'images': np.random.rand(1 ,	3 ,	4 ,	4					)}					)

										# check every way of getting the attribute
										assert isinstance(outputs.images ,	np.ndarray					)
										assert outputs.images.shape == (1, 3, 4, 4)
										assert isinstance(outputs['images'] ,	np.ndarray					)
										assert outputs["images"].shape == (1, 3, 4, 4)
										assert isinstance(outputs[0] ,	np.ndarray					)
										assert outputs[0].shape == (1, 3, 4, 4)

										# test with a non-tensor attribute
										SCREAMING_SNAKE_CASE_		:    Any 		=				CustomOutput({'images': [PIL.Image.new('RGB' ,	(4, 4)					)]}					)

										# check every way of getting the attribute
										assert isinstance(outputs.images ,	lowerCAmelCase__					)
										assert isinstance(outputs.images[0] ,	PIL.Image.Image					)
										assert isinstance(outputs['images'] ,	lowerCAmelCase__					)
										assert isinstance(outputs['images'][0] ,	PIL.Image.Image					)
										assert isinstance(outputs[0] ,	lowerCAmelCase__					)
										assert isinstance(outputs[0][0] ,	PIL.Image.Image					)





