0
我正在研究一個涉及人臉檢測,人臉識別(基於facenet),年齡/性別檢測和人臉表情分析的項目。對於每個提到的功能,我有一個正常工作的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中)。但是,我想一次加載所有圖形(在while之前),只需在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