hukkelas / dsfd-pytorch-inference Goto Github PK
View Code? Open in Web Editor NEWA High-Performance Pytorch Implementation of face detection models, including RetinaFace and DSFD
License: Apache License 2.0
A High-Performance Pytorch Implementation of face detection models, including RetinaFace and DSFD
License: Apache License 2.0
Hi,
Thank you for the rewrite and very intuitive repo.
Have you reported validation accuracy for the RetinaNet Resnet50 and mobilenet? Or are they exactly the same as reported in here: https://github.com/biubug6/Pytorch_Retinaface#widerface-val-performance-in-single-scale-when-using-resnet50-as-backbone-net ?
Thanks,
Johannes
I have 4 gpus, I try to use gpu 1,2,3 other than 0:
face_detection.build_detector('RetinaNetMobileNetV1', device=torch.device('cuda:1') )
But it still consumes some memory on gpu-0. I guess some part of the model still runs on gpu-0.
By default, the code is running on GPU and causing this error RuntimeError: CUDA out of memory. Tried to allocate 90.00 MiB (GPU 0; 2.00 GiB total capacity; 941.01 MiB already allocated; 43.44 MiB free; 1.14 GiB reserved in total by PyTorch)
. Is it possible to change it to run on CPU
import cv2
import face_detection
detector = face_detection.build_detector(
"DSFDDetector", confidence_threshold=.5, nms_iou_threshold=.3)
for im in imgs:
detector.detect(im)
save...
I am using one GPU(V100 32G) to detect these imgs. At first, it used about 7800M VRAM then later it stabilize at 28100M but the speed gets much slower.
It was very fast at the beginning altho it spends some time for startup. It was like 200 imgs processed in 2min or 3min? Now it takes 10-20s to process one. All images are almost same size.
What's wrong with my code above? Any tips on process large amount of images?
img shape (1800, 2880, 3)
n_anchors += x[0] * x[1] * len(min_sizes[0])
Traceback (most recent call last):
File "test.py", line 29, in face_detect
boxes = detector.detect(img)
File "/lib/python3.8/site-packages/face_detection/base.py", line 56, in detect
boxes = self.batched_detect(image, shrink)
File "/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "/lib/python3.8/site-packages/face_detection/base.py", line 146, in batched_detect
boxes = self._batched_detect(image)
File "/lib/python3.8/site-packages/face_detection/base.py", line 126, in _batched_detect
boxes = self._detect(image)
File "/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "/lib/python3.8/site-packages/face_detection/retinaface/detect.py", line 120, in _detect
priors = priorbox.forward()
File "/lib/python3.8/site-packages/face_detection/retinaface/prior_box.py", line 43, in forward
anchors = generate_prior_box(
File "/lib/python3.8/site-packages/face_detection/retinaface/prior_box.py", line 26, in generate_prior_box
anchors[idx_anchor:idx_anchor+4] = [cx, cy, s_kx, s_ky]
ValueError: could not broadcast input array from shape (4,) into shape (0,)
Hi,
after pip installation of your module I have a problem with importing face_detection and build detector. The error is:
detector = face_detection.build_detector("RetinaNetResNet50", confidence_threshold=.5, nms_iou_threshold=.3)
AttributeError: module 'face_detection' has no attribute 'build_detector'
The call is written
import face_detection
detector = face_detection.build_detector("RetinaNetResNet50", confidence_threshold=.5, nms_iou_threshold=.3)
Thanks.
Hi all,
I encounter the following error while doing inference on video and it is likely to happen when I down-scale the frame. Do you know how should I fixed it ?
~\DSFD-Pytorch-Inference\dsfd\detect.py in detect_face(self, image, confidence_threshold, shrink)
41
42 with torch.no_grad():
---> 43 y = self.net(x, confidence_threshold, self.nms_iou_threshold)
44
45 detections = y.data.cpu().numpy()
~\Anaconda3\envs\py36\lib\site-packages\torch\nn\modules\module.py in call(self, *input, **kwargs)
545 result = self._slow_forward(*input, **kwargs)
546 else:
--> 547 result = self.forward(*input, **kwargs)
548 for hook in self._forward_hooks.values():
549 hook_result = hook(self, input, result)
\DSFD-Pytorch-Inference\dsfd\face_ssd.py in forward(self, x, confidence_threshold, nms_threshold)
191 self.priors,
192 confidence_threshold,
--> 193 nms_threshold
194 )
195 return output
~\DSFD-Pytorch-Inference\dsfd\utils.py in forward(self, loc_data, conf_data, prior_data, confidence_threshold, nms_threshold)
65 if conf_scores.dim() == 0:
66 final_ouput.append(torch.empty(0, 5))
---> 67 keep_idx = nms(decoded_boxes, conf_scores, nms_threshold)
68
69 scores = conf_scores[keep_idx].view(1, -1, 1)
~\Anaconda3\envs\py36\lib\site-packages\torchvision\ops\boxes.py in nms(boxes, scores, iou_threshold)
31 """
32 _C = _lazy_import()
---> 33 return _C.nms(boxes, scores, iou_threshold)
34
35
RuntimeError: too many indices for tensor of dimension 0 (got 1) (index at ..\aten\src\ATen\native\Indexing.cpp:235)
(no backtrace available)
Hi, I'm trying to create a detector using the same code as mentioned in readme. I'm trying to do this in google colab but I'm receiving a HTTP 308 and not able to find out why is that. Can any one help me with this please?
My code:
import face_detection
print(face_detection.available_detectors) # This is working fine
detector = face_detection.build_detector("DSFDDetector", confidence_threshold=.5, nms_iou_threshold=.3) # throws HTTP 308 error
Hi,
I am currently using the DSFDDetector on thousands of images.
This is working well for a few images but after 1k or 2k images the script stopped without any bug or any errors.
I know that the script is not finished because I do not see my ending prints.
Just to be clear, I am also running the exact same script with the RetinaNetResNet50 detector and it is working perfectly.
I am working on a GCP VM in Debian 9. Python3.7.6, torch==1.2.0, face-detection==0.1.4
Currently I am using a Tesla P100 GPU for the inferences.
Has somebody ever encountered a similar issue ?
Hi,
since your latest commit and the removal of torch from the setup.py I get an error message when trying to run pip install git+https://github.com/hukkelas/DSFD-Pytorch-Inference.git
which says that it cannot find torch:
ModuleNotFoundError: No module named 'torch'
What is the intention behind removing it from the setup.py?
the locations of the faces are correct, but the confidence is 3.x ?
how we can return the face-landmark from the detect method?
@hukkelas Looks like the URL of the DSFD checkpoint is not working. Getting HTTP Error 308: Permanent Redirect when I run this:
detector = face_detection.build_detector("DSFDDetector", confidence_threshold=.5, nms_iou_threshold=.3)
However "RetinaNetResNet50" and "RetinaNetMobileNetV1" are working fine.
Please check this issue and fix it. Thanks!
Hi,
I am always getting zeros as confidence values, as consequence I am not able to plot the Precision vs Recall curve.
5
829 270 920 374 0
565 346 582 372 0
493 342 514 371 0
677 353 687 367 0
457 352 466 362 0
Could you give me a hint about what could be happened ?
I encountered probem with DSFDDetector creation (rest of detectors work without any problem) .. Any idea for fixing problem?
detector = face_detection.build_detector("DSFDDetector",confidence_threshold=.5, nms_iou_threshold=.3)
raises error
FileNotFoundError Traceback (most recent call last)
in
----> 1 detector = face_detection.build_detector("DSFDDetector",confidence_threshold=.5, nms_iou_threshold=.3)
~\AppData\Local\r-miniconda\envs\aivision\lib\site-packages\face_detection\build.py in build_detector(name, confidence_threshold, nms_iou_threshold, device, max_resolution)
28 max_resolution=max_resolution
29 )
---> 30 detector = build_from_cfg(args, DETECTOR_REGISTRY)
31 return detector
~\AppData\Local\r-miniconda\envs\aivision\lib\site-packages\face_detection\registry.py in build_from_cfg(cfg, registry, **kwargs)
70 else:
71 raise TypeError('type must be a str or valid type, but got {}'.format(type(obj_type)))
---> 72 return obj_cls(**args, **kwargs)
~\AppData\Local\r-miniconda\envs\aivision\lib\site-packages\face_detection\dsfd\detect.py in init(self, *args, **kwargs)
21 model_url,
22 map_location=torch_utils.get_device(),
---> 23 progress=True)
24 self.net = SSD(resnet152_model_config)
25 self.net.load_state_dict(state_dict)
~\AppData\Local\r-miniconda\envs\aivision\lib\site-packages\torch\hub.py in load_state_dict_from_url(url, model_dir, map_location, progress, check_hash)
507 cached_file = os.path.join(model_dir, extraced_name)
508
--> 509 return torch.load(cached_file, map_location=map_location)
~\AppData\Local\r-miniconda\envs\aivision\lib\site-packages\torch\serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
582 pickle_load_args['encoding'] = 'utf-8'
583
--> 584 with _open_file_like(f, 'rb') as opened_file:
585 if _is_zipfile(opened_file):
586 with _open_zipfile_reader(f) as opened_zipfile:
~\AppData\Local\r-miniconda\envs\aivision\lib\site-packages\torch\serialization.py in _open_file_like(name_or_buffer, mode)
232 def _open_file_like(name_or_buffer, mode):
233 if _is_path(name_or_buffer):
--> 234 return _open_file(name_or_buffer, mode)
235 else:
236 if 'w' in mode:
~\AppData\Local\r-miniconda\envs\aivision\lib\site-packages\torch\serialization.py in init(self, name, mode)
213 class _open_file(_opener):
214 def init(self, name, mode):
--> 215 super(_open_file, self).init(open(name, mode))
216
217 def exit(self, *args):
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\remek/.cache\torch\checkpoints\'
Hi, how can I choose cpu or gpu id. Thanks
When I run build_detector, the pytorch .pth models were automatically saved in a default directory. How can I save in another directory, and then load model from that directory during model call?
Dear Håkon, first of all i want to thank you for providing this very useful and easy to use python module.
Next, i have a small suggestion how to improve the documentation / README.md:
please document the available options for build_detector(...). I had to look into the source code (ok, always a good idea) to figure out what the string for retina face is ("RetinaNetResNet50").
Would be nice if that would be placed upfront into the README.
Thanks again.
Hi,
I installed the great tool with 'pip install face_detection' ,but there is no parameters file in '.cache\torch\checkpoints'. I do not know why. Could you give me some helpful suggestions that what i should do,
best regards!
Thank you for the great code!
Is batch prediction possible (many images at once), any plans to add it? Do you think we can expect a speed up?
Thanks,
Zahar
Hi, during the inference of each model, the memory continuously increases with each image (only for single image inference). I have tried this on CPU as well as on GPU. Is there any way to solve this?
[TensorRT] ERROR: INVALID_ARGUMENT: Cannot deserialize with an empty memory buffer.
[TensorRT] ERROR: INVALID_CONFIG: Deserialize the cuda engine failed.
Traceback (most recent call last):
File "test_video.py", line 33, in
detector = TensorRTRetinaFace(input_imshape,inference_imshape)
File "/data/DSFD-Pytorch-Inference/face_detection/retinaface/tensorrt_wrap.py", line 38, in init
self.context = self.engine.create_execution_context()
AttributeError: 'NoneType' object has no attribute 'create_execution_context'
Seeing issues running inference using tensorrt. How to fix it.
Tensorrt version 7.1.3
Torch version - 1.4.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.