나는 얼굴 인식, 얼굴 인식 (facetet 기반), 연령/성별 감지 및 얼굴 표현 분석과 관련된 프로젝트를 진행 중입니다. 언급 한 각 기능에 대해 잘 작동하는 텐서 흐름 그래프가 하나 있습니다. 이제 모든 것을 단일 코드로 결합해야합니다. 내 접근 방식은 다음과 같습니다 :tensorflow에서 그래프 간 전환
with tf.Graph().as_default():
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options, log_device_placement=False))
with sess.as_default():
#configure my camera
video_capture = cv2.VideoCapture(0)
while True:
#read one frame from camera
ret, frame = video_capture.read()
#here I load face recognition graph using saver restore
facenet.load_model(modeldir)
images_placeholder tf.get_default_graph().get_tensor_by_name("input:0")
embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0")
#Here I reset the graph and load another tensorflow graph for age/gender detection
tf.reset_default_graph()
....
#Here I reset the graph and load another tensorflow graph for face expression analysis
tf.reset_default_graph()
.....
이제는 코드가 효율적이지 않고 매우 느립니다. 그 이유는 비디오의 각 프레임에 대해 내 디스크에서 여러 그래프를로드 (복원)해야하기 때문입니다 (잠시 동안). 그러나, 모든 그래프를 한 번로드하기 전에 (전에), 런타임을 줄이기 위해 while 루프에서 그래프를 전환하고 싶습니다. 당신은, GPU를 사용하여 GPU 메모리 할당에주의하십시오
graph_face_detection = tf.Graph()
sess_face_detection = tf.Session(graph=graph_face_detection)
graph_face_recognition = tf.Graph()
sess_face_recognition = tf.Session(graph=graph_face_recognition)
...
sess_face_detection.run(operations)
...
sess_face_recognition.run(operations)
: 나는 당신의 의견
감사합니다. 이 코드를 "softmax_output = tf.nn.softmax (logits)"코드에 추가한다고 가정합니다. 어떤 세션과 그래프에 속하는지 궁금합니다. 위의 세션/그래프 중 하나에 시스템을 추가하도록 강제 할 수 있습니까? – user2867237
한 번 더 질문 : 모든 그래프를 단 1 세션에 추가 할 수 있습니까? 아니면 각 그래프에 대해 하나의 세션을 만들어야합니까? 감사합니다. – user2867237
@ user2867237 내 대답을 편집합니다. – Sraw