.Append error method successfully resolved IndexError: list index out of range
table of Contents
Solve the problem
.append method error IndexError: list index out of range
Solution
X.append(fr.face_encodings(image,known_face_locations=boxes)[0])
print(fr.face_encodings(image,known_face_locations=boxes)),
I found a list fr.face_encodings pictures output (image, known_face_locations = boxes) for [] Jishi Kong, it appeared list index out of range,
T1, you can just delete that picture!
T2, rewrite function increased determination, if the current value of the list is empty, the loop out of the loop execution time
for img_path in image_files_in_folder(os.path.join(train_dir, class_dir)):
image = fr.load_image_file(img_path)
boxes = fr.face_locations(image)
print(img_path)
# print(fr.face_encodings(image,known_face_locations=boxes))
if len(fr.face_encodings(image,known_face_locations=boxes))==0: #判断空列表
print("这张图片不合法,请删除!即将退出程序",img_path)
continue
# sys.exit()
# 对于当前图片,增加编码到训练集,返回128个值放到X集合里(X.append)
X.append(fr.face_encodings(image,known_face_locations=boxes)[0])