

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

from ...utils import logging


a__												=						logging.get_logger(__name__)

class 							UpperCAmelCase_						(     __lowercase  ):
							"""simple docstring"""







							UpperCAmelCase__			:		List[Any]             =       CLIPConfig

							UpperCAmelCase__			:		List[Any]             =       ["CLIPEncoderLayer"]


							def __init__(     self			,				_a			)       ->       List[Any]:
												super().__init__(_a			)

												_a      :       List[str]   =						CLIPVisionModelWithProjection(config.vision_config			)

												_a      :       Any   =						nn.Linear(config.vision_config.projection_dim			,				1			)
												_a      :       Any   =						nn.Linear(config.vision_config.projection_dim			,				1			)




							@torch.no_grad()
							def 							__lowercase							(     self			,				_a			,				_a			,				_a=0.5			,				_a=0.5			)       ->       Any:
												_a      :       Dict   =						self.vision_model(_a			)[0]

												_a      :       Union[str, Any]   =						self.p_head(_a			)
												_a      :       str   =						nsfw_detected.flatten()
												_a      :       Optional[int]   =						nsfw_detected > p_threshold
												_a      :       Dict   =						nsfw_detected.tolist()

												if any(_a			):
																	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(_a			):
																	if nsfw_detected_:
																						_a      :       Union[str, Any]   =						np.zeros(images[idx].shape			)

												_a      :       str   =						self.w_head(_a			)
												_a      :       Dict   =						watermark_detected.flatten()
												_a      :       Optional[Any]   =						watermark_detected > w_threshold
												_a      :       str   =						watermark_detected.tolist()

												if any(_a			):
																	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(_a			):
																	if watermark_detected_:
																						_a      :       Dict   =						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


a__												=						logging.get_logger(__name__)

a__												=						{
    '''google/mobilenet_v1_1.0_224''': '''https://huggingface.co/google/mobilenet_v1_1.0_224/resolve/main/config.json''',
    '''google/mobilenet_v1_0.75_192''': '''https://huggingface.co/google/mobilenet_v1_0.75_192/resolve/main/config.json''',
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
}

class 							UpperCAmelCase_						(     __lowercase  ):
							"""simple docstring"""







							UpperCAmelCase__			:		int             =       "mobilenet_v1"


							def __init__(     self			,				_a=3			,				_a=2_2_4			,				_a=1.0			,				_a=8			,				_a="relu6"			,				_a=True			,				_a=0.999			,				_a=0.02			,				_a=0.001			,				**_a			,				)       ->       List[Any]:
												super().__init__(**_a			)

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

												_a      :       Tuple   =						num_channels
												_a      :       str   =						image_size
												_a      :       Tuple   =						depth_multiplier
												_a      :       Any   =						min_depth
												_a      :       int   =						hidden_act
												_a      :       Optional[Any]   =						tf_padding
												_a      :       str   =						classifier_dropout_prob
												_a      :       Optional[int]   =						initializer_range
												_a      :       Any   =						layer_norm_eps



class 							UpperCAmelCase_						(     __lowercase  ):
							"""simple docstring"""







							UpperCAmelCase__			:		str             =       version.parse("1.11"  )


							@property
							def 							__lowercase							(     self			)       ->       Mapping[str, Mapping[int, str]]:
												return OrderedDict([('''pixel_values''', {0: '''batch'''})]			)


							@property
							def 							__lowercase							(     self			)       ->       Mapping[str, Mapping[int, str]]:
												if self.task == "image-classification":
																	return OrderedDict([('''logits''', {0: '''batch'''})]			)
												else:
																	return OrderedDict([('''last_hidden_state''', {0: '''batch'''}), ('''pooler_output''', {0: '''batch'''})]			)




							@property
							def 							__lowercase							(     self			)       ->       float:
												return 1e-4



