I'm trying to use all the CPU so I'm using threading package
But I get similar time using one that ten threads (in a 12 threads cpu)
I believe there is a limit in python, but not sure, int top I see only 133% CPU.
I put the code but I think it is not software defect.
class normalizeTh(threading.Thread):
def __init__(self, image, idx):
self.image = image
self.output = image
self.idx = idx
threading.Thread.__init__(self)
def run(self):
# print("test")
self.output = exposure.equalize_adapthist(self.image, clip_limit=0.03)
numTheads = 10
def normalizeImgTh(X):
global numThreads
idx = 0
dest = np.empty(X.shape)
ths = []
for img in tqdm(X):
# if we have all threads used, wait until fist is free
if len(ths) >= numThreads:
ths[0].join()
dest[ths[0].idx] = ths[0].output
del ths[0]
nTh = normalizeTh(img, idx)
nTh.start()
ths.append(nTh)
idx += 1
#delete all finished threads... garbage out
for i in range(len(ths),0,-1):
if not ths[i-1].is_alive():
dest[ths[0].idx] = ths[0].output
del ths[i-1]
# wait for all pending threads.
while len(ths) > 0:
ths[0].join()
dest[ths[0].idx] = ths[0].output
return dest
dest=normalizeImgTh(X_train)