From 337f5c7d1fb43c600dd48288415f5bb245505305 Mon Sep 17 00:00:00 2001 From: Gavin Taylor Date: Sun, 27 Jan 2019 10:50:05 -0500 Subject: [PATCH 1/2] The current use of scipy.misc for image reading/writing/resizing in the implementation of mtcnn will be deprecated with the new version of scipy. In addition, (and most motivating for me), the scipy.misc imread function ignores the image's Orientation Exif flag, meaning vertical images can be read in rotated, greating decreasing performance. This branch converts all scipy.misc functions in align_dataset_mtcnn.py to the appropriate and suggested equivalents in the imageio package. This introduces a new project dependency on imageio, but the orientation data is now considered and handled appropriately. --- src/align/align_dataset_mtcnn.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/align/align_dataset_mtcnn.py b/src/align/align_dataset_mtcnn.py index 7d5e735e6..25447b65f 100644 --- a/src/align/align_dataset_mtcnn.py +++ b/src/align/align_dataset_mtcnn.py @@ -25,7 +25,9 @@ from __future__ import division from __future__ import print_function -from scipy import misc +import imageio +#from scipy import misc +from PIL import Image import sys import os import argparse @@ -80,7 +82,7 @@ def main(args): print(image_path) if not os.path.exists(output_filename): try: - img = misc.imread(image_path) + img = imageio.imread(image_path) except (IOError, ValueError, IndexError) as e: errorMessage = '{}: {}'.format(image_path, e) print(errorMessage) @@ -121,14 +123,14 @@ def main(args): bb[2] = np.minimum(det[2]+args.margin/2, img_size[1]) bb[3] = np.minimum(det[3]+args.margin/2, img_size[0]) cropped = img[bb[1]:bb[3],bb[0]:bb[2],:] - scaled = misc.imresize(cropped, (args.image_size, args.image_size), interp='bilinear') + scaled = np.array(Image.fromarray(cropped).resize((args.image_size,args.image_size))) nrof_successfully_aligned += 1 filename_base, file_extension = os.path.splitext(output_filename) if args.detect_multiple_faces: output_filename_n = "{}_{}{}".format(filename_base, i, file_extension) else: output_filename_n = "{}{}".format(filename_base, file_extension) - misc.imsave(output_filename_n, scaled) + imageio.imwrite(output_filename_n, scaled) text_file.write('%s %d %d %d %d\n' % (output_filename_n, bb[0], bb[1], bb[2], bb[3])) else: print('Unable to align "%s"' % image_path) From 1e69953d184588ba8ba572fa2010264e46f48a9d Mon Sep 17 00:00:00 2001 From: Gavin Taylor Date: Sun, 27 Jan 2019 10:57:52 -0500 Subject: [PATCH 2/2] removing unnecessary commented line --- src/align/align_dataset_mtcnn.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/align/align_dataset_mtcnn.py b/src/align/align_dataset_mtcnn.py index 25447b65f..bc41dace3 100644 --- a/src/align/align_dataset_mtcnn.py +++ b/src/align/align_dataset_mtcnn.py @@ -26,7 +26,6 @@ from __future__ import print_function import imageio -#from scipy import misc from PIL import Image import sys import os