在tensorflow训练中,每组训练速度越来越慢,时长越来越高、从运行日志中可以看到:每个视频花费时间从9s到165s、到207s。这样每组数据有81个视频、导致每组数据训练时长从12分钟变到3小时变到4小时(一开始只需要十几分钟)~~虽然还差几组数据就训练完了,但这速度这简直不能忍
#·····································运行日志1····································#
100%|##################################################################################| 81/81 [12:56<00:00, 9.59s/it]
Predicting on frame of L:\collect_program\sign_language\sign-language-gesture-recognition-master\dataset\frames\train-frames\s10-Enemy
100%|##################################################################################| 81/81 [13:54<00:00, 10.30s/it]
Predicting on frame of L:\collect_program\sign_language\sign-language-gesture-recognition-master\dataset\frames\train-frames\s11-Son
100%|##################################################################################| 81/81 [16:42<00:00, 12.38s/it]
Predicting on frame of L:\collect_program\sign_language\sign-language-gesture-recognition-master\dataset\frames\train-frames\s12-Man
~~~~~~~省略·~~~~~~
100%|###############################################################################| 81/81 [3:29:29<00:00, 155.18s/it]
Predicting on frame of s3-Green
100%|###############################################################################| 81/81 [3:43:52<00:00, 165.83s/it]
Predicting on frame of s30-Birthday
100%|###############################################################################| 81/81 [3:55:48<00:00, 174.67s/it]
Predicting on frame of s31-Breakfast
100%|###############################################################################| 81/81 [4:08:02<00:00, 183.74s/it]
Predicting on frame of s32-Photo
100%|###############################################################################| 81/81 [4:21:15<00:00, 193.53s/it]
Predicting on frame of s33-Hungry
100%|###############################################################################| 81/81 [4:39:47<00:00, 207.26s/it]
Predicting on frame ofs 34-Map
#··················································································#
重新看程序,发现程序中,没有用feed和fetch,没有用操作数和占位符转递数据,导致计算图graph越来越大,这也就造成训练时间指数性增加。
解决方法1:严格按照tensorflow标准,用feed和fetch传递数据(没有实验)
解决方法2:每组数据训练完毕后,清空重置计算图(亲测可行)
def load_graph(model_file):
graph = tf.Graph()
graph_def = tf.GraphDef()
with open(model_file, "rb") as f:
graph_def.ParseFromString(f.read())
with graph.as_default():
tf.import_graph_def(graph_def)
return graph
#·····································#
tf.reset_default_graph()
graph = load_graph(model_file)
print("reset graph")
修改后的运行日志:
100%|##################################################################################| 81/81 [12:06<00:00, 8.97s/it]
Predicting on frame of s10-Enemy
reset graph
100%|##################################################################################| 81/81 [11:50<00:00, 8.77s/it]
Predicting on frame of s11-Son
reset graph
100%|##################################################################################| 81/81 [11:49<00:00, 8.76s/it]
Predicting on frame of s12-Man
reset graph
100%|##################################################################################| 81/81 [11:56<00:00, 8.85s/it]
Predicting on frame of s13-Away