Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
c6d778ea
Commit
c6d778ea
authored
May 08, 2014
by
Davis King
Browse files
Made the examples use the new simplified file serialization API.
parent
eb2806f3
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
31 additions
and
80 deletions
+31
-80
examples/assignment_learning_ex.cpp
examples/assignment_learning_ex.cpp
+2
-5
examples/custom_trainer_ex.cpp
examples/custom_trainer_ex.cpp
+3
-6
examples/fhog_object_detector_ex.cpp
examples/fhog_object_detector_ex.cpp
+2
-5
examples/krls_ex.cpp
examples/krls_ex.cpp
+3
-7
examples/krr_classification_ex.cpp
examples/krr_classification_ex.cpp
+2
-6
examples/krr_regression_ex.cpp
examples/krr_regression_ex.cpp
+2
-6
examples/learning_to_track_ex.cpp
examples/learning_to_track_ex.cpp
+2
-5
examples/multiclass_classification_ex.cpp
examples/multiclass_classification_ex.cpp
+2
-5
examples/object_detector_ex.cpp
examples/object_detector_ex.cpp
+2
-5
examples/rvm_ex.cpp
examples/rvm_ex.cpp
+2
-6
examples/rvm_regression_ex.cpp
examples/rvm_regression_ex.cpp
+2
-6
examples/sequence_labeler_ex.cpp
examples/sequence_labeler_ex.cpp
+2
-5
examples/sequence_segmenter_ex.cpp
examples/sequence_segmenter_ex.cpp
+2
-5
examples/svm_ex.cpp
examples/svm_ex.cpp
+2
-5
examples/train_object_detector.cpp
examples/train_object_detector.cpp
+1
-3
No files found.
examples/assignment_learning_ex.cpp
View file @
c6d778ea
...
@@ -195,13 +195,10 @@ int main()
...
@@ -195,13 +195,10 @@ int main()
// Finally, the assigner can be serialized to disk just like most dlib objects.
// Finally, the assigner can be serialized to disk just like most dlib objects.
ofstream
fout
(
"assigner.dat"
,
ios
::
binary
);
serialize
(
"assigner.dat"
)
<<
assigner
;
serialize
(
assigner
,
fout
);
fout
.
close
();
// recall from disk
// recall from disk
ifstream
fin
(
"assigner.dat"
,
ios
::
binary
);
deserialize
(
"assigner.dat"
)
>>
assigner
;
deserialize
(
assigner
,
fin
);
}
}
catch
(
std
::
exception
&
e
)
catch
(
std
::
exception
&
e
)
{
{
...
...
examples/custom_trainer_ex.cpp
View file @
c6d778ea
...
@@ -208,15 +208,12 @@ int main()
...
@@ -208,15 +208,12 @@ int main()
decision_function
<
radial_basis_kernel
<
sample_type
>
>
// This is the output of the rbf_trainer
decision_function
<
radial_basis_kernel
<
sample_type
>
>
// This is the output of the rbf_trainer
>
df2
,
df3
;
>
df2
,
df3
;
df2
=
df
;
df2
=
df
;
ofstream
fout
(
"df.dat"
,
ios
::
binary
);
// save to a file called df.dat
serialize
(
df2
,
fout
);
serialize
(
"df.dat"
)
<<
df2
;
fout
.
close
();
// load the function back in from disk and store it in df3.
// load the function back in from disk and store it in df3.
ifstream
fin
(
"df.dat"
,
ios
::
binary
);
deserialize
(
"df.dat"
)
>>
df3
;
deserialize
(
df3
,
fin
);
// Test df3 to see that this worked.
// Test df3 to see that this worked.
...
...
examples/fhog_object_detector_ex.cpp
View file @
c6d778ea
...
@@ -180,14 +180,11 @@ int main(int argc, char** argv)
...
@@ -180,14 +180,11 @@ int main(int argc, char** argv)
// Like everything in dlib, you can save your detector to disk using the
// Like everything in dlib, you can save your detector to disk using the
// serialize() function.
// serialize() function.
ofstream
fout
(
"face_detector.svm"
,
ios
::
binary
);
serialize
(
"face_detector.svm"
)
<<
detector
;
serialize
(
detector
,
fout
);
fout
.
close
();
// Then you can recall it using the deserialize() function.
// Then you can recall it using the deserialize() function.
ifstream
fin
(
"face_detector.svm"
,
ios
::
binary
);
object_detector
<
image_scanner_type
>
detector2
;
object_detector
<
image_scanner_type
>
detector2
;
deserialize
(
detector
2
,
fin
)
;
deserialize
(
"face_
detector
.svm"
)
>>
detector2
;
...
...
examples/krls_ex.cpp
View file @
c6d778ea
...
@@ -78,21 +78,17 @@ int main()
...
@@ -78,21 +78,17 @@ int main()
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// So for example, you can save the test object to disk and recall it later like so:
// So for example, you can save the test object to disk and recall it later like so:
ofstream
fout
(
"saved_krls_object.dat"
,
ios
::
binary
);
serialize
(
"saved_krls_object.dat"
)
<<
test
;
serialize
(
test
,
fout
);
fout
.
close
();
// Now let's open that file back up and load the krls object it contains.
// Now let's open that file back up and load the krls object it contains.
ifstream
fin
(
"saved_krls_object.dat"
,
ios
::
binary
);
deserialize
(
"saved_krls_object.dat"
)
>>
test
;
deserialize
(
test
,
fin
);
// If you don't want to save the whole krls object (it might be a bit large)
// If you don't want to save the whole krls object (it might be a bit large)
// you can save just the decision function it has learned so far. You can get
// you can save just the decision function it has learned so far. You can get
// the decision function out of it by calling test.get_decision_function() and
// the decision function out of it by calling test.get_decision_function() and
// then you can serialize that object instead. E.g.
// then you can serialize that object instead. E.g.
decision_function
<
kernel_type
>
funct
=
test
.
get_decision_function
();
decision_function
<
kernel_type
>
funct
=
test
.
get_decision_function
();
fout
.
open
(
"saved_krls_function.dat"
,
ios
::
binary
);
serialize
(
"saved_krls_function.dat"
)
<<
funct
;
serialize
(
funct
,
fout
);
}
}
examples/krr_classification_ex.cpp
View file @
c6d778ea
...
@@ -196,14 +196,10 @@ int main()
...
@@ -196,14 +196,10 @@ int main()
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// So for example, you can save the learned_pfunct object to disk and recall it later like so:
// So for example, you can save the learned_pfunct object to disk and recall it later like so:
ofstream
fout
(
"saved_function.dat"
,
ios
::
binary
);
serialize
(
"saved_function.dat"
)
<<
learned_pfunct
;
serialize
(
learned_pfunct
,
fout
);
fout
.
close
();
// Now let's open that file back up and load the function object it contains.
// Now let's open that file back up and load the function object it contains.
ifstream
fin
(
"saved_function.dat"
,
ios
::
binary
);
deserialize
(
"saved_function.dat"
)
>>
learned_pfunct
;
deserialize
(
learned_pfunct
,
fin
);
}
}
examples/krr_regression_ex.cpp
View file @
c6d778ea
...
@@ -94,14 +94,10 @@ int main()
...
@@ -94,14 +94,10 @@ int main()
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// So for example, you can save the test object to disk and recall it later like so:
// So for example, you can save the test object to disk and recall it later like so:
ofstream
fout
(
"saved_function.dat"
,
ios
::
binary
);
serialize
(
"saved_function.dat"
)
<<
test
;
serialize
(
test
,
fout
);
fout
.
close
();
// Now let's open that file back up and load the function object it contains.
// Now let's open that file back up and load the function object it contains.
ifstream
fin
(
"saved_function.dat"
,
ios
::
binary
);
deserialize
(
"saved_function.dat"
)
>>
test
;
deserialize
(
test
,
fin
);
}
}
...
...
examples/learning_to_track_ex.cpp
View file @
c6d778ea
...
@@ -344,13 +344,10 @@ int main()
...
@@ -344,13 +344,10 @@ int main()
// Finally, you can save your track_association_function to disk like so:
// Finally, you can save your track_association_function to disk like so:
ofstream
fout
(
"track_assoc.svm"
,
ios
::
binary
);
serialize
(
"track_assoc.svm"
)
<<
assoc
;
serialize
(
assoc
,
fout
);
fout
.
close
();
// And recall it from disk later like so:
// And recall it from disk later like so:
ifstream
fin
(
"track_assoc.svm"
,
ios
::
binary
);
deserialize
(
"track_assoc.svm"
)
>>
assoc
;
deserialize
(
assoc
,
fin
);
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
examples/multiclass_classification_ex.cpp
View file @
c6d778ea
...
@@ -138,13 +138,10 @@ int main()
...
@@ -138,13 +138,10 @@ int main()
// Put df into df2 and then save df2 to disk. Note that we could have also said
// Put df into df2 and then save df2 to disk. Note that we could have also said
// df2 = trainer.train(samples, labels); But doing it this way avoids retraining.
// df2 = trainer.train(samples, labels); But doing it this way avoids retraining.
df2
=
df
;
df2
=
df
;
ofstream
fout
(
"df.dat"
,
ios
::
binary
);
serialize
(
"df.dat"
)
<<
df2
;
serialize
(
df2
,
fout
);
fout
.
close
();
// load the function back in from disk and store it in df3.
// load the function back in from disk and store it in df3.
ifstream
fin
(
"df.dat"
,
ios
::
binary
);
deserialize
(
"df.dat"
)
>>
df3
;
deserialize
(
df3
,
fin
);
// Test df3 to see that this worked.
// Test df3 to see that this worked.
...
...
examples/object_detector_ex.cpp
View file @
c6d778ea
...
@@ -247,13 +247,10 @@ int main()
...
@@ -247,13 +247,10 @@ int main()
// Finally, note that the detector can be serialized to disk just like other dlib objects.
// Finally, note that the detector can be serialized to disk just like other dlib objects.
ofstream
fout
(
"object_detector.dat"
,
ios
::
binary
);
serialize
(
"object_detector.dat"
)
<<
detector
;
serialize
(
detector
,
fout
);
fout
.
close
();
// Recall from disk.
// Recall from disk.
ifstream
fin
(
"object_detector.dat"
,
ios
::
binary
);
deserialize
(
"object_detector.dat"
)
>>
detector
;
deserialize
(
detector
,
fin
);
}
}
catch
(
exception
&
e
)
catch
(
exception
&
e
)
{
{
...
...
examples/rvm_ex.cpp
View file @
c6d778ea
...
@@ -208,14 +208,10 @@ int main()
...
@@ -208,14 +208,10 @@ int main()
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// So for example, you can save the learned_pfunct object to disk and recall it later like so:
// So for example, you can save the learned_pfunct object to disk and recall it later like so:
ofstream
fout
(
"saved_function.dat"
,
ios
::
binary
);
serialize
(
"saved_function.dat"
)
<<
learned_pfunct
;
serialize
(
learned_pfunct
,
fout
);
fout
.
close
();
// Now let's open that file back up and load the function object it contains.
// Now let's open that file back up and load the function object it contains.
ifstream
fin
(
"saved_function.dat"
,
ios
::
binary
);
deserialize
(
"saved_function.dat"
)
>>
learned_pfunct
;
deserialize
(
learned_pfunct
,
fin
);
}
}
examples/rvm_regression_ex.cpp
View file @
c6d778ea
...
@@ -91,14 +91,10 @@ int main()
...
@@ -91,14 +91,10 @@ int main()
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// So for example, you can save the test object to disk and recall it later like so:
// So for example, you can save the test object to disk and recall it later like so:
ofstream
fout
(
"saved_function.dat"
,
ios
::
binary
);
serialize
(
"saved_function.dat"
)
<<
test
;
serialize
(
test
,
fout
);
fout
.
close
();
// Now let's open that file back up and load the function object it contains.
// Now let's open that file back up and load the function object it contains.
ifstream
fin
(
"saved_function.dat"
,
ios
::
binary
);
deserialize
(
"saved_function.dat"
)
>>
test
;
deserialize
(
test
,
fin
);
}
}
...
...
examples/sequence_labeler_ex.cpp
View file @
c6d778ea
...
@@ -292,13 +292,10 @@ int main()
...
@@ -292,13 +292,10 @@ int main()
// Finally, the labeler can be serialized to disk just like most dlib objects.
// Finally, the labeler can be serialized to disk just like most dlib objects.
ofstream
fout
(
"labeler.dat"
,
ios
::
binary
);
serialize
(
"labeler.dat"
)
<<
labeler
;
serialize
(
labeler
,
fout
);
fout
.
close
();
// recall from disk
// recall from disk
ifstream
fin
(
"labeler.dat"
,
ios
::
binary
);
deserialize
(
"labeler.dat"
)
>>
labeler
;
deserialize
(
labeler
,
fin
);
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
examples/sequence_segmenter_ex.cpp
View file @
c6d778ea
...
@@ -228,13 +228,10 @@ int main()
...
@@ -228,13 +228,10 @@ int main()
// Finally, the segmenter can be serialized to disk just like most dlib objects.
// Finally, the segmenter can be serialized to disk just like most dlib objects.
ofstream
fout
(
"segmenter.dat"
,
ios
::
binary
);
serialize
(
"segmenter.dat"
)
<<
segmenter
;
serialize
(
segmenter
,
fout
);
fout
.
close
();
// recall from disk
// recall from disk
ifstream
fin
(
"segmenter.dat"
,
ios
::
binary
);
deserialize
(
"segmenter.dat"
)
>>
segmenter
;
deserialize
(
segmenter
,
fin
);
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
examples/svm_ex.cpp
View file @
c6d778ea
...
@@ -210,13 +210,10 @@ int main()
...
@@ -210,13 +210,10 @@ int main()
// Another thing that is worth knowing is that just about everything in dlib is
// Another thing that is worth knowing is that just about everything in dlib is
// serializable. So for example, you can save the learned_pfunct object to disk and
// serializable. So for example, you can save the learned_pfunct object to disk and
// recall it later like so:
// recall it later like so:
ofstream
fout
(
"saved_function.dat"
,
ios
::
binary
);
serialize
(
"saved_function.dat"
)
<<
learned_pfunct
;
serialize
(
learned_pfunct
,
fout
);
fout
.
close
();
// Now let's open that file back up and load the function object it contains.
// Now let's open that file back up and load the function object it contains.
ifstream
fin
(
"saved_function.dat"
,
ios
::
binary
);
deserialize
(
"saved_function.dat"
)
>>
learned_pfunct
;
deserialize
(
learned_pfunct
,
fin
);
// Note that there is also an example program that comes with dlib called the
// Note that there is also an example program that comes with dlib called the
// file_to_code_ex.cpp example. It is a simple program that takes a file and outputs a
// file_to_code_ex.cpp example. It is a simple program that takes a file and outputs a
...
...
examples/train_object_detector.cpp
View file @
c6d778ea
...
@@ -291,9 +291,7 @@ int main(int argc, char** argv)
...
@@ -291,9 +291,7 @@ int main(int argc, char** argv)
object_detector
<
image_scanner_type
>
detector
=
trainer
.
train
(
images
,
object_locations
,
ignore
);
object_detector
<
image_scanner_type
>
detector
=
trainer
.
train
(
images
,
object_locations
,
ignore
);
cout
<<
"Saving trained detector to object_detector.svm"
<<
endl
;
cout
<<
"Saving trained detector to object_detector.svm"
<<
endl
;
ofstream
fout
(
"object_detector.svm"
,
ios
::
binary
);
serialize
(
"object_detector.svm"
)
<<
detector
;
serialize
(
detector
,
fout
);
fout
.
close
();
cout
<<
"Testing detector on training data..."
<<
endl
;
cout
<<
"Testing detector on training data..."
<<
endl
;
cout
<<
"Test detector (precision,recall,AP): "
<<
test_object_detection_function
(
detector
,
images
,
object_locations
)
<<
endl
;
cout
<<
"Test detector (precision,recall,AP): "
<<
test_object_detection_function
(
detector
,
images
,
object_locations
)
<<
endl
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment