Python:我在Windows 10中为我的面部识别程序运行训练器时收到错误,但它在ubuntu 20.04上有效

问题描述 投票:0回答:1

我想在我的[[面部识别程序中使用培训,但收到错误,我尝试了所有操作,但即使在相同的设置下,也无法在该项目中找到解决方案在ubuntu 20.04上它对我有用,但是当我迁移到windows 10时,我保留了相同的设置(库),但出现了错误。

另一个使用

cnn

hog支持的项目与ubuntu 20.04和Windows 10上的dlibface-recognitionopencv配合得很好。不知道为什么在此项目中它无法在Windows 10中运行。

versions:

os == windows 10 python == 3.6 onnx==1.6.0 onnx-tf==1.3.0 onnxruntime==0.5.0 opencv-python==4.1.1.26 tensorflow==1.13.1 dlib==19.19.0

脚本(trainer.py):

import cv2 import numpy as np import onnx import onnxruntime as ort from onnx_tf.backend import prepare import os import dlib from imutils import face_utils import tensorflow as tf import pickle def area_of(left_top,right_bottom): hw = np.clip(right_bottom-left_top,0.0,None) return hw[...,0]*hw[...,1] def iou_of(boxes0,boxes1,eps=1e-5): overlap_left_top = np.maximum(boxes0[..., :2], boxes1[..., :2]) overlap_right_bottom = np.minimum(boxes0[..., 2:], boxes1[..., 2:]) overlap_area = area_of(overlap_left_top, overlap_right_bottom) area0 = area_of(boxes0[..., :2], boxes0[..., 2:]) area1 = area_of(boxes1[..., :2], boxes1[..., 2:]) return overlap_area / (area0 + area1 - overlap_area + eps) def hard_nms(box_scores,iou_threshold,top_k=-1,candidate_size=200): scores = box_scores[:, -1] boxes = box_scores[:, :-1] picked = [] indexes = np.argsort(scores) indexes = indexes[-candidate_size:] while len(indexes) > 0: current = indexes[-1] picked.append(current) if 0 < top_k == len(picked) or len(indexes) == 1: break current_box = boxes[current, :] indexes = indexes[:-1] rest_boxes = boxes[indexes, :] ##Return intersection-over-union (Jaccard index) of boxes. iou = iou_of( rest_boxes, np.expand_dims(current_box, axis=0), ) indexes = indexes[iou <= iou_threshold] return box_scores[picked, :] def predict(width, height, confidences, boxes, prob_threshold, iou_threshold=0.5, top_k=-1): boxes = boxes[0] confidences = confidences[0] picked_box_probs = [] picked_labels = [] for class_index in range(1, confidences.shape[1]): probs = confidences[:, class_index] mask = probs > prob_threshold probs = probs[mask] if probs.shape[0] == 0: continue subset_boxes = boxes[mask, :] #joignez une séquence de tableaux le long d'un axe existant. #numpy.reshape(ligne,colonne):Donne une nouvelle forme à un tableau sans modifier ses données. box_probs = np.concatenate([subset_boxes, probs.reshape(-1, 1)], axis=1) # Perform hard non-maximum-supression to filter out boxes with iou greater than threshold box_probs = hard_nms(box_probs, iou_threshold=iou_threshold, top_k=top_k, ) picked_box_probs.append(box_probs) picked_labels.extend([class_index] * box_probs.shape[0]) if not picked_box_probs: return np.array([]), np.array([]), np.array([]) picked_box_probs = np.concatenate(picked_box_probs) picked_box_probs[:, 0] *= width picked_box_probs[:, 1] *= height picked_box_probs[:, 2] *= width picked_box_probs[:, 3] *= height return picked_box_probs[:, :4].astype(np.int32), np.array(picked_labels), picked_box_probs[:, 4] onnx_path = 'ultra_light_640.onnx' onnx_model = onnx.load(onnx_path) predictor = prepare(onnx_model) ort_session = ort.InferenceSession(onnx_path) input_name = ort_session.get_inputs()[0].name fa = face_utils.facealigner.FaceAligner(shape_predictor, desiredFaceWidth=112, desiredLeftEye=(0.3, 0.3)) TRAINING_BASE = 'faces/training/' dirs = os.listdir(TRAINING_BASE) # images and names for later use images = [] names = [] for label in dirs: for i, fn in enumerate(os.listdir(os.path.join(TRAINING_BASE, label))): print(f"start collecting faces from {label}'s data") cap = cv2.VideoCapture(os.path.join(TRAINING_BASE, label, fn)) frame_count = 0 while True: # read video frame ret, raw_img = cap.read() if frame_count % 5 == 0 and raw_img is not None: # size photo h, w, _ = raw_img.shape # conversion d'espace colorimétrique. img = cv2.cvtColor(raw_img, cv2.COLOR_BGR2RGB) # Redimmensionner une image img = cv2.resize(img, (640, 480)) img_mean = np.array([127, 127, 127]) img = (img - img_mean) / 128 img = np.transpose(img, [2, 0, 1]) img = np.expand_dims(img, axis=0) img = img.astype(np.float32) confidences, boxes = ort_session.run(None, {input_name: img}) boxes, labels, probs = predict(w, h, confidences, boxes, 0.7) if boxes.shape[0] > 0: x1, y1, x2, y2 = boxes[0, :] gray = cv2.cvtColor(raw_img, cv2.COLOR_BGR2GRAY) aligned_face = fa.align(raw_img, gray, dlib.rectangle(left=int(x1), top=int(y1), right=int(x2), bottom=int(y2))) aligned_face = cv2.resize(aligned_face, (112, 112)) cv2.imwrite(f'faces/tmp/{label}_{frame_count}.jpg', aligned_face) aligned_face = aligned_face - 127.5 aligned_face = aligned_face * 0.0078125 images.append(aligned_face) names.append(label) frame_count += 1 # if video end if frame_count == cap.get(cv2.CAP_PROP_FRAME_COUNT): break with tf.Graph().as_default(): with tf.Session() as sess: print("loading checkpoint ...") saver = tf.train.import_meta_graph('models/mfn/m1/mfn.ckpt.meta') saver.restore(sess, 'models/mfn/m1/mfn.ckpt') images_placeholder = tf.get_default_graph().get_tensor_by_name("input:0") embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0") phase_train_placeholder = tf.get_default_graph().get_tensor_by_name("phase_train:0") embedding_size = embeddings.get_shape()[1] feed_dict = {images_placeholder: images, phase_train_placeholder: False} embeds = sess.run(embeddings, feed_dict=feed_dict) print("saving embeddings") with open("embeddings/embeddings.pkl", "wb") as f: pickle.dump((embeds, names), f) print("Done !")'''

错误消息:

G:\PROJET\PYTHON\FACE_RECOGNITION\Real_time_face_recognition_with_CPU\venv\Scripts\python.exe G:/PROJET/PYTHON/FACE_RECOGNITION/Real_time_face_recognition_with_CPU/trainer.py G:\PROJET\PYTHON\FACE_RECOGNITION\Real_time_face_recognition_with_CPU\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint8 = np.dtype([("qint8", np.int8, 1)]) G:\PROJET\PYTHON\FACE_RECOGNITION\Real_time_face_recognition_with_CPU\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint8 = np.dtype([("quint8", np.uint8, 1)]) G:\PROJET\PYTHON\FACE_RECOGNITION\Real_time_face_recognition_with_CPU\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint16 = np.dtype([("qint16", np.int16, 1)]) G:\PROJET\PYTHON\FACE_RECOGNITION\Real_time_face_recognition_with_CPU\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint16 = np.dtype([("quint16", np.uint16, 1)]) G:\PROJET\PYTHON\FACE_RECOGNITION\Real_time_face_recognition_with_CPU\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint32 = np.dtype([("qint32", np.int32, 1)]) G:\PROJET\PYTHON\FACE_RECOGNITION\Real_time_face_recognition_with_CPU\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. np_resource = np.dtype([("resource", np.ubyte, 1)]) G:\PROJET\PYTHON\FACE_RECOGNITION\Real_time_face_recognition_with_CPU\venv\lib\site-packages\onnx_tf\common\__init__.py:87: UserWarning: onnx_tf.common.get_outputs_names is deprecated. It will be removed in future release. Use TensorflowGraph.get_outputs_names instead. warnings.warn(message) WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0. For more information, please see: * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md * https://github.com/tensorflow/addons If you depend on functionality not listed there, please file an issue. G:\PROJET\PYTHON\FACE_RECOGNITION\Real_time_face_recognition_with_CPU\venv\lib\site-packages\onnx_tf\common\handler_helper.py:37: UserWarning: Unknown op ConstantFill in domain `ai.onnx`. handler.ONNX_OP, handler.DOMAIN or "ai.onnx")) G:\PROJET\PYTHON\FACE_RECOGNITION\Real_time_face_recognition_with_CPU\venv\lib\site-packages\onnx_tf\common\handler_helper.py:37: UserWarning: Unknown op ImageScaler in domain `ai.onnx`. handler.ONNX_OP, handler.DOMAIN or "ai.onnx")) Process finished with exit code -1073741819 (0xC0000005)
tensorflow python-3.6 dlib onnx onnxruntime
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.