multithreading - Python: threading + curve_fit: null argument to internal routine -
i have got problems using following code, supposed gaussian fits using threads:
pil import image import numpy np scipy.optimize import curve_fit import threading class mythread (threading.thread): def __init__(self, index): threading.thread.__init__(self) self.index = index def run(self): in np.arange(n_bild.shape[1]): curve_fit(self.gauss, x_x, intensitaet[self.index, ...], p0=(intensitaet[self.index, i], i, 1, 0)) def gauss(self, x, a, b, c, d): return * np.exp(-(x-b) ** 2 / (2 * c ** 2)) + d bild = image.open("test.bmp") n_bild = np.asarray(bild) intensitaet = np.zeros((n_bild.shape[0], n_bild.shape[1]), dtype=np.uint32) intensitaet += n_bild[..., ..., 0] intensitaet += n_bild[..., ..., 1] intensitaet += n_bild[..., ..., 2] x_x = np.arange(n_bild.shape[1]) #pixel auf "x"-achse threads = [] # create new threads thread0 = mythread(0) thread1 = mythread(1) # add threads thread list threads.append(thread0) threads.append(thread1) # start new threads thread0.start() thread1.start() # wait threads complete t in threads: t.join() print "finished"
if run programm error:
systemerror: null argument internal routine exception in thread thread-2: traceback (most recent call last): file "c:\anaconda\lib\threading.py", line 808, in __bootstrap_inner self.run() file "g:/dropbox/daten/dropbox/uni/bachelorarbeit/python/threadtest.py", line 12, in run curve_fit(self.gauss, x_x, intensitaet[self.index, ...], p0=(intensitaet[self.index, i], i, 1, 0)) file "c:\anaconda\lib\site-packages\scipy\optimize\minpack.py", line 533, in curve_fit res = leastsq(func, p0, args=args, full_output=1, **kw) file "c:\anaconda\lib\site-packages\scipy\optimize\minpack.py", line 378, in leastsq gtol, maxfev, epsfcn, factor, diag) error: internal error constructing argument list.#
if run 1 thread instead of two, programm works fine, have no idea i'm doing wrong. help.
i believe leastsq() not threadsafe, , need either use threading.lock() around calls curve_fit() (which might defeat purpose) or use multiprocessing.
Comments
Post a Comment