Skip to content

Commit

Permalink
clarified no_multiprocessing variable/flag name and added if statemen…
Browse files Browse the repository at this point in the history
…t to close pool
  • Loading branch information
CharlesDove committed Jun 10, 2020
1 parent 0c096f3 commit c85ff4a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions datasets/combine_A_and_B.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def image_write(path_A, path_B, path_AB):
parser.add_argument('--fold_AB', dest='fold_AB', help='output directory', type=str, default='../dataset/test_AB')
parser.add_argument('--num_imgs', dest='num_imgs', help='number of images', type=int, default=1000000)
parser.add_argument('--use_AB', dest='use_AB', help='if true: (0001_A, 0001_B) to (0001_AB)', action='store_true')
parser.add_argument('--no_multiprocessing', dest='no_multiprocess', help='If used, chooses single CPU execution instead of parallel execution', action='store_true',default=False)
parser.add_argument('--no_multiprocessing', dest='no_multiprocessing', help='If used, chooses single CPU execution instead of parallel execution', action='store_true',default=False)
args = parser.parse_args()

for arg in vars(args):
print('[%s] = ' % arg, getattr(args, arg))

splits = os.listdir(args.fold_A)

if not args.no_multiprocess:
if not args.no_multiprocessing:
pool=Pool()

for sp in splits:
Expand Down Expand Up @@ -55,13 +55,13 @@ def image_write(path_A, path_B, path_AB):
if args.use_AB:
name_AB = name_AB.replace('_A.', '.') # remove _A
path_AB = os.path.join(img_fold_AB, name_AB)
if not args.no_multiprocess:
if not args.no_multiprocessing:
pool.apply_async(image_write, args=(path_A, path_B, path_AB))
else:
im_A = cv2.imread(path_A, 1) # python2: cv2.CV_LOAD_IMAGE_COLOR; python3: cv2.IMREAD_COLOR
im_B = cv2.imread(path_B, 1) # python2: cv2.CV_LOAD_IMAGE_COLOR; python3: cv2.IMREAD_COLOR
im_AB = np.concatenate([im_A, im_B], 1)
cv2.imwrite(path_AB, im_AB)

pool.close()
pool.join()
if not args.no_multiprocessing:
pool.close()
pool.join()

0 comments on commit c85ff4a

Please sign in to comment.