


"""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


if is_torch_available():
		import torch

if is_vision_available():
		from PIL import Image

		from transformers import TvltImageProcessor
def     UpperCAmelCase    (					_lowercase   :      Dict ,      _lowercase   :      Optional[Any]=1_0 ,      _lowercase   :      List[Any]=1_0 ,      _lowercase   :      Any=False ,      _lowercase   :      str=False  )	->   str:


	"""simple docstring"""




	lowerCAmelCase_			       = []
	for i in range(image_processor_tester.num_frames  ):
		video.append(np.random.randint(2_5_5 ,      size=(image_processor_tester.num_channels, width, height) ,      dtype=np.uinta  )  )

	if not numpify and not torchify:
		# PIL expects the channel dimension as last dimension
		lowerCAmelCase_			       = [Image.fromarray(np.moveaxis(_lowercase ,      0 ,      -1  )  ) for frame in video]

	if torchify:
		lowerCAmelCase_			       = [torch.from_numpy(_lowercase  ) for frame in video]

	return video
def     UpperCAmelCase    (					_lowercase   :      Tuple ,      _lowercase   :      Any=False ,      _lowercase   :      str=False ,      _lowercase   :      Optional[Any]=False  )	->   str:


	"""simple docstring"""




	assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

	lowerCAmelCase_			       = []
	for i in range(image_processor_tester.batch_size  ):
		if equal_resolution:
			lowerCAmelCase_			       = lowerCAmelCase_			       = image_processor_tester.max_resolution
		else:
			lowerCAmelCase_       ,  lowerCAmelCase_			       = np.random.choice(
			    np.arange(image_processor_tester.min_resolution ,      image_processor_tester.max_resolution  ) ,      2  )
			lowerCAmelCase_			       = prepare_video(
			    image_processor_tester=_lowercase ,      width=_lowercase ,      height=_lowercase ,      numpify=_lowercase ,      torchify=_lowercase ,      )
		video_inputs.append(_lowercase  )

	return video_inputs







class       __a	(   unittest.TestCase       ):







				def __init__(   self			,  UpperCAmelCase			,  UpperCAmelCase=7			,  UpperCAmelCase=3			,  UpperCAmelCase=4			,  UpperCAmelCase=18			,  UpperCAmelCase=30			,  UpperCAmelCase=400			,  UpperCAmelCase=True			,  UpperCAmelCase=None			,  UpperCAmelCase=True			,  UpperCAmelCase=[0.5, 0.5, 0.5]			,  UpperCAmelCase=[0.5, 0.5, 0.5]			,  UpperCAmelCase=True			,  UpperCAmelCase=None			,  ):

					'''simple docstring'''






					lowerCAmelCase_			       = size if size is not None else {'''shortest_edge''': 18}
					lowerCAmelCase_			       = crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

					lowerCAmelCase_			       = parent
					lowerCAmelCase_			       = batch_size
					lowerCAmelCase_			       = num_channels
					lowerCAmelCase_			       = num_frames
					lowerCAmelCase_			       = image_size
					lowerCAmelCase_			       = min_resolution
					lowerCAmelCase_			       = max_resolution
					lowerCAmelCase_			       = do_resize
					lowerCAmelCase_			       = size
					lowerCAmelCase_			       = do_normalize
					lowerCAmelCase_			       = image_mean
					lowerCAmelCase_			       = image_std
					lowerCAmelCase_			       = do_center_crop
					lowerCAmelCase_			       = crop_size







				def     lowerCamelCase_    (   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,
					    "do_center_crop": self.do_center_crop,
					    "crop_size": self.crop_size,
					}







@require_torch
@require_vision
class       __a	(   __snake_case				, unittest.TestCase       ):
				lowerCamelCase    :					Tuple 					=TvltImageProcessor if is_vision_available() else None







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					lowerCAmelCase_			       = TvltImageProcessorTester(self      )







				@property
				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					return self.image_processor_tester.prepare_image_processor_dict()







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					lowerCAmelCase_			       = self.image_processing_class(**self.image_processor_dict      )
					self.assertTrue(hasattr(UpperCAmelCase			,  '''image_mean'''      )      )
					self.assertTrue(hasattr(UpperCAmelCase			,  '''image_std'''      )      )
					self.assertTrue(hasattr(UpperCAmelCase			,  '''do_normalize'''      )      )
					self.assertTrue(hasattr(UpperCAmelCase			,  '''do_resize'''      )      )
					self.assertTrue(hasattr(UpperCAmelCase			,  '''do_center_crop'''      )      )
					self.assertTrue(hasattr(UpperCAmelCase			,  '''size'''      )      )







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					lowerCAmelCase_			       = self.image_processing_class(**self.image_processor_dict      )
					# create random PIL videos
					lowerCAmelCase_			       = prepare_video_inputs(self.image_processor_tester			,  equal_resolution=UpperCAmelCase      )
					for video in video_inputs:
						self.assertIsInstance(UpperCAmelCase			,  UpperCAmelCase      )
						self.assertIsInstance(video[0]			,  Image.Image      )

					# Test not batched input
					lowerCAmelCase_			       = image_processor(video_inputs[0]			,  return_tensors='''pt'''      ).pixel_values
					self.assertEqual(
					    encoded_videos.shape			,  (
					        1,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['''height'''],
					        self.image_processor_tester.crop_size['''width'''],
					    )			,  )

					# Test batched
					lowerCAmelCase_			       = image_processor(UpperCAmelCase			,  return_tensors='''pt'''      ).pixel_values
					self.assertEqual(
					    encoded_videos.shape			,  (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['''height'''],
					        self.image_processor_tester.crop_size['''width'''],
					    )			,  )







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					lowerCAmelCase_			       = self.image_processing_class(**self.image_processor_dict      )
					# create random numpy tensors
					lowerCAmelCase_			       = prepare_video_inputs(self.image_processor_tester			,  equal_resolution=UpperCAmelCase			,  numpify=UpperCAmelCase      )
					for video in video_inputs:
						self.assertIsInstance(UpperCAmelCase			,  UpperCAmelCase      )
						self.assertIsInstance(video[0]			,  np.ndarray      )

					# Test not batched input
					lowerCAmelCase_			       = image_processor(video_inputs[0]			,  return_tensors='''pt'''      ).pixel_values
					self.assertEqual(
					    encoded_videos.shape			,  (
					        1,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['''height'''],
					        self.image_processor_tester.crop_size['''width'''],
					    )			,  )

					# Test batched
					lowerCAmelCase_			       = image_processor(UpperCAmelCase			,  return_tensors='''pt'''      ).pixel_values
					self.assertEqual(
					    encoded_videos.shape			,  (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['''height'''],
					        self.image_processor_tester.crop_size['''width'''],
					    )			,  )







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					lowerCAmelCase_			       = self.image_processing_class(**self.image_processor_dict      )
					# create random PyTorch tensors
					lowerCAmelCase_			       = prepare_video_inputs(self.image_processor_tester			,  equal_resolution=UpperCAmelCase			,  torchify=UpperCAmelCase      )
					for video in video_inputs:
						self.assertIsInstance(UpperCAmelCase			,  UpperCAmelCase      )
						self.assertIsInstance(video[0]			,  torch.Tensor      )

					# Test not batched input
					lowerCAmelCase_			       = image_processor(video_inputs[0]			,  return_tensors='''pt'''      ).pixel_values
					self.assertEqual(
					    encoded_videos.shape			,  (
					        1,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['''height'''],
					        self.image_processor_tester.crop_size['''width'''],
					    )			,  )

					# Test batched
					lowerCAmelCase_			       = image_processor(UpperCAmelCase			,  return_tensors='''pt'''      ).pixel_values
					self.assertEqual(
					    encoded_videos.shape			,  (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['''height'''],
					        self.image_processor_tester.crop_size['''width'''],
					    )			,  )



"""simple docstring"""



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowercase_							 =       {
    'configuration_prophetnet': ['PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP', 'ProphetNetConfig'],
    'tokenization_prophetnet': ['ProphetNetTokenizer'],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase_							 =       [
		    'PROPHETNET_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'ProphetNetDecoder',
		    'ProphetNetEncoder',
		    'ProphetNetForCausalLM',
		    'ProphetNetForConditionalGeneration',
		    'ProphetNetModel',
		    'ProphetNetPreTrainedModel',
		]


if TYPE_CHECKING:
		from .configuration_prophetnet import PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP, ProphetNetConfig
		from .tokenization_prophetnet import ProphetNetTokenizer

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_prophetnet import (
				    PROPHETNET_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ProphetNetDecoder,
				    ProphetNetEncoder,
				    ProphetNetForCausalLM,
				    ProphetNetForConditionalGeneration,
				    ProphetNetModel,
				    ProphetNetPreTrainedModel,
				)

else:
		import sys

		lowercase_							 =       _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)