Skip to content
Snippets Groups Projects
Commit 0d9ff463 authored by dingjian's avatar dingjian
Browse files

fix multi process bug for python2

parent afd0aa1a
No related branches found
No related tags found
No related merge requests found
......@@ -38,6 +38,8 @@ def cal_line_length(point1, point2):
return math.sqrt( math.pow(point1[0] - point2[0], 2) + math.pow(point1[1] - point2[1], 2))
def split_single_warp(name, split_base, rate, extent):
split_base.SplitSingle(name, rate, extent)
class splitbase():
def __init__(self,
......@@ -78,6 +80,7 @@ class splitbase():
self.choosebestpoint = choosebestpoint
self.ext = ext
self.padding = padding
self.num_process = num_process
self.pool = Pool(num_process)
print('padding:', padding)
......@@ -258,14 +261,15 @@ class splitbase():
"""
:param rate: resize rate before cut
"""
imagelist = GetFileFromThisRootDir(self.imagepath)
imagenames = [util.custombasename(x) for x in imagelist if (util.custombasename(x) != 'Thumbs')]
if self.num_process == 1:
for name in imagenames:
self.SplitSingle(name, rate, self.ext)
else:
worker = partial(self.SplitSingle, rate=rate, extent=self.ext)
#
# for name in imagenames:
# self.SplitSingle(name, rate, self.ext)
# worker = partial(self.SplitSingle, rate=rate, extent=self.ext)
worker = partial(split_single_warp, split_base=self, rate=rate, extent=self.ext)
self.pool.map(worker, imagenames)
def __getstate__(self):
......
......@@ -6,6 +6,9 @@ import dota_utils as util
from multiprocessing import Pool
from functools import partial
def split_single_warp(name, split_base, rate, extent):
split_base.SplitSingle(name, rate, extent)
class splitbase():
def __init__(self,
srcpath,
......@@ -53,6 +56,9 @@ class splitbase():
weight = np.shape(resizeimg)[1]
height = np.shape(resizeimg)[0]
# if (max(weight, height) < self.subsize/2):
# return
left, up = 0, 0
while (left < weight):
if (left + self.subsize >= weight):
......@@ -77,8 +83,8 @@ class splitbase():
imagelist = util.GetFileFromThisRootDir(self.srcpath)
imagenames = [util.custombasename(x) for x in imagelist if (util.custombasename(x) != 'Thumbs')]
worker = partial(self.SplitSingle, rate=rate, extent=self.ext)
# worker = partial(self.SplitSingle, rate=rate, extent=self.ext)
worker = partial(split_single_warp, split_base=self, rate=rate, extent=self.ext)
self.pool.map(worker, imagenames)
#
# for name in imagenames:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment