如何使用图在张量流中连接两个神经网络?

时间:2019-06-18 19:53:23

标签: python tensorflow

我正在建立一个能够使用python和tensorflow识别人脸的系统。

我想认识两件事。

>未知人员的“人员”和已知人员的“人员名称”(以前在模型中训练标签)。

因此,我需要实现2个神经网络。

第一个将识别所有对象(例如椅子,桌子等)中的面孔, 第二个将使用面部对框架进行分类,并考虑模型的所有已知面部来检查标签。 (之前受过训练)

因此,为了解决类似问题,我知道我需要两个神经网络,第一个神经网络的输出将成为第二个神经网络的输入。但是我只是不知道如何使用图形文件连接这两个神经网络。 (在培训过程中创建)

现在,我可以训练我的模型,获取图形文件并将其用于识别过程。但是我无法混合两个神经网络,也无法将第一个模型的输出添加到第二个模型的输入中

with detection_graph.as_default():
    with tf.Session(graph=detection_graph) as sess:
        while True:

            # Read frame from camera
            ret, image_np = cap.read()
            # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
            image_np_expanded = np.expand_dims(image_np, axis=0)
            # Extract image tensor
            image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
            # Extract detection boxes
            boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
            # Extract detection scores
            scores = detection_graph.get_tensor_by_name('detection_scores:0')
            # Extract detection classes
            classes = detection_graph.get_tensor_by_name('detection_classes:0')
            # Extract number of detectionsd
            num_detections = detection_graph.get_tensor_by_name(
                'num_detections:0')
            # Actual detection.
            (boxes, scores, classes, num_detections) = sess.run(
                [boxes, scores, classes, num_detections],
                feed_dict={image_tensor: image_np_expanded})
            # Visualization of the results of a detection.
            vis_util.visualize_boxes_and_labels_on_image_array(
                image_np,
                np.squeeze(boxes),
                np.squeeze(classes).astype(np.int32),
                np.squeeze(scores),
                category_index,
                use_normalized_coordinates=True,
                line_thickness=8)

            # Display output
            cv2.imshow('object detection', cv2.resize(image_np, (800, 600)))

            if cv2.waitKey(25) & 0xFF == ord('q'):
                cv2.destroyAllWindows()
                break

detection_graph是模型(对内存中图形文件的引用)

前面的代码在一个模型(图形文件)上运行良好,但是我想集成第二个神经网络。 (将第一个的输出添加到第二个的输入中)。知道我该怎么做吗?

0 个答案:

没有答案