-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw_loss_plot.m
61 lines (52 loc) · 1.65 KB
/
draw_loss_plot.m
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
clc;
clear;
% log file of caffe model
logName = 'caffe_log20160204-092304.25218';
fid = fopen(logName, 'r');
fid_accuracy = fopen('output_accuracy.txt', 'w');
fid_loss = fopen('output_loss.txt', 'w');
tline = fgetl(fid);
while ischar(tline)
% First find the accuracy line
k = strfind(tline, 'Test net output');
if (k)
k = strfind(tline, 'accuracy');
if (k)
% If the string contain test and accuracy at the same time
% The bias from 'accuracy' to the float number
indexStart = k + 11;
indexEnd = size(tline);
str = tline(indexStart : indexEnd(2));
end
% Get the number of index
k = strfind(tline, '#');
if (k)
indexStart = k + 1;
indexEnd = strfind(tline, ':');
str2 = tline(indexStart : indexEnd - 1);
end
% Concatenation of two string
res_str = [str2 ' ' str1];
fprintf(fid_accuracy, '%s\r\n', res_str);
end
% Then find the loss line
k1 = strfind(tline, 'Iteration');
if (k1)
k2 = strfind(tline, 'loss');
if (k2)
indexStart = k2 + 7;
indexEnd = size(tline);
str1 = tline(indexStart:indexEnd(2));
indexStart = k1 + 10;
indexEnd = strfind(tline, ',') - 1;
str2 = tline(indexStart:indexEnd);
res_str1 = [str2 ' ' str1];
fprintf(fid_loss, '%s\r\n', res_str1);
end
end
tline = fgetl(fid);
end
fclose(fid);
fclose(fid_accuracy);
a=importdata('output_loss.txt');
plot(a(:,1),a(:,2));