Skip to content

Commit

Permalink
fix multi process bug for python2
Browse files Browse the repository at this point in the history
  • Loading branch information
dingjiansw101 committed Jun 14, 2019
1 parent afd0aa1 commit 0d9ff46
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
16 changes: 10 additions & 6 deletions ImgSplit_multi_process.py
Expand Up @@ -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,
Expand Down Expand Up @@ -78,6 +80,7 @@ def __init__(self,
self.choosebestpoint = choosebestpoint
self.ext = ext
self.padding = padding
self.num_process = num_process
self.pool = Pool(num_process)
print('padding:', padding)

Expand Down Expand Up @@ -258,15 +261,16 @@ def splitdata(self, rate):
"""
: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)
self.pool.map(worker, imagenames)
# 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):
self_dict = self.__dict__.copy()
Expand Down
10 changes: 8 additions & 2 deletions SplitOnlyImage_multi_process.py
Expand Up @@ -6,6 +6,9 @@
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,
Expand Down Expand Up @@ -53,6 +56,9 @@ def SplitSingle(self, name, rate, extent):
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):
Expand All @@ -77,8 +83,8 @@ def splitdata(self, rate):
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:
Expand Down

0 comments on commit 0d9ff46

Please sign in to comment.