pythonblurprivacyfaceanonymize

ModuleNotFoundError: No module named 'anonymizer.anonymization'


Getting this error: (blur) D:\anonymizer-master\anonymizer\bin>python anonymize.py Traceback (most recent call last): File "anonymize.py", line 20, in <module> from anonymizer.anonymization import Anonymizer

By Running this file:
import argparse

from anonymizer.anonymization import Anonymizer
from anonymizer.detection import Detector, download_weights, get_weights_path
from anonymizer.obfuscation import Obfuscator


def parse_args():
    parser = argparse.ArgumentParser(
        description='Anonymize faces and license plates in a series of images.')
    parser.add_argument('--input', required=True,
                        metavar='/path/to/input_folder',
                        help='Path to a folder that contains the images that should be anonymized. '
                             'Images can be arbitrarily nested in subfolders and will still be found.')
    parser.add_argument('--image-output', required=True,
                        metavar='/path/to/output_foler',
                        help='Path to the folder the anonymized images should be written to. '
                             'Will mirror the folder structure of the input folder.')
    parser.add_argument('--weights', required=True,
                        metavar='/path/to/weights_foler',
                        help='Path to the folder where the weights are stored. If no weights with the '
                             'appropriate names are found they will be downloaded automatically.')
    parser.add_argument('--image-extensions', required=False, default='jpg,png',
                        metavar='"jpg,png"',
                        help='Comma-separated list of file types that will be anonymized')
    parser.add_argument('--face-threshold', type=float, required=False, default=0.3,
                        metavar='0.3',
                        help='Detection confidence needed to anonymize a detected face. '
                             'Must be in [0.001, 1.0]')
    parser.add_argument('--plate-threshold', type=float, required=False, default=0.3,
                        metavar='0.3',
                        help='Detection confidence needed to anonymize a detected license plate. '
                             'Must be in [0.001, 1.0]')
    parser.add_argument('--write-detections', dest='write_detections', action='store_true')
    parser.add_argument('--no-write-detections', dest='write_detections', action='store_false')
    parser.set_defaults(write_detections=True)
    parser.add_argument('--obfuscation-kernel', required=False, default='21,2,9',
                        metavar='kernel_size,sigma,box_kernel_size',
                        help='This parameter is used to change the way the blurring is done. '
 

Solution

  • This problem occurs because Python cannot find the anonymizer.anonymization module in PYTHONPATH. So, a solution is to install the module because thankfully the repo has a functional setup.py. Run the below code (tested on Ubuntu) from the anonymizer-master's parent directory.

    pip install anonymizer-master
    python anonymizer-master/anonymizer/bin/anonymize.py
    

    The first command will also install the repo's dependencies. If you plan to edit the files in the repo, use pip install -e anonymizer-master (notice the -e option) to install in editable mode.