使用matlab绘制caffe的loss图像

之前见过有人使用shell画loss图像,我是在是学不来,于是自己动手写了一段matlab代码,把数据读到matlab里面。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fid=fopen('/data2/xxx/workspace/output.txt');
tline = fgetl(fid);
while ischar(tline)
sub_idx_iteration=strfind(tline,'Iteration');
if(sub_idx_iteration)
sub_loss = strfind(tline,'loss');
if(sub_loss)
idx_end=strfind(tline,',');
iteration = str2num(tline(sub_idx_iteration+10:idx_end-1));
total_loss=str2num(tline(sub_loss+7:end));
idx=iteration/5+1;
matrix_for_plot(idx,1)=iteration;
matrix_for_plot(idx,14)=total_loss;
for i=1:12
tline=fgetl(fid);
stage_loss_start=strfind(tline,'* 1 =')+6;
stage_loss=str2num(tline(stage_loss_start:end-5));
matrix_for_plot(idx,i+1)=stage_loss;
end
end
end
tline = fgetl(fid);
end
figure(1)
plot(matrix_for_plot(:,1),matrix_for_plot(:,13));
ylim([0,200])
xlabel('Iteration')
ylabel('L2 (Joints)')
saveas(1,'L2.jpg');
figure(2)
plot(matrix_for_plot(:,1),matrix_for_plot(:,12));
xlabel('Iteration')
ylabel('L1 (PAF)')
saveas(2,'L1.jpg');
figure(3)
plot(matrix_for_plot(:,1),matrix_for_plot(:,14));
ylim([0,3000])
xlabel('Iteration')
ylabel('total loss')
saveas(3,'total_loss.jpg');