bear63 / sceneReco

ctpn+crnn Scene character recognition
943 stars 371 forks source link

how to run the demo code in multiprocess in python(I change it but get error) #14

Closed Jayhello closed 7 years ago

Jayhello commented 7 years ago

from ctpnport import *
from crnnport import *
from multiprocessing import Pool as ProcessPool
from multiprocessing.dummy import Pool as ThreadPool
import time

#ctpn
text_detector = ctpnSource()
#crnn
model,converter = crnnSource()

timer=Timer()

def loop_by_input_filename():
    print "\ninput exit break\n"
    while 1 :
        im_name = raw_input("\nplease input file name:")
        if im_name == "exit":
           break
        im_path = "./img/" + im_name
        im = cv2.imread(im_path)
        if im is None:
          continue
        timer.tic()
        img,text_recs = getCharBlock(text_detector,im)
        print 'after demo.py getCharBlock(text_detector,im)'
        crnnRec(model,converter,img,text_recs)
        print "Time: %f"%timer.toc()
        #cv2.waitKey(0)    

def do_recognition(file):
    im = cv2.imread(file)
    timer.tic()
    img,text_recs = getCharBlock(text_detector,im)
    crnnRec(model,converter,img,text_recs)
    print "Time: %f"%timer.toc()

def get_all_files_in_dir(dir='./img/'):
    import glob
    files = glob.glob(dir + '*.jpg')
    return files
def stress_test():
    files = get_all_files_in_dir()
    print files
    start = time.time()
    pool = ProcessPool(1)
    #pool = ThreadPool(1)
    ret = pool.map(do_recognition, files)
    pool.close()
    pool.join()
    print 'time consume %s' % (time.time() - start)
if __name__ == '__main__':
    stress_test()
    #loop_by_input_filename()
    #do_recognition('./img/22.jpg')

when I runs python demo.py I get the below error, I just use one process,

""" F0728 16:03:35.364833 4085 syncedmem.hpp:19] Check failed: error == cudaSuccess (3 vs. 0) initialization error Check failure stack trace: E0728 16:03:36.586454 4090 common.cpp:103] Cannot create Cublas handle. Cublas won't be available. E0728 16:03:36.586565 4090 common.cpp:110] Cannot create Curand generator. Curand won't be available. Number of the detected text lines: 3 Time: 22.920991 THCudaCheck FAIL file=/b/wheel/pytorch-src/torch/lib/THC/generic/THCStorage.c line=55 error=3 : initialization error Traceback (most recent call last): File "demo.py", line 54, in stress_test() File "demo.py", line 49, in stress_test ret = pool.map(do_recognition, files) File "/usr/lib/python2.7/multiprocessing/pool.py", line 251, in map return self.map_async(func, iterable, chunksize).get() File "/usr/lib/python2.7/multiprocessing/pool.py", line 558, in get raise self._value RuntimeError: cuda runtime error (3) : initialization error at /b/wheel/pytorch-src/torch/lib/THC/generic/THCStorage.c:55 """

if I change the code as below, i also get error

    #pool = ProcessPool(1)
    pool = ThreadPool(1)

""" Error in `python': free(): invalid pointer: 0x0000000204800000 Aborted (core dumped) """