-
Notifications
You must be signed in to change notification settings - Fork 5
/
caffe_write_solverprototxt.m
52 lines (42 loc) · 1.47 KB
/
caffe_write_solverprototxt.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
function [ out ] = caffe_write_solverprototxt( filename, solver_descr )
%% Description:
% write prototxt file from
% caffe_write_solverprototxt( solver_descr )
% --- INPUTS:
% filename = filename to save (*.prototxt will be added automatically if absent)
% solver_descr = structure with properties you want to write
% IMPORTANT:
% - field "solver_mode" should be 0/1, where 0 = cpu, 1 = gpu
%% Parameters
%% Execution:
% Cut the extension
extension = '.prototxt';
if length(filename ) >= 10
if strcmp( filename(end-8:end), extension)
filename = filename(1:end-9);
end
end
fileID = fopen( [filename extension], 'w');
parameter_names = fieldnames(solver_descr);
for var_i=1:length(parameter_names)
is_solvermode = strcmp( 'solver_mode', parameter_names{var_i} );
is_logical = any(strcmp( {'true', 'false'}, solver_descr.(parameter_names{var_i})));
num = str2double( solver_descr.(parameter_names{var_i}) );
if is_logical || is_solvermode || ~isnan(num)
fprintf(fileID, '%s : %s\n', parameter_names{var_i}, solver_descr.(parameter_names{var_i}) );
else
fprintf(fileID, '%s : \"%s\"\n', parameter_names{var_i}, solver_descr.(parameter_names{var_i}) );
end
end
fclose(fileID);
% Checking that the file is fine
fprintf('%s : \n', [filename extension] );
fprintf('-------------------\n');
fid = fopen( [filename extension] );
tline = fgets(fid);
while ischar(tline)
fprintf('%s', tline);
tline = fgets(fid);
end
fclose(fid);
end