






from ...configuration_utils import PretrainedConfig
from ...utils import logging


A										=      logging.get_logger(__name__)

A										=      {
    'MCG-NJU/videomae-base': 'https://huggingface.co/MCG-NJU/videomae-base/resolve/main/config.json',
}


class 				__a				(	__A    ):





		'''simple docstring'''



		UpperCAmelCase__   :					Dict					     =    """videomae"""


		def __init__(    self			,     UpperCamelCase__=224			,     UpperCamelCase__=16			,     UpperCamelCase__=3			,     UpperCamelCase__=16			,     UpperCamelCase__=2			,     UpperCamelCase__=768			,     UpperCamelCase__=12			,     UpperCamelCase__=12			,     UpperCamelCase__=3072			,     UpperCamelCase__="gelu"			,     UpperCamelCase__=0.0			,     UpperCamelCase__=0.0			,     UpperCamelCase__=0.02			,     UpperCamelCase__=1E-12			,     UpperCamelCase__=True			,     UpperCamelCase__=True			,     UpperCamelCase__=6			,     UpperCamelCase__=384			,     UpperCamelCase__=4			,     UpperCamelCase__=1536			,     UpperCamelCase__=True			,     **UpperCamelCase__			,     ):
						super().__init__(**UpperCamelCase__							)

						SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= image_size
						SCREAMING_SNAKE_CASE_ :						Dict    				= patch_size
						SCREAMING_SNAKE_CASE_ :						Any    				= num_channels
						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= num_frames
						SCREAMING_SNAKE_CASE_ :						Dict    				= tubelet_size

						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= hidden_size
						SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= num_hidden_layers
						SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= num_attention_heads
						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= intermediate_size
						SCREAMING_SNAKE_CASE_ :						Tuple    				= hidden_act
						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= hidden_dropout_prob
						SCREAMING_SNAKE_CASE_ :						int    				= attention_probs_dropout_prob
						SCREAMING_SNAKE_CASE_ :						Tuple    				= initializer_range
						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= layer_norm_eps
						SCREAMING_SNAKE_CASE_ :						Any    				= qkv_bias
						SCREAMING_SNAKE_CASE_ :						List[str]    				= use_mean_pooling

						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= decoder_num_attention_heads
						SCREAMING_SNAKE_CASE_ :						int    				= decoder_hidden_size
						SCREAMING_SNAKE_CASE_ :						Any    				= decoder_num_hidden_layers
						SCREAMING_SNAKE_CASE_ :						Any    				= decoder_intermediate_size
						SCREAMING_SNAKE_CASE_ :						Dict    				= norm_pix_loss







from typing import SupportsIndex

import numpy as np
from scipy.ndimage import convolve



def        _lowerCamelCase(      lowerCAmelCase__					:		np.ndarray     ,     lowerCAmelCase__					:		np.ndarray     ,     lowerCAmelCase__					:		np.ndarray   ):





				'''simple docstring'''







				SCREAMING_SNAKE_CASE_ :						List[Any]    				= np.stack((horizontal_flow, vertical_flow)     ,     2   )

				# Create a grid of all pixel coordinates and subtract the flow to get the
				# target pixels coordinates
				SCREAMING_SNAKE_CASE_ :						List[Any]    				= np.stack(
				    np.meshgrid(np.arange(0     ,     image.shape[1]   )     ,     np.arange(0     ,     image.shape[0]   )   )     ,     2   )
				SCREAMING_SNAKE_CASE_ :						List[str]    				= np.round(grid - flow   ).astype(np.intaa   )

				# Find the locations outside of the original image
				SCREAMING_SNAKE_CASE_ :						str    				= (grid < 0) | (grid >= np.array([image.shape[1], image.shape[0]]   ))
				SCREAMING_SNAKE_CASE_ :						Dict    				= 0

				SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= image[grid[:, :, 1], grid[:, :, 0]]

				# Set pixels at invalid locations to 0
				SCREAMING_SNAKE_CASE_ :						Optional[int]    				= 0

				return warped



def        _lowerCamelCase(      lowerCAmelCase__					:		np.ndarray     ,     lowerCAmelCase__					:		np.ndarray     ,     lowerCAmelCase__					:		SupportsIndex     ,     lowerCAmelCase__					:		float | None = None     ,     ):





				'''simple docstring'''







				if alpha is None:
								SCREAMING_SNAKE_CASE_ :						Any    				= 0.1

				# Initialize flow
				SCREAMING_SNAKE_CASE_ :						List[Any]    				= np.zeros_like(lowerCAmelCase__   )
				SCREAMING_SNAKE_CASE_ :						Any    				= np.zeros_like(lowerCAmelCase__   )

				# Prepare kernels for the calculation of the derivatives and the average velocity
				SCREAMING_SNAKE_CASE_ :						Optional[int]    				= np.array([[-1, 1], [-1, 1]]   ) * 0.25
				SCREAMING_SNAKE_CASE_ :						Tuple    				= np.array([[-1, -1], [1, 1]]   ) * 0.25
				SCREAMING_SNAKE_CASE_ :						Optional[int]    				= np.array([[1, 1], [1, 1]]   ) * 0.25
				SCREAMING_SNAKE_CASE_ :						Tuple    				= np.array(
				    [[1 / 12, 1 / 6, 1 / 12], [1 / 6, 0, 1 / 6], [1 / 12, 1 / 6, 1 / 12]]   )

				# Iteratively refine the flow
				for _ in range(lowerCAmelCase__   ):
								SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= warp(lowerCAmelCase__     ,     lowerCAmelCase__     ,     lowerCAmelCase__   )
								SCREAMING_SNAKE_CASE_ :						Any    				= convolve(lowerCAmelCase__     ,     lowerCAmelCase__   ) + convolve(lowerCAmelCase__     ,     lowerCAmelCase__   )
								SCREAMING_SNAKE_CASE_ :						Optional[int]    				= convolve(lowerCAmelCase__     ,     lowerCAmelCase__   ) + convolve(lowerCAmelCase__     ,     lowerCAmelCase__   )
								SCREAMING_SNAKE_CASE_ :						Optional[int]    				= convolve(lowerCAmelCase__     ,     lowerCAmelCase__   ) + convolve(lowerCAmelCase__     ,     -kernel_t   )

								SCREAMING_SNAKE_CASE_ :						List[str]    				= convolve(lowerCAmelCase__     ,     lowerCAmelCase__   )
								SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= convolve(lowerCAmelCase__     ,     lowerCAmelCase__   )

								# This updates the flow as proposed in the paper (Step 12)
								SCREAMING_SNAKE_CASE_ :						Tuple    				= (
								    derivative_x * avg_horizontal_velocity
								    + derivative_y * avg_vertical_velocity
								    + derivative_t
								)
								SCREAMING_SNAKE_CASE_ :						Optional[int]    				= update / (alpha**2 + derivative_x**2 + derivative_y**2)

								SCREAMING_SNAKE_CASE_ :						List[str]    				= avg_horizontal_velocity - derivative_x * update
								SCREAMING_SNAKE_CASE_ :						Optional[int]    				= avg_vertical_velocity - derivative_y * update

				return horizontal_flow, vertical_flow


if __name__ == "__main__":
				import doctest

				doctest.testmod()