未验证 提交 c8c51ac7 编写于 作者: G Guanghua Yu 提交者: GitHub

fix use cv2 in face_detection (#1034)

上级 fb650fbb
...@@ -98,10 +98,6 @@ EvalReader: ...@@ -98,10 +98,6 @@ EvalReader:
- !DecodeImage - !DecodeImage
to_rgb: true to_rgb: true
- !NormalizeBox {} - !NormalizeBox {}
- !ResizeImage
interp: 1
target_size: 640
use_cv2: false
- !Permute {} - !Permute {}
- !NormalizeImage - !NormalizeImage
is_scale: false is_scale: false
...@@ -111,7 +107,6 @@ EvalReader: ...@@ -111,7 +107,6 @@ EvalReader:
TestReader: TestReader:
inputs_def: inputs_def:
image_shape: [3,640,640]
fields: ['image', 'im_id', 'im_shape'] fields: ['image', 'im_id', 'im_shape']
dataset: dataset:
!ImageFolder !ImageFolder
...@@ -119,10 +114,6 @@ TestReader: ...@@ -119,10 +114,6 @@ TestReader:
sample_transforms: sample_transforms:
- !DecodeImage - !DecodeImage
to_rgb: true to_rgb: true
- !ResizeImage
interp: 1
target_size: 640
use_cv2: false
- !Permute {} - !Permute {}
- !NormalizeImage - !NormalizeImage
is_scale: false is_scale: false
......
...@@ -7,7 +7,7 @@ log_smooth_window: 20 ...@@ -7,7 +7,7 @@ log_smooth_window: 20
log_iter: 20 log_iter: 20
metric: WIDERFACE metric: WIDERFACE
save_dir: output save_dir: output
weights: output/blazeface_nas/model_final weights: output/blazeface_nas_v2/model_final
# 1(label_class) + 1(background) # 1(label_class) + 1(background)
num_classes: 2 num_classes: 2
...@@ -98,10 +98,6 @@ EvalReader: ...@@ -98,10 +98,6 @@ EvalReader:
- !DecodeImage - !DecodeImage
to_rgb: true to_rgb: true
- !NormalizeBox {} - !NormalizeBox {}
- !ResizeImage
interp: 1
target_size: 640
use_cv2: false
- !Permute {} - !Permute {}
- !NormalizeImage - !NormalizeImage
is_scale: false is_scale: false
...@@ -111,7 +107,6 @@ EvalReader: ...@@ -111,7 +107,6 @@ EvalReader:
TestReader: TestReader:
inputs_def: inputs_def:
image_shape: [3,640,640]
fields: ['image', 'im_id', 'im_shape'] fields: ['image', 'im_id', 'im_shape']
dataset: dataset:
!ImageFolder !ImageFolder
...@@ -119,10 +114,6 @@ TestReader: ...@@ -119,10 +114,6 @@ TestReader:
sample_transforms: sample_transforms:
- !DecodeImage - !DecodeImage
to_rgb: true to_rgb: true
- !ResizeImage
interp: 1
target_size: 640
use_cv2: false
- !Permute {} - !Permute {}
- !NormalizeImage - !NormalizeImage
is_scale: false is_scale: false
......
...@@ -25,7 +25,7 @@ if parent_path not in sys.path: ...@@ -25,7 +25,7 @@ if parent_path not in sys.path:
import paddle.fluid as fluid import paddle.fluid as fluid
import numpy as np import numpy as np
from PIL import Image import cv2
from collections import OrderedDict from collections import OrderedDict
import ppdet.utils.checkpoint as checkpoint import ppdet.utils.checkpoint as checkpoint
...@@ -81,9 +81,10 @@ def face_eval_run(exe, ...@@ -81,9 +81,10 @@ def face_eval_run(exe,
if eval_mode == 'fddb': if eval_mode == 'fddb':
image_path += '.jpg' image_path += '.jpg'
assert os.path.exists(image_path) assert os.path.exists(image_path)
image = Image.open(image_path).convert('RGB') image = cv2.imread(image_path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
if multi_scale: if multi_scale:
shrink, max_shrink = get_shrink(image.size[1], image.size[0]) shrink, max_shrink = get_shrink(image.shape[0], image.shape[1])
det0 = detect_face(exe, compile_program, fetches, image, shrink) det0 = detect_face(exe, compile_program, fetches, image, shrink)
det1 = flip_test(exe, compile_program, fetches, image, shrink) det1 = flip_test(exe, compile_program, fetches, image, shrink)
[det2, det3] = multi_scale_test(exe, compile_program, fetches, [det2, det3] = multi_scale_test(exe, compile_program, fetches,
...@@ -106,10 +107,10 @@ def face_eval_run(exe, ...@@ -106,10 +107,10 @@ def face_eval_run(exe,
def detect_face(exe, compile_program, fetches, image, shrink): def detect_face(exe, compile_program, fetches, image, shrink):
image_shape = [3, image.size[1], image.size[0]] image_shape = [3, image.shape[0], image.shape[1]]
if shrink != 1: if shrink != 1:
h, w = int(image_shape[1] * shrink), int(image_shape[2] * shrink) h, w = int(image_shape[1] * shrink), int(image_shape[2] * shrink)
image = image.resize((w, h), Image.ANTIALIAS) image = cv2.resize(image, (w, h))
image_shape = [3, h, w] image_shape = [3, h, w]
img = face_img_process(image) img = face_img_process(image)
...@@ -133,13 +134,13 @@ def detect_face(exe, compile_program, fetches, image, shrink): ...@@ -133,13 +134,13 @@ def detect_face(exe, compile_program, fetches, image, shrink):
def flip_test(exe, compile_program, fetches, image, shrink): def flip_test(exe, compile_program, fetches, image, shrink):
img = image.transpose(Image.FLIP_LEFT_RIGHT) img = cv2.flip(image, 1)
det_f = detect_face(exe, compile_program, fetches, img, shrink) det_f = detect_face(exe, compile_program, fetches, img, shrink)
det_t = np.zeros(det_f.shape) det_t = np.zeros(det_f.shape)
# image.size: [width, height] img_width = image.shape[1]
det_t[:, 0] = image.size[0] - det_f[:, 2] det_t[:, 0] = img_width - det_f[:, 2]
det_t[:, 1] = det_f[:, 1] det_t[:, 1] = det_f[:, 1]
det_t[:, 2] = image.size[0] - det_f[:, 0] det_t[:, 2] = img_width - det_f[:, 0]
det_t[:, 3] = det_f[:, 3] det_t[:, 3] = det_f[:, 3]
det_t[:, 4] = det_f[:, 4] det_t[:, 4] = det_f[:, 4]
return det_t return det_t
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册