Closed slslazy closed 1 year ago
Do you mean completely black out the full body? If so, yes!
You can use the anonymization script with this config file:
configs/anonymizers/market1501/blackout.py
Thanks for the reply @hukkelas! I've tested that one and receive the following error. I'll play with it more later today.
Traceback (most recent call last):
File "anonymize.py", line 255, in
This commit should resolve the issue. Could you try again with the updated code?
Thanks for the update. No luck. Looks like there's a script missing from that generator's directory.
Traceback (most recent call last): File "anonymize.py", line 255, in
anonymize_path() File "/home/ubuntu/miniconda3/envs/dp2/lib/python3.8/site-packages/click/core.py", line 1130, in call return self.main(args, kwargs) File "/home/ubuntu/miniconda3/envs/dp2/lib/python3.8/site-packages/click/core.py", line 1055, in main rv = self.invoke(ctx) File "/home/ubuntu/miniconda3/envs/dp2/lib/python3.8/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/ubuntu/miniconda3/envs/dp2/lib/python3.8/site-packages/click/core.py", line 760, in invoke return __callback(args, *kwargs) File "anonymize.py", line 231, in anonymize_path anonymizer = instantiate(cfg.anonymizer, load_cache=cache) File "/home/ubuntu/miniconda3/envs/dp2/lib/python3.8/site-packages/tops/config/instantiate.py", line 77, in instantiate return cls(args_, cfg, kwargs) File "/home/ubuntu/python_projects/deep_privacy2/dp2/anonymizer/anonymizer.py", line 35, in init self.generators[CSEPersonDetection] = load_generator_from_cfg_path(cse_person_G_cfg) File "/home/ubuntu/python_projects/deep_privacy2/dp2/anonymizer/anonymizer.py", line 14, in load_generator_from_cfg_path cfg = load_config(cfg_path) File "/home/ubuntu/python_projects/deep_privacy2/dp2/utils/init.py", line 15, in load_config assert config_path.is_file(), config_path AssertionError: configs/generators/dummy/maskout.py
They're added now with this commit. Hope it works now! :)
Thanks for the update. Works perfectly :)
Hello @hukkelas ! Amazing repo but unfortunately getting the following error:
python3 anonymize.py configs/anonymizers/market1501/blackout.py -i /home/kameel/Pictures/TestIn/ --output_path output_folder/
Saving outputs to: outputs/anonymizers/market1501/blackout
2023-08-08 16:17:28,845 [INFO ] driver.py: 266 Generating grammar tables from /home/kameel/anaconda3/lib/python3.9/site-packages/blib2to3/Grammar.txt
2023-08-08 16:17:28,861 [INFO ] driver.py: 269 Writing grammar tables to /home/kameel/.cache/black/22.6.0/Grammar3.9.13.final.0.pickle
2023-08-08 16:17:28,861 [INFO ] driver.py: 273 Writing failed: [Errno 2] No such file or directory: '/home/kameel/.cache/black/22.6.0/tmpcmf7t_6p'
2023-08-08 16:17:28,862 [INFO ] driver.py: 266 Generating grammar tables from /home/kameel/anaconda3/lib/python3.9/site-packages/blib2to3/PatternGrammar.txt
2023-08-08 16:17:28,864 [INFO ] driver.py: 269 Writing grammar tables to /home/kameel/.cache/black/22.6.0/PatternGrammar3.9.13.final.0.pickle
2023-08-08 16:17:28,864 [INFO ] driver.py: 273 Writing failed: [Errno 2] No such file or directory: '/home/kameel/.cache/black/22.6.0/tmpn78adehv'
2023-08-08 16:17:29,001 [INFO ] logger.py: 102 [0]
anonymizer = dp2.anonymizer.Anonymizer(
_args_=[],
car_G_cfg="configs/generators/dummy/pixelation8.py",
cse_person_G_cfg="configs/generators/dummy/maskout.py",
detector=dp2.detection.CSeMaskFaceDetector(
_args_=[],
cache_directory=PosixPath("outputs/cse_mask_face_detection_cache"),
cse_cfg={"score_thres": 0.3},
cse_post_process_cfg={
"dilation_percentage": 0.02,
"exp_bbox_cfg": {
"axis_minimum_expansion": 0.1,
"percentage_background": 0.3,
},
"exp_bbox_filter": {
"aspect_ratio_range": [0, 99999],
"min_bbox_ratio_inside": 0,
"minimum_area": 1024,
},
"iou_combine_threshold": 0.4,
"normalize_embedding": False,
"target_imsize": [288, 160],
},
face_detector_cfg={"confidence_threshold": 0.5},
face_post_process_cfg={"fdf128_expand": False, "target_imsize": [256, 256]},
mask_rcnn_cfg={},
score_threshold=0.3,
),
face_G_cfg=None,
person_G_cfg="configs/generators/dummy/maskout.py",
)
checkpoint_dir = PosixPath("outputs/anonymizers/market1501/blackout/checkpoints")
common.experiment_name = None
common.logger_backend = ["wandb", "stdout", "json", "image_dumper"]
common.output_dir = PosixPath("outputs")
common.wandb_project = "deep_privacy2"
detector = dp2.detection.CSeMaskFaceDetector(
_args_=[],
cache_directory=PosixPath("outputs/cse_mask_face_detection_cache"),
cse_cfg={"score_thres": 0.3},
cse_post_process_cfg={
"dilation_percentage": 0.02,
"exp_bbox_cfg": {"axis_minimum_expansion": 0.1, "percentage_background": 0.3},
"exp_bbox_filter": {
"aspect_ratio_range": [0, 99999],
"min_bbox_ratio_inside": 0,
"minimum_area": 1024,
},
"iou_combine_threshold": 0.4,
"normalize_embedding": False,
"target_imsize": [288, 160],
},
face_detector_cfg={"confidence_threshold": 0.5},
face_post_process_cfg={"fdf128_expand": False, "target_imsize": [256, 256]},
mask_rcnn_cfg={},
score_threshold=0.3,
)
experiment_name = "configs/anonymizers/market1501/blackout.py"
filename = "configs/anonymizers/market1501/blackout.py"
output_dir = PosixPath("outputs/anonymizers/market1501/blackout")
2023-08-08 16:17:33,576 [INFO ] logger.py: 102 [0]Mask R-CNN built.
2023-08-08 16:17:35,137 [INFO ] logger.py: 102 [0]CSEDetector built.
Saving outputs to: outputs/generators/dummy/maskout
2023-08-08 16:17:36,575 [WARNI] logger.py: 102 [0]Did not find generator checkpoint in: outputs/generators/dummy/maskout/checkpoints
2023-08-08 16:17:36,575 [INFO ] logger.py: 102 [0]Loaded generator from: configs/generators/dummy/maskout.py
Saving outputs to: outputs/generators/dummy/maskout
2023-08-08 16:17:36,578 [WARNI] logger.py: 102 [0]Did not find generator checkpoint in: outputs/generators/dummy/maskout/checkpoints
2023-08-08 16:17:36,578 [INFO ] logger.py: 102 [0]Loaded generator from: configs/generators/dummy/maskout.py
Saving outputs to: outputs/generators/dummy/pixelation8
2023-08-08 16:17:36,581 [WARNI] logger.py: 102 [0]Did not find generator checkpoint in: outputs/generators/dummy/pixelation8/checkpoints
2023-08-08 16:17:36,581 [INFO ] logger.py: 102 [0]Loaded generator from: configs/generators/dummy/pixelation8.py
0it [00:00, ?it/s]2023-08-08 16:17:36,583 [WARNI] logger.py: 102 [0]Overwriting previous file: output_folder/6bf7136b-ef24-4502-a3a9-411c5f48f675.jpeg
2023-08-08 16:17:36,870 [WARNI] warnings.py: 109 /home/kameel/anaconda3/lib/python3.9/site-packages/torch/functional.py:445: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:2157.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
Calling face detector.
Saved to: output_folder/6bf7136b-ef24-4502-a3a9-411c5f48f675.jpeg
1it [00:02, 2.60s/it]2023-08-08 16:17:39,180 [WARNI] logger.py: 102 [0]Overwriting previous file: output_folder/308cefc8-0b9c-498b-8628-91f4eedd1a00.jpeg
Calling face detector.
Saved to: output_folder/308cefc8-0b9c-498b-8628-91f4eedd1a00.jpeg
2it [00:04, 2.18s/it]2023-08-08 16:17:41,076 [WARNI] logger.py: 102 [0]Overwriting previous file: output_folder/35612501-928a-4aff-b9e4-52a23ea2b0cf.jpeg
Calling face detector.
Saved to: output_folder/35612501-928a-4aff-b9e4-52a23ea2b0cf.jpeg
3it [00:07, 2.49s/it]2023-08-08 16:17:43,930 [WARNI] logger.py: 102 [0]Overwriting previous file: output_folder/MicrosoftTeams-image.jpeg
Calling face detector.
Saved to: output_folder/MicrosoftTeams-image.jpeg
4it [00:09, 2.44s/it]2023-08-08 16:17:46,295 [WARNI] logger.py: 102 [0]Overwriting previous file: output_folder/5d852367-5ce2-4d50-a26e-39b28882d461.jpeg
Calling face detector.
Saved to: output_folder/5d852367-5ce2-4d50-a26e-39b28882d461.jpeg
5it [00:11, 2.27s/it]2023-08-08 16:17:48,250 [WARNI] logger.py: 102 [0]Overwriting previous file: output_folder/8c9f098d-4c6d-4fa2-9109-acd01c493a14.jpeg
Calling face detector.
Saved to: output_folder/8c9f098d-4c6d-4fa2-9109-acd01c493a14.jpeg
6it [00:14, 2.38s/it]2023-08-08 16:17:50,861 [WARNI] logger.py: 102 [0]Overwriting previous file: output_folder/201a0885-b35c-4274-b9fe-025b29bb411a.jpeg
Calling face detector.
6it [00:16, 2.69s/it]
Traceback (most recent call last):
File "/home/kameel/Repos/deep_privacy2/anonymize.py", line 255, in <module>
anonymize_path()
File "/home/kameel/anaconda3/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "/home/kameel/anaconda3/lib/python3.9/site-packages/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/home/kameel/anaconda3/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/kameel/anaconda3/lib/python3.9/site-packages/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/home/kameel/Repos/deep_privacy2/anonymize.py", line 248, in anonymize_path
anonymize_directory(input_path, output_path, **kwargs)
File "/home/kameel/Repos/deep_privacy2/anonymize.py", line 149, in anonymize_directory
anonymize_file(childpath, output_path, **kwargs)
File "/home/kameel/Repos/deep_privacy2/anonymize.py", line 134, in anonymize_file
anonymize_image(input_path, output_path, **kwargs)
File "/home/kameel/Repos/deep_privacy2/anonymize.py", line 113, in anonymize_image
im_ = anonymizer(im, **synthesis_kwargs)
File "/home/kameel/Repos/deep_privacy2/dp2/anonymizer/anonymizer.py", line 162, in __call__
return self.forward(*args, **kwargs)
File "/home/kameel/anaconda3/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "/home/kameel/Repos/deep_privacy2/dp2/anonymizer/anonymizer.py", line 137, in forward
all_detections = self.detector(im)
File "/home/kameel/Repos/deep_privacy2/dp2/detection/cse_mask_face_detector.py", line 53, in __call__
return self.forward(*args, **kwargs)
File "/home/kameel/anaconda3/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "/home/kameel/Repos/deep_privacy2/dp2/detection/cse_mask_face_detector.py", line 84, in forward
face_boxes = self._detect_faces(im).cpu()
File "/home/kameel/Repos/deep_privacy2/dp2/detection/cse_mask_face_detector.py", line 59, in _detect_faces
boxes_XYXY = self.face_detector._batched_detect(im)[0][:, :-1] # Remove score
File "/home/kameel/anaconda3/lib/python3.9/site-packages/face_detection/base.py", line 126, in _batched_detect
boxes = self._detect(image)
File "/home/kameel/anaconda3/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "/home/kameel/anaconda3/lib/python3.9/site-packages/face_detection/dsfd/detect.py", line 40, in _detect
boxes = self.net(
File "/home/kameel/anaconda3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "/home/kameel/anaconda3/lib/python3.9/site-packages/face_detection/dsfd/face_ssd.py", line 166, in forward
self.cpm3_3(conv3_3_x),
File "/home/kameel/anaconda3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "/home/kameel/anaconda3/lib/python3.9/site-packages/face_detection/dsfd/face_ssd.py", line 26, in forward
return torch.cat([x1_1, x2_1, x3_1], dim=1)
RuntimeError: CUDA out of memory. Tried to allocate 1.04 GiB (GPU 0; 7.79 GiB total capacity; 4.38 GiB already allocated; 681.56 MiB free; 5.77 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF
Running Nvidia-smi:
Tue Aug 8 16:20:10 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.86.10 Driver Version: 535.86.10 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA GeForce RTX 2080 ... On | 00000000:01:00.0 On | N/A |
| N/A 55C P8 12W / 80W | 116MiB / 8192MiB | 10% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| 0 N/A N/A 3494 G /usr/lib/xorg/Xorg 30MiB |
| 0 N/A N/A 7164 G /usr/lib/xorg/Xorg 83MiB |
+---------------------------------------------------------------------------------------+
With following CUDA Version:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0
Your GPU is running out of memory when running the face detector. Either you could specify the max resolution that DeepPrivacy operates at (e.g. include `--max-res 1920' when running anonymize.py). This will resize the image and output a lower resolution image.
Or you could set the 'max_resolution` argument when building the face detector. That is replace the following line here from
self.face_detector = build_face_detector(**face_detector_cfg, confidence_threshold=score_threshold)
to:
self.face_detector = build_face_detector(**face_detector_cfg, confidence_threshold=score_threshold, max_resolution=1920)
Is there a way to mask the full body with a black silhouette? Kind of like the --vd option without the transparency and frame.