Closed kylezhang1983 closed 6 years ago
And If I don't check the subprocess result:
change line 131: result.append(multiprocess_pool.apply_async(caffe_preprocess_and_compute, args=(p, caffe_transformer, nsfw_net, ['prob'] ,))) ---->multiprocess_pool.apply_async(caffe_preprocess_and_compute, args=(p, caffe_transformer, nsfw_net, ['prob'] ,))
it's ok
this issue caused by bad usage for multi-processing poll
@kylezhang1983 Hi, how did you solve this issue? I have the same problem as you did.
@taosean , look Caffee will solve it in Caffee2. So I change the framwork caffee to tensorflow.
when I try run open_nsfw in multi-process , a runtimeError raised: Traceback (most recent call last): File "./verify_concurrency.py", line 152, in
main(sys.argv)
File "./verify_concurrency.py", line 149, in main
print res.get()
File "/usr/lib/python2.7/multiprocessing/pool.py", line 567, in get raise self._value RuntimeError: Pickling of "caffe._caffe.Net" instances is not enabled (http://www.boost.org/libs/python/doc/v2/pickle.html)
could some expert help check where is wrong as i'm rookie my command is : ./verify_concurrency.py --model_def ./nsfw_model/deploy.prototxt --pretrained_model ./nsfw_model/resnet_50_1by2_nsfw.caffemodel /home/harold/nsfw/pic/1
below is my script verify_concurrency.py :
!/usr/bin/env python
""" Copyright 2016 Yahoo Inc. Licensed under the terms of the 2 clause BSD license. Please see LICENSE file in the project root for terms. """
import numpy as np import os import sys import argparse import glob import time from PIL import Image from StringIO import StringIO import caffe from multiprocessing import Pool
def resize_image(data, sz=(256, 256)): """ Resize image. Please use this resize logic for best results instead of the caffe, since it was used to generate training dataset :param str data: The image data :param sz tuple: The resized image dimensions :returns bytearray: A byte array with the resized image """ img_data = str(data) im = Image.open(StringIO(img_data)) if im.mode != "RGB": im = im.convert('RGB') imr = im.resize(sz, resample=Image.BILINEAR) fh_im = StringIO() imr.save(fh_im, format='JPEG') fh_im.seek(0) return bytearray(fh_im.read())
def caffe_preprocess_and_compute(file_name, caffe_transformer=None, caffe_net=None, output_layers=None): """ Run a Caffe network on an input image after preprocessing it to prepare it for Caffe. :param file name file_name: PIL image to be input into Caffe. :param caffe.Net caffe_net: A Caffe network with which to process pimg afrer preprocessing. :param list output_layers: A list of the names of the layers from caffe_net whose outputs are to to be returned. If this is None, the default outputs for the network are returned. :return: Returns the requested outputs from the Caffe net. """ if caffe_net is not None:
def main(argv): pycaffe_dir = os.path.dirname(file)
if name == 'main': main(sys.argv)