私は、顔検出、顔認識(顔面に基づく)、年齢/性別の検出、顔の表情解析を含むプロジェクトに取り組んでいます。上記の各機能について、うまく動作するテンソルフローグラフが1つあります。今、私はすべてを1つのコードで結合する必要があります。私のアプローチは以下の通りです:グラフをテンソルフローで切り替える
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つの質問:1つのセッションにすべてのグラフを追加することはできますか?または各グラフについて1つのセッションを作成する必要がありますか?ありがとう – user2867237
@ user2867237私は自分の答えを編集します。 – Sraw