Example #1
0
class AipAntiPornModel(AipModel):
    """Create a :class:`Model` instance from an `AipAntiPorn` model.

    Parameters
    ----------
    credential : tuple
        Tuple of (appId, apiKey, secretKey) for using AIP API.
    bounds : tuple
        Tuple of lower and upper bound for the pixel values, usually
        (0, 1) or (0, 255).
    channel_axis : int
        The index of the axis that represents color channels.
    preprocessing: 2-element tuple with floats or numpy arrays
        Elementwises preprocessing of input; we first substract the first
        element of preprocessing from the input and then divide the input
        by the second element.

    """
    def __init__(self,
                 credential,
                 bounds=(0, 255),
                 channel_axis=3,
                 preprocessing=(0, 1)):

        from aip import AipImageCensor
        super(AipAntiPornModel, self).__init__(credential=credential,
                                               bounds=bounds,
                                               channel_axis=channel_axis,
                                               preprocessing=preprocessing)

        self._task = 'cls'
        self.model = AipImageCensor(self._appId, self._apiKey, self._secretKey)

    def predictions(self, image):
        """Get prediction for input image

        Parameters
        ----------
        image : `numpy.ndarray`
            The input image in [h, n, c] ndarry format.

        Returns
        -------
        list
            List of anitporn prediction resutls.
            Each element is a dictionary containing:
            {'class_name', 'probability'}

        """

        image_bytes = ndarray_to_bytes(image)
        predictions = self.model.antiPorn(image_bytes)
        if 'result' in predictions:
            return predictions['result']
        return predictions

    def model_task(self):
        """Get the task that the model is used for."""
        return self._task
Example #2
0
def Check_Baidu():
    imgContent, imgType = downloadImg(imgurl)
    if len(imgContent) < 5e3 or len(imgContent) > 4e6:
        return
    if imgType not in ['jpg', 'jpeg', 'png']:
        return

    from aip import AipImageCensor

    censor_APP_ID = '15708523'
    censor_API_KEY = '6USQY453ZVSjxYYej1F195IZ'
    censor_SECRET_KEY = 'r0rtrpRj8eHRnkPCfEhjOPRh2eO997Uv'

    #另一个百度账号
    if random.random() < 0:
        censor_APP_ID = '22908418'
        censor_API_KEY = 'Fz2zsXkSFmdH4BgcSwvGLeNP'
        censor_SECRET_KEY = 'VSbOwvqUNzG1cDW89O9iTnnweLvLyGGM'

    #classify_APP_ID = '17981247'
    #classify_API_KEY = '3HuleW8fwIPymQcRM1DNhigp'
    #classify_SECRET_KEY = 'LcClAOmKwGSIXR2st8ishMXUPXkiLaaI'

    censor_client = AipImageCensor(censor_APP_ID, censor_API_KEY,
                                   censor_SECRET_KEY)
    censor_result = censor_client.antiPorn(imgContent)

    #print(censor_result)
    if 'result_fine' in censor_result:
        for each in censor_result['result_fine']:
            #print('type', each['type'], 'prob', each['probability'])
            if each['class_name'] == '一般色情' and each['probability'] > 0.9:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '卡通色情' and each['probability'] > 0.51:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == 'SM' and each['probability'] > 0.65:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '艺术品色情' and each['probability'] > 0.9:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '儿童裸露' and each['probability'] > 0.9:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '低俗' and each['probability'] > 0.95:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '性玩具' and each['probability'] > 0.7:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '女性性感' and each['probability'] > 0.85:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '卡通女性性感' and each['probability'] > 0.51:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '男性性感' and each['probability'] > 0.95:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '自然男性裸露' and each['probability'] > 0.95:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '亲密行为' and each['probability'] > 0.90:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '卡通亲密行为' and each['probability'] > 0.65:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '特殊类' and each['probability'] > 0.95:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '一般正常' and each['probability'] > 1.0:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '卡通正常' and each['probability'] > 1.0:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '臀部特写' and each['probability'] > 0.85:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '裆部特写' and each['probability'] > 0.75:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '脚部特写' and each['probability'] > 0.85:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '孕肚裸露' and each['probability'] > 0.99:
                print('色图!', end='')
                saveImg(imgurl)
                break
Example #3
0
# -*- coding: utf-8 -*-

# 定义常量
APP_ID = '9839224'
API_KEY = '38aM2cGHnGXgfjwPgNv3hgHN'
SECRET_KEY = 'ze0DckCR2GTpFcz8LX17L61Ec8NV9Bc7'

# 引入AipImageCensor SDK
from aip import AipImageCensor


# 初始化AipImageCensor对象
aipImageCensor = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)

# 读取图片
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

# 调用色情识别接口
result = aipImageCensor.antiPorn(get_file_content('antiporn.jpg'))
print(result)
Example #4
0
def downloadImg(url):
    r = requests.get(url)
    return r.content


censor_APP_ID = '15708523'
censor_API_KEY = '6USQY453ZVSjxYYej1F195IZ'
censor_SECRET_KEY = 'r0rtrpRj8eHRnkPCfEhjOPRh2eO997Uv'

#classify_APP_ID = '17981247'
#classify_API_KEY = '3HuleW8fwIPymQcRM1DNhigp'
#classify_SECRET_KEY = 'LcClAOmKwGSIXR2st8ishMXUPXkiLaaI'

censor_client = AipImageCensor(censor_APP_ID, censor_API_KEY,
                               censor_SECRET_KEY)
censor_result = censor_client.antiPorn(downloadImg(imgurl))

print(censor_result)
if 'result_fine' in censor_result:
    for each in censor_result['result_fine']:
        #print('type', each['type'], 'prob', each['probability'])
        if each['class_name'] == '一般色情' and each['probability'] > 0.9:
            print('色图!', end='')
            saveImg(imgurl)
            break
        elif each['class_name'] == '卡通色情' and each['probability'] > 0.55:
            print('色图!', end='')
            saveImg(imgurl)
            break
        elif each['class_name'] == 'SM' and each['probability'] > 0.65:
            print('色图!', end='')