  
          logger.info("Sorting by face similarity...")
  
          images = np.array(self.find_images(input_dir))
          preds = np.array([self.vgg_face.predict(cv2.imread(img))
                            for img in tqdm(images, desc="loading", file=sys.stdout)])
          logger.info("Sorting. Depending on ths size of your dataset, this may take a few "
                      "minutes...")
          indices = self.vgg_face.sorted_similarity(preds, method="ward")
          img_list = images[indices]
 
</s> remove             [img, cv2.calcHist([cv2.imread(img)], [0], None, [256], [0, 256])]
 </s> add             [img, cv2.calcHist([cv2_read_img(img, raise_error=True)], [0], None, [256], [0, 256])] </s> remove         Estimate the amount of blur an image has
        with the variance of the Laplacian.
        Normalize by pixel number to offset the effect
        of image size on pixel gradients & variance
 </s> add         Estimate the amount of blur an image has with the variance of the Laplacian.
        Normalize by pixel number to offset the effect of image size on pixel gradients & variance </s> remove         image = cv2.imread(image_file)
 </s> add         image = cv2_read_img(image_file, raise_error=True) </s> remove              cv2.calcHist([cv2.imread(img)], [0], None, [256], [0, 256]), 0]
 </s> add              cv2.calcHist([cv2_read_img(img, raise_error=True)], [0], None, [256], [0, 256]), 0] </s> remove         image = cv2.imread(filename)
 </s> add         image = cv2_read_img(filename, raise_error=True)
        preds = np.array([self.vgg_face.predict(cv2_read_img(img, raise_error=True))
  
          logger.info("Sorting by face similarity...")
  
          images = np.array(self.find_images(input_dir))
        preds = np.array([self.vgg_face.predict(cv2_read_img(img, raise_error=True))
                            for img in tqdm(images, desc="loading", file=sys.stdout)])
          logger.info("Sorting. Depending on ths size of your dataset, this may take a few "
                      "minutes...")
          indices = self.vgg_face.sorted_similarity(preds, method="ward")
          img_list = images[indices]
keep keep keep keep replace keep keep keep keep keep
 Centralize cv2 image reading and handle bad filenames 
tools/sort.py