我有caffe的结果,我将从中提取最终的损失值。现在我已经用bash脚本获得了最终结果。例如,输出为:
I1221 15:29:03.581897 23416 solver.cpp:347] Iteration 300000, Testing net (#0) I1221 15:29:36.107956 23416 solver.cpp:415] Test net output #0: acc01 = 0.997557 I1221 15:29:36.108728 23416 solver.cpp:415] Test net output #1: acc02 = 0.799582 I1221 15:29:36.108815 23416 solver.cpp:415] Test net output #2: acc03 = 0.614063 I1221 15:29:36.108839 23416 solver.cpp:415] Test net output #3: acc04 = 0.875842 I1221 15:29:36.108880 23416 solver.cpp:415] Test net output #4: loss01 = 0.0183781 (* 1 = 0.0183781 loss) I1221 15:29:36.108914 23416 solver.cpp:415] Test net output #5: loss02 = 0.499269 (* 1 = 0.499269 loss) I1221 15:29:36.108945 23416 solver.cpp:415] Test net output #6: loss03 = 0.660662 (* 1 = 0.660662 loss) I1221 15:29:36.108974 23416 solver.cpp:415] Test net output #7: loss04 = 0.373288 (* 1 = 0.373288 loss) I1221 15:29:36.108996 23416 solver.cpp:332] Optimization Done. I1221 15:29:36.109011 23416 caffe.cpp:215] Optimization Done.
我会得到:
300000, 0.997557, 0.799582, 0.614063, 0.875842, 0.0183781, 0.499269, 0.660662, 0.373288
是
Iteration, acc01, acc02, acc03, acc04, loss01, loss02, loss03, loss04
请您指导我如何编写一些bash脚本来执行此操作。
谢谢, 阿夫欣
答案 0 :(得分:1)
awk -v value="" '{for(i=1;i<=NF;++i){if($i~/^acc/){value=value " " $(i+2)}else if($i~/^Iteration/){value=value $(i+1)}};print value}' my_file