Я пытаюсь обучить свой собственный набор данных, используя проект github CNN-Facial-Landmarks, и у меня есть мой собственный набор данных лица, помеченный ориентирами радужной оболочки,
У меня есть эти сценарии:
+ pts_tools.py
+ extract_face_from_ibug.py
https://github.com/yinguobing/image_utility
, который может извлекать точки из изображения и генерировать файлы .json
, который работает на 68 ориентирах и наборе данных ibug (300VW, 300W, Helen ...)
Я попытался изменить код в pts_tools.py и extract_face_from_ibug.py
Я изменил
assert len(raw_points)==68
до
assert len(raw_points)==10
Это некоторый код из pts_tools.py
def preview_json(json_file):
"""
Preview points on image.
"""
# Read the points from file.
with open(json_file, 'r') as f:
data = json.load(f)
raw_points = np.reshape(data, (-1, 2))
marks = raw_points * PREVIEW_FACE_SIZE
# Safe guard, make sure point importing goes well.
assert len(raw_points) == 10, "The landmarks should contain 68 points."
# Read the image.
_, tail = os.path.split(json_file)
image_file = tail.split('.')[-2]
img_jpg = os.path.join(IMAGE_DIR, image_file + ".jpg")
img = cv2.imread(img_jpg)
img = cv2.resize(img, (PREVIEW_FACE_SIZE, PREVIEW_FACE_SIZE))
# Fast check: all points are in image.
if points_are_valid(marks, img) is False:
return None
# Get the pose.
estimator = pe.PoseEstimator(
img_size=(PREVIEW_FACE_SIZE, PREVIEW_FACE_SIZE))
pose = estimator.solve_pose_by_68_points(marks)
# Uncomment the following line to draw the 3D model points.
# estimator.show_3d_model()
# Draw annotations.
estimator.draw_annotation_box(img, pose[0], pose[1])
estimator.draw_axis(img, pose[0], pose[1])
draw_landmark_point(img, marks)
# Solve the pitch, yaw and roll angels.
r_mat, _ = cv2.Rodrigues(pose[0])
p_mat = np.hstack((r_mat, np.array([[0], [0], [0]])))
_, _, _, _, _, _, u_angle = cv2.decomposeProjectionMatrix(p_mat)
pitch, yaw, roll = u_angle.flatten()
# I do not know why the roll axis seems flipted 180 degree. Manually by pass
# this issue.
if roll > 0:
roll = 180-roll
elif roll < 0:
roll = -(180 + roll)
# print("pitch: {:.2f}, yaw: {:.2f}, roll: {:.2f}".format(pitch, yaw, roll))
# Save the pose in json files.
pose = {
"pitch": pitch/180,
"yaw": yaw/180,
"roll": roll/180
}
pose_file_path = os.path.join(POSE_DIR, image_file + "-pose.json")
with open(pose_file_path, 'w') as fid:
json.dump(pose, fid)
# Show the face area and the whole image.
cv2.imshow("preview", img)
if cv2.waitKey(60) == 27:
exit()
Когда я выполняю pts_tools.py, я получаю это:
0it [00:00,? It / s]
и когда я выполняю extract_face_from_ibug.py, я получаю следующие ошибки:
Номера файлов PTS: 57
0% |
| 0/57 [00:00
Файл "extract_face_from_ibug.py", строка 146, в
Основной () * * тысяча тридцать-четыря
Файл "extract_face_from_ibug.py", строка 95, в
главный
points = pt.read_points (имя_файла)
Файл "C: \ Users \ starinfo \ cnn-facial-landmark \ pts_tools.py", строка 40, в> read_points
loc_x, loc_y = line.strip (). Split (sep = "")
ValueError: недостаточно значений для распаковки (ожидается 2, получено 1)
Как я могу решить эту ошибку?