Reputation: 532
I know that is possible to save a trained ANN into a file using CvFileStorage
, but I really don't like the way that CvFileStorage
saves the training, then I was wondering: Is that possible to retrieve the informations of a training and save it in a custom way?
Thanks in advance.
Upvotes: 0
Views: 613
Reputation: 10850
Just look at xml structure, it's very simple. The names of objects are the same as in ANN class. Here is a XOR solving network:
<?xml version="1.0"?>
<opencv_storage>
<my_nn type_id="opencv-ml-ann-mlp">
<layer_sizes type_id="opencv-matrix">
<rows>1</rows>
<cols>3</cols>
<dt>i</dt>
<data>
2 3 1</data></layer_sizes>
<activation_function>SIGMOID_SYM</activation_function>
<f_param1>1.</f_param1>
<f_param2>1.</f_param2>
<min_val>-9.4999999999999996e-001</min_val>
<max_val>9.4999999999999996e-001</max_val>
<min_val1>-9.7999999999999998e-001</min_val1>
<max_val1>9.7999999999999998e-001</max_val1>
<training_params>
<train_method>RPROP</train_method>
<dw0>1.0000000000000001e-001</dw0>
<dw_plus>1.2000000000000000e+000</dw_plus>
<dw_minus>5.0000000000000000e-001</dw_minus>
<dw_min>1.1920928955078125e-007</dw_min>
<dw_max>50.</dw_max>
<term_criteria><epsilon>9.9999997764825821e-003</epsilon>
<iterations>1000</iterations></term_criteria></training_params>
<input_scale>
2. -1. 2. -1.</input_scale>
<output_scale>
5.2631578947368418e-001 4.9999999999999994e-001</output_scale>
<inv_output_scale>
1.8999999999999999e+000 -9.4999999999999996e-001</inv_output_scale>
<weights>
<_>
-3.8878915951440729e+000 -3.7728173427563569e+000
-1.9587678786875042e+000 3.7898767378369680e+000
3.0354324494246829e+000 1.9757881693499044e+000
-3.5862527376978406e+000 -3.2701446005792296e+000
1.3000011629911392e+000</_>
<_>
3.1017381376627204e+000 1.1052842857439200e+000
-4.6739037571329822e+000 3.2282702769334666e+000</_></weights></my_nn>
</opencv_storage>
You can save the same parameters to you oun formated file. Some of the fields are protected, but you can make child class from CvANN_MLP and make your oun file saver.
Upvotes: 1