
import numpy as np
import torch
import torch.nn as nn
from transformers import CLIPConfig, CLIPVisionModelWithProjection, PreTrainedModel

from ...utils import logging


_lowerCamelCase					   =logging.get_logger(__name__)





class 							A__		(	__lowerCamelCase):
      _UpperCAmelCase				:    int           =			CLIPConfig

      _UpperCAmelCase				:    Tuple           =			["CLIPEncoderLayer"]
      def __init__(      self    ,  __magic_name__      ):
       super().__init__(__magic_name__      )

       lowerCamelCase		:	Tuple							=      CLIPVisionModelWithProjection(config.vision_config      )

       lowerCamelCase		:	Union[str, Any]							=      nn.Linear(config.vision_config.projection_dim    ,  1      )
       lowerCamelCase		:	List[Any]							=      nn.Linear(config.vision_config.projection_dim    ,  1      )






      @torch.no_grad()
      def 						UpperCamelCase__							(      self    ,  __magic_name__    ,  __magic_name__    ,  __magic_name__=0.5    ,  __magic_name__=0.5      ):
       lowerCamelCase		:	str							=      self.vision_model(__magic_name__      )[0]

       lowerCamelCase		:	str							=      self.p_head(__magic_name__      )
       lowerCamelCase		:	Tuple							=      nsfw_detected.flatten()
       lowerCamelCase		:	Any							=      nsfw_detected > p_threshold
       lowerCamelCase		:	str							=      nsfw_detected.tolist()

       if any(__magic_name__      ):
        logger.warning(
            """Potential NSFW content was detected in one or more images. A black image will be returned instead."""
            """ Try again with a different prompt and/or seed."""      )

       for idx, nsfw_detected_ in enumerate(__magic_name__      ):
        if nsfw_detected_:
         lowerCamelCase		:	Dict							=      np.zeros(images[idx].shape      )

       lowerCamelCase		:	Union[str, Any]							=      self.w_head(__magic_name__      )
       lowerCamelCase		:	Dict							=      watermark_detected.flatten()
       lowerCamelCase		:	Dict							=      watermark_detected > w_threshold
       lowerCamelCase		:	Tuple							=      watermark_detected.tolist()

       if any(__magic_name__      ):
        logger.warning(
            """Potential watermarked content was detected in one or more images. A black image will be returned instead."""
            """ Try again with a different prompt and/or seed."""      )

       for idx, watermark_detected_ in enumerate(__magic_name__      ):
        if watermark_detected_:
         lowerCamelCase		:	Any							=      np.zeros(images[idx].shape      )

       return images, nsfw_detected, watermark_detected











from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


UpperCAmelCase_     							= logging.get_logger(__name__)

UpperCAmelCase_     							= {
    'google/mobilenet_v2_1.4_224': 'https://huggingface.co/google/mobilenet_v2_1.4_224/resolve/main/config.json',
    'google/mobilenet_v2_1.0_224': 'https://huggingface.co/google/mobilenet_v2_1.0_224/resolve/main/config.json',
    'google/mobilenet_v2_0.75_160': 'https://huggingface.co/google/mobilenet_v2_0.75_160/resolve/main/config.json',
    'google/mobilenet_v2_0.35_96': 'https://huggingface.co/google/mobilenet_v2_0.35_96/resolve/main/config.json',
    # See all MobileNetV2 models at https://huggingface.co/models?filter=mobilenet_v2
}






class     lowercase__       (	__lowerCamelCase				):

   '''simple docstring'''


   a						:							List[str]   		=		"mobilenet_v2"




   def __init__(    self,		__magic_name__=3,		__magic_name__=224,		__magic_name__=1.0,		__magic_name__=8,		__magic_name__=8,		__magic_name__=6,		__magic_name__=32,		__magic_name__=True,		__magic_name__=True,		__magic_name__="relu6",		__magic_name__=True,		__magic_name__=0.8,		__magic_name__=0.02,		__magic_name__=0.001,		__magic_name__=255,		**__magic_name__,		) ->      List[Any]:






       """simple docstring"""
       super().__init__(**__magic_name__							)

       if depth_multiplier <= 0:
           raise ValueError('''depth_multiplier must be greater than zero.'''							)

       UpperCamelCase__							:				Union[str, Any]          =      num_channels
       UpperCamelCase__							:				int          =      image_size
       UpperCamelCase__							:				int          =      depth_multiplier
       UpperCamelCase__							:				Tuple          =      depth_divisible_by
       UpperCamelCase__							:				List[str]          =      min_depth
       UpperCamelCase__							:				Optional[int]          =      expand_ratio
       UpperCamelCase__							:				Optional[int]          =      output_stride
       UpperCamelCase__							:				Tuple          =      first_layer_is_expansion
       UpperCamelCase__							:				Union[str, Any]          =      finegrained_output
       UpperCamelCase__							:				str          =      hidden_act
       UpperCamelCase__							:				Optional[Any]          =      tf_padding
       UpperCamelCase__							:				Optional[int]          =      classifier_dropout_prob
       UpperCamelCase__							:				int          =      initializer_range
       UpperCamelCase__							:				Union[str, Any]          =      layer_norm_eps
       UpperCamelCase__							:				Tuple          =      semantic_loss_ignore_index






class     lowercase__       (	__lowerCamelCase				):

   '''simple docstring'''


   a						:							Union[str, Any]   		=		version.parse("1.11"				)




   @property
   def       UpperCamelCase__  (    self							) ->      Mapping[str, Mapping[int, str]]:






       """simple docstring"""
       return OrderedDict([('''pixel_values''', {0: '''batch'''})]							)




   @property
   def       UpperCamelCase__  (    self							) ->      Mapping[str, Mapping[int, str]]:






       """simple docstring"""
       if self.task == "image-classification":
           return OrderedDict([('''logits''', {0: '''batch'''})]							)
       else:
           return OrderedDict([('''last_hidden_state''', {0: '''batch'''}), ('''pooler_output''', {0: '''batch'''})]							)




   @property
   def       UpperCamelCase__  (    self							) ->      float:






       """simple docstring"""
       return 1E-4

