예제 #1
0
 def detect_image(self, image_data):
     scores = caffe_preprocess_and_compute(
         image_data,
         caffe_transformer=self.caffe_transformer,
         caffe_net=self.nsfw_net,
         output_layers=['prob'])
     return scores[1]
예제 #2
0
파일: app.py 프로젝트: ruanhanqin/nsfw_api
def classify(image_data, nsfw_net):
    # Classify.
    scores = classify_nsfw.caffe_preprocess_and_compute(
        image_data,
        caffe_transformer=caffe_transformer,
        caffe_net=nsfw_net,
        output_layers=['prob'])

    return scores[1]
예제 #3
0
def classify(image_data, nsfw_net):

    # disable stdout
    null_fds = [os.open(os.devnull, os.O_RDWR) for x in range(2)]
    save = os.dup(1), os.dup(2)
    os.dup2(null_fds[0], 1)
    os.dup2(null_fds[1], 2)

    scores = classify_nsfw.caffe_preprocess_and_compute(
        image_data,
        caffe_transformer=caffe_transformer,
        caffe_net=nsfw_net,
        output_layers=['prob'])

    # enable stdout
    os.dup2(save[0], 1)
    os.dup2(save[1], 2)
    os.close(null_fds[0])
    os.close(null_fds[1])

    return scores
예제 #4
0
def ck():

    u0 = u = ""

    try:
        u0 = request.args.get('u')
        u = urllib.unquote(u0).decode('utf8')

        handle = urlopen(u)
        image_data = handle.read()

        # Classify.
        scores = classify_nsfw.caffe_preprocess_and_compute(image_data, caffe_transformer=caffe_transformer, caffe_net=nsfw_net, output_layers=['prob'])

        # Scores is the array containing SFW / NSFW image probabilities
        # scores[1] indicates the NSFW probability
        # print "NSFW score:  " , scores[1]

        rt = {
            "code": 0,
            "msg": "",
            "data": {
                "score" : scores[1]
            }
        }
        return jsonify(rt)


    except Exception as e:
        msg = "%s, decode: %s, raw: %s" % (str(e), u, u0)
        rt = {
            "code": 500,
            "msg": msg,
            "data": {}
        }
        return jsonify(rt)
예제 #5
0
def classify(image: bytes) -> np.float64:
    scores = caffe_preprocess_and_compute(image,
                                          caffe_transformer=caffe_transformer,
                                          caffe_net=nsfw_net,
                                          output_layers=["prob"])
    return scores[1]
예제 #6
0
def classify(image_path: str) -> np.float64:
    with open(image_path, "rb") as image:
        scores = caffe_preprocess_and_compute(image.read(), caffe_transformer=caffe_transformer, caffe_net=nsfw_net, output_layers=["prob"])
    return scores[1]