I am trying to use Pytorch-MTCNN with multiple camera
My setup is 2 webcams and 1 RTSP camera even though each process is just using 800Mbs of GPU Memory, the FPS is dropping drastically from 30 FPS using one camera to 20 when using two to 8-10 when using three video streams.
Specs
CPU - Intel i7 9th gen 12 cores
GPU - RTX 2070 8 GB
RAM - 16 GB
SSD - 512 GB
HDD - 1 TB
Here’s the screenshot of nvidia-smi
from facenet_pytorch import MTCNN, InceptionResnetV1
import torch
import os
import cv2
import time
#workers = 0 if os.name == 'nt' else 4
os.environ['DISPLAY'] = ':0'
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
print('Running on device: {}'.format(device))
mtcnn = MTCNN(
image_size=160, margin=30, min_face_size=50,
thresholds=[0.6, 0.7, 0.7], factor=0.709, post_process=True,
device=device)
#cap = cv2.VideoCapture('rtsp://admin:incerno123@192.168.1.36:554/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif')
#cap = cv2.VideoCapture('rtsp://admin:123456@192.168.1.10:554/H264?ch=1&subtype=0&proto=Onvif')
cap = cv2.VideoCapture(0)
while(True):
start_fps = time.time()
# Capture frame(-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
#img = Image.fromarray(img)
boxes, probs, landmarks = mtcnn.detect(img, landmarks=True)
if boxes is not None:
for (j,i,k) in zip(probs,boxes,landmarks):
if j>=0.55:
xmin,ymin,xmax,ymax = i
#print(xmin,ymin,xmax,ymax)
img = cv2.rectangle( img , (xmin, ymin) , (xmax, ymax) , (0,255,0) , 2 )
# Display the resulting frame
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
img = cv2.resize(img , (1280, 1080))
cv2.imshow('frame',img)
#cv2.imshow('face',img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
end_fps = time.time()
print(1/(end_fps-start_fps))
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()