GazeML
GazeML copied to clipboard
Lag on runing realtime
hello, How can I fix the lag when running realtime on webcam, I implement it by GPU and cuda10 & Cudnn, but it has a periodic lag that I think its because of the program problem, thanks to anyone can help me
I also got exactly the same problem, when I test on video. However, I saved result afterward, I can check it later. Have you tried --from_video, too?
I also got exactly the same problem, when I test on video. However, I saved result afterward, I can check it later. Have you tried --from_video, too?
No, actually my need is running realtime
Have you try to adjust "--fps" ? or what kind of lag is it? Does it lag in certain pattern, like after every 60 frames will lag? Author did a batch result during inference. Maybe this is the reason. You can edit the code without batch output.
Have you try to adjust "--fps" ? or what kind of lag is it? Does it lag in certain pattern, like after every 60 frames will lag? Author did a batch result during inference. Maybe this is the reason. You can edit the code without batch output.
I tried "--fps" but didn't work, yeah it lags in a certain pattern but I don't know how can I disable the batch output.
could u help me with that?!
@meysam97 Currently, haven't got time to look into this. If you have already solved, please share with us. Thank you.
You can adjust the input image resolution in Webcam class
class Webcam(FramesSource): """Webcam frame grabbing and preprocessing."""
def __init__(self, camera_id=0, fps=60, w=1280, h=720, **kwargs):
"""Create queues and threads to read and preprocess data."""
self._short_name = 'Webcam'
self._capture = cv.VideoCapture(camera_id)
self._capture.set(cv.CAP_PROP_FRAME_WIDTH, w)
self._capture.set(cv.CAP_PROP_FRAME_HEIGHT, h)
self._capture.set(cv.CAP_PROP_FOURCC, cv.VideoWriter_fourcc(*'MJPG'))
self._capture.set(cv.CAP_PROP_FPS, fps)
or use another face detection to replace dlib
That's a good point.
You could try compiling dlib manually instead of using the pip installed version: http://dlib.net/compile.html
I recall that I was using such a version of the library.
On Thu, 5 Sep 2019, 05:05 LZJ, [email protected] wrote:
You can adjust the input image resolution in Webcam class
class Webcam(FramesSource): """Webcam frame grabbing and preprocessing."""
def init(self, camera_id=0, fps=60, w=1280, h=720, **kwargs): """Create queues and threads to read and preprocess data.""" self._short_name = 'Webcam'
self._capture = cv.VideoCapture(camera_id) self._capture.set(cv.CAP_PROP_FRAME_WIDTH, w) self._capture.set(cv.CAP_PROP_FRAME_HEIGHT, h) self._capture.set(cv.CAP_PROP_FOURCC, cv.VideoWriter_fourcc(*'MJPG')) self._capture.set(cv.CAP_PROP_FPS, fps)
or use another face detection to replace dlib
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/swook/GazeML/issues/38?email_source=notifications&email_token=AAFYRUSTCQHL6C5UJOMTRG3QIBZPHA5CNFSM4IIORIUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD55VMMQ#issuecomment-528176690, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFYRUWIGYW52E56SFMVZ4LQIBZPHANCNFSM4IIORIUA .
The lag still persists. The lag actually happens in multiples of 60 frames. Is this lag related to the batch inference?
You can comment these lines of _record_frame()
function, it will solve the problem:
#now_time = time.time()
#if last_frame_time is not None:
# time_diff = now_time - last_frame_time
# while time_diff > 0.0:
# video_out.write(frame)
# time_diff -= out_frame_interval
#last_frame_time = now_time
@hoangthang1607 Didn't help for me
I am getting the same issue. Did anyone of you people find a solution to it? Commenting the lines mentioned by @hoangthang1607 didn't work for me.
For me, reducing the resolution helped, just as @gy29289957 said.
Other option is to keep the same resolution, but decrease fps. Unfortunately, --fps
option doesn't work for me. I don't know if it falis in general, or it's just specific to my webcam. I ended up using this stupid hack:
def frame_generator(self):
"""Read frame from webcam."""
while True:
ret, bgr = self._capture.read()
ret, bgr = self._capture.read()
if ret:
yield bgr
Which isn't elegant but was enough for me. The duplicated self._capture.read()
causes frame_generator
to skip every other frame, which in practice gives 30fps.
I managed to solve my problem as well. I built dlib from source with cuda enabled and managed to eliminate the bottleneck and got steady 23 fps. I then downloaded the tensorflow-gpu instead of the cpu version and managed to boost the speed up to steady 30 fps.
I, too, have to problem with a powerful PC, Ubuntu 20.04, tf 1.14, CUDA 11.
It sometimes gets a weird lag peak even though mostly it's running with nice stable 30fps. Maybe the program is doing some heavy operations such as copying stuff to queue, moving them in memory or saving things on disk.