





"""simple docstring"""
import numpy as np
from cva import COLOR_BGR2GRAY, CV_8UC3, cvtColor, filteraD, imread, imshow, waitKey



def 					__lowerCamelCase       (							a_					:		int			,       a_					:		int			,       a_					:		int			,       a_					:		int			,       a_					:		int			,       a_					:		int							)      ->				np.ndarray:





      if (ksize % 2) == 0:
            __SCREAMING_SNAKE_CASE       :int		    =  ksize + 1
      __SCREAMING_SNAKE_CASE       :Optional[int]		    =  np.zeros((ksize, ksize)			,       dtype=np.floataa							)

      # each value
      for y in range(_snake_case							):
            for x in range(_snake_case							):
                  # distance from center
                  __SCREAMING_SNAKE_CASE       :List[Any]		    =  x - ksize // 2
                  __SCREAMING_SNAKE_CASE       :Tuple		    =  y - ksize // 2

                  # degree to radiant
                  __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  theta / 1_80 * np.pi
                  __SCREAMING_SNAKE_CASE       :Dict		    =  np.cos(_theta							)
                  __SCREAMING_SNAKE_CASE       :Any		    =  np.sin(_theta							)

                  # get kernel x
                  __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  cos_theta * px + sin_theta * py

                  # get kernel y
                  __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  -sin_theta * px + cos_theta * py

                  # fill kernel
                  __SCREAMING_SNAKE_CASE       :int		    =  np.exp(
                      -(_x**2 + gamma**2 * _y**2) / (2 * sigma**2)							) * np.cos(2 * np.pi * _x / lambd + psi							)

      return gabor


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  # read original image
  lowerCamelCase_       =		imread("../image_data/lena.jpg")
  # turn image in gray scale value
  lowerCamelCase_       =		cvtColor(img, COLOR_BGR2GRAY)

  # Apply multiple Kernel to detect edges
  lowerCamelCase_       =		np.zeros(gray.shape[:2])
  for theta in [0, 3_0, 6_0, 9_0, 1_2_0, 1_5_0]:
    lowerCamelCase_       =		gabor_filter_kernel(1_0, 8, theta, 1_0, 0, 0)
    out += filteraD(gray, CV_8UC3, kernel_aa)
  lowerCamelCase_       =		out / out.max() * 2_5_5
  lowerCamelCase_       =		out.astype(np.uinta)

  imshow("Original", gray)
  imshow("Gabor filter with 20x20 mask and 6 directions", out)

  waitKey(0)










"""simple docstring"""
import unittest

from datasets import load_dataset

from transformers.pipelines import pipeline
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_torch, slow






@is_pipeline_test
@require_torch
class  _SCREAMING_SNAKE_CASE(       unittest.TestCase  ):




       @require_torch
       def    _UpperCamelCase					(						self							)      ->				str:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Dict		    =  pipeline(
                 task='''zero-shot-audio-classification'''		,model='''hf-internal-testing/tiny-clap-htsat-unfused'''							)
             __SCREAMING_SNAKE_CASE       :Any		    =  load_dataset('''ashraq/esc50'''							)
             __SCREAMING_SNAKE_CASE       :int		    =  dataset['''train''']['''audio'''][-1]['''array''']
             __SCREAMING_SNAKE_CASE       :Dict		    =  audio_classifier(SCREAMING_SNAKE_CASE__		,candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']							)
             self.assertEqual(
                 nested_simplify(SCREAMING_SNAKE_CASE__							)		,[{'''score''': 0.5_0_1, '''label''': '''Sound of a dog'''}, {'''score''': 0.4_9_9, '''label''': '''Sound of vaccum cleaner'''}]		,)




       @unittest.skip('''No models are available in TF'''							)
       def    _UpperCamelCase					(						self							)      ->				Optional[int]:





             """simple docstring"""






             pass




       @slow
       @require_torch
       def    _UpperCamelCase					(						self							)      ->				Tuple:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[int]		    =  pipeline(
                 task='''zero-shot-audio-classification'''		,model='''laion/clap-htsat-unfused'''		,)
             # This is an audio of a dog
             __SCREAMING_SNAKE_CASE       :List[Any]		    =  load_dataset('''ashraq/esc50'''							)
             __SCREAMING_SNAKE_CASE       :Tuple		    =  dataset['''train''']['''audio'''][-1]['''array''']
             __SCREAMING_SNAKE_CASE       :str		    =  audio_classifier(SCREAMING_SNAKE_CASE__		,candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']							)

             self.assertEqual(
                 nested_simplify(SCREAMING_SNAKE_CASE__							)		,[
                     {'''score''': 0.9_9_9, '''label''': '''Sound of a dog'''},
                     {'''score''': 0.0_0_1, '''label''': '''Sound of vaccum cleaner'''},
                 ]		,)

             __SCREAMING_SNAKE_CASE       :Dict		    =  audio_classifier([audio] * 5		,candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']							)
             self.assertEqual(
                 nested_simplify(SCREAMING_SNAKE_CASE__							)		,[
                     [
                         {'''score''': 0.9_9_9, '''label''': '''Sound of a dog'''},
                         {'''score''': 0.0_0_1, '''label''': '''Sound of vaccum cleaner'''},
                     ],
                 ]
                 * 5		,)
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  audio_classifier(
                 [audio] * 5		,candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']		,batch_size=5							)
             self.assertEqual(
                 nested_simplify(SCREAMING_SNAKE_CASE__							)		,[
                     [
                         {'''score''': 0.9_9_9, '''label''': '''Sound of a dog'''},
                         {'''score''': 0.0_0_1, '''label''': '''Sound of vaccum cleaner'''},
                     ],
                 ]
                 * 5		,)




       @unittest.skip('''No models are available in TF'''							)
       def    _UpperCamelCase					(						self							)      ->				List[str]:





             """simple docstring"""






             pass