Added additional inference options
This commit is contained in:
parent
c77c82aee7
commit
f043ec6f2c
2 changed files with 13 additions and 2 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -11,3 +11,6 @@ filelists/*.txt
|
||||||
evaluation/test_filelists/lr*.txt
|
evaluation/test_filelists/lr*.txt
|
||||||
*.pyc
|
*.pyc
|
||||||
*.mkv
|
*.mkv
|
||||||
|
*.gif
|
||||||
|
*.webm
|
||||||
|
*.mp3
|
||||||
|
|
|
||||||
10
inference.py
10
inference.py
|
|
@ -35,13 +35,17 @@ parser.add_argument('--resize_factor', default=1, type=int,
|
||||||
help='Reduce the resolution by this factor. Sometimes, best results are obtained at 480p or 720p')
|
help='Reduce the resolution by this factor. Sometimes, best results are obtained at 480p or 720p')
|
||||||
|
|
||||||
parser.add_argument('--crop', nargs='+', type=int, default=[0, -1, 0, -1],
|
parser.add_argument('--crop', nargs='+', type=int, default=[0, -1, 0, -1],
|
||||||
help='Crop video to a smaller region (top, bottom, left, right). Applied after resize_factor arg. '
|
help='Crop video to a smaller region (top, bottom, left, right). Applied after resize_factor and rotate arg. '
|
||||||
'Useful if multiple face present. -1 implies the value will be auto-inferred based on height, width')
|
'Useful if multiple face present. -1 implies the value will be auto-inferred based on height, width')
|
||||||
|
|
||||||
parser.add_argument('--box', nargs='+', type=int, default=[-1, -1, -1, -1],
|
parser.add_argument('--box', nargs='+', type=int, default=[-1, -1, -1, -1],
|
||||||
help='Specify a constant bounding box for the face. Use only as a last resort if the face is not detected.'
|
help='Specify a constant bounding box for the face. Use only as a last resort if the face is not detected.'
|
||||||
'Also, might work only if the face is not moving around much. Syntax: (top, bottom, left, right).')
|
'Also, might work only if the face is not moving around much. Syntax: (top, bottom, left, right).')
|
||||||
|
|
||||||
|
parser.add_argument('--rotate', default=False, action='store_true',
|
||||||
|
help='Sometimes videos taken from a phone can be flipped 90deg. If true, will flip video right by 90deg.'
|
||||||
|
'Use if you get a flipped result, despite feeding a normal looking video')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
args.img_size = 96
|
args.img_size = 96
|
||||||
|
|
||||||
|
|
@ -80,6 +84,7 @@ def face_detect(images):
|
||||||
pady1, pady2, padx1, padx2 = args.pads
|
pady1, pady2, padx1, padx2 = args.pads
|
||||||
for rect, image in zip(predictions, images):
|
for rect, image in zip(predictions, images):
|
||||||
if rect is None:
|
if rect is None:
|
||||||
|
cv2.imwrite('temp/faulty_frame.jpg', image) # check this frame where the face was not detected.
|
||||||
raise ValueError('Face not detected! Ensure the video contains a face in all the frames.')
|
raise ValueError('Face not detected! Ensure the video contains a face in all the frames.')
|
||||||
|
|
||||||
y1 = max(0, rect[1] - pady1)
|
y1 = max(0, rect[1] - pady1)
|
||||||
|
|
@ -193,6 +198,9 @@ def main():
|
||||||
if args.resize_factor > 1:
|
if args.resize_factor > 1:
|
||||||
frame = cv2.resize(frame, (frame.shape[1]//args.resize_factor, frame.shape[0]//args.resize_factor))
|
frame = cv2.resize(frame, (frame.shape[1]//args.resize_factor, frame.shape[0]//args.resize_factor))
|
||||||
|
|
||||||
|
if args.rotate:
|
||||||
|
frame = cv2.rotate(frame, cv2.cv2.ROTATE_90_CLOCKWISE)
|
||||||
|
|
||||||
y1, y2, x1, x2 = args.crop
|
y1, y2, x1, x2 = args.crop
|
||||||
if x2 == -1: x2 = frame.shape[1]
|
if x2 == -1: x2 = frame.shape[1]
|
||||||
if y2 == -1: y2 = frame.shape[0]
|
if y2 == -1: y2 = frame.shape[0]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue