Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
23d0e361
Commit
23d0e361
authored
Dec 17, 2012
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix floating point precision
parent
ef4b18f3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
50 deletions
+12
-50
octave.hpp
apps/sft/include/sft/octave.hpp
+2
-2
octave.cpp
apps/sft/octave.cpp
+10
-13
sft.cpp
apps/sft/sft.cpp
+0
-35
No files found.
apps/sft/include/sft/octave.hpp
View file @
23d0e361
...
...
@@ -147,7 +147,7 @@ public:
virtual
void
setRejectThresholds
(
cv
::
Mat
&
thresholds
);
virtual
void
write
(
CvFileStorage
*
fs
,
string
name
)
const
;
virtual
void
write
(
cv
::
FileStorage
&
fs
,
const
FeaturePool
&
pool
,
const
Mat
&
thresholds
=
Mat
()
)
const
;
virtual
void
write
(
cv
::
FileStorage
&
fs
,
const
FeaturePool
&
pool
,
const
Mat
&
thresholds
)
const
;
int
logScale
;
...
...
@@ -160,7 +160,7 @@ protected:
float
predict
(
const
Mat
&
_sample
,
const
cv
::
Range
range
)
const
;
private
:
void
traverse
(
const
CvBoostTree
*
tree
,
cv
::
FileStorage
&
fs
,
int
&
nfeatures
,
int
*
used
,
const
float
*
th
=
0
)
const
;
void
traverse
(
const
CvBoostTree
*
tree
,
cv
::
FileStorage
&
fs
,
int
&
nfeatures
,
int
*
used
,
const
double
*
th
)
const
;
virtual
void
initial_weights
(
double
(
&
p
)[
2
]);
cv
::
Rect
boundingBox
;
...
...
apps/sft/octave.cpp
View file @
23d0e361
...
...
@@ -116,7 +116,7 @@ void sft::Octave::setRejectThresholds(cv::Mat& thresholds)
for
(
int
si
=
0
;
si
<
nsamples
;
++
si
)
{
float
decision
=
dptr
[
si
]
=
predict
(
trainData
.
col
(
si
),
stab
,
false
,
false
);
mptr
[
si
]
=
cv
::
saturate_cast
<
uchar
>
((
uint
)(
responses
.
ptr
<
float
>
(
si
)[
0
]
==
1.
f
&&
decision
==
1.
f
));
mptr
[
si
]
=
cv
::
saturate_cast
<
uchar
>
((
uint
)(
(
responses
.
ptr
<
float
>
(
si
)[
0
]
==
1.
f
)
&&
(
decision
==
1.
f
)
));
}
// std::cout << "WARNING: responses " << responses << std::endl;
...
...
@@ -144,8 +144,10 @@ void sft::Octave::setRejectThresholds(cv::Mat& thresholds)
double
mintrace
=
0.
;
cv
::
minMaxLoc
(
traces
.
row
(
w
),
&
mintrace
);
thptr
[
w
]
=
mintrace
;
// std::cout << "mintrace " << mintrace << std::endl << traces.colRange(0, npositives) << std::endl;
// std::cout << "mintrace " << mintrace << std::endl << traces.colRange(0, npositives)
.rowRange(w, w + 1) << std::endl << std::endl << std::endl
<< std::endl;
}
std
::
cout
<<
"WARNING: thresholds "
<<
thresholds
<<
std
::
endl
;
}
namespace
{
...
...
@@ -300,7 +302,7 @@ template <typename T> int sgn(T val) {
return
(
T
(
0
)
<
val
)
-
(
val
<
T
(
0
));
}
void
sft
::
Octave
::
traverse
(
const
CvBoostTree
*
tree
,
cv
::
FileStorage
&
fs
,
int
&
nfeatures
,
int
*
used
,
const
float
*
th
)
const
void
sft
::
Octave
::
traverse
(
const
CvBoostTree
*
tree
,
cv
::
FileStorage
&
fs
,
int
&
nfeatures
,
int
*
used
,
const
double
*
th
)
const
{
std
::
queue
<
const
CvDTreeNode
*>
nodes
;
nodes
.
push
(
tree
->
get_root
());
...
...
@@ -310,6 +312,7 @@ void sft::Octave::traverse(const CvBoostTree* tree, cv::FileStorage& fs, int& nf
float
*
leafs
=
new
float
[(
int
)
pow
(
2.
f
,
get_params
().
max_depth
)];
fs
<<
"{"
;
fs
<<
"treeThreshold"
<<
*
th
;
fs
<<
"internalNodes"
<<
"["
;
while
(
!
nodes
.
empty
())
{
...
...
@@ -349,14 +352,16 @@ void sft::Octave::traverse(const CvBoostTree* tree, cv::FileStorage& fs, int& nf
fs
<<
"leafValues"
<<
"["
;
for
(
int
ni
=
0
;
ni
<
-
leafValIdx
;
ni
++
)
fs
<<
(
(
!
th
)
?
leafs
[
ni
]
:
(
sgn
(
leafs
[
ni
])
*
*
th
));
fs
<<
leafs
[
ni
];
//
( (!th) ? leafs[ni] : (sgn(leafs[ni]) * *th));
fs
<<
"]"
;
fs
<<
"}"
;
}
void
sft
::
Octave
::
write
(
cv
::
FileStorage
&
fso
,
const
FeaturePool
&
pool
,
const
Mat
&
thresholds
)
const
{
CV_Assert
(
!
thresholds
.
empty
());
cv
::
Mat
used
(
1
,
weak
->
total
*
(
pow
(
2
,
params
.
max_depth
)
-
1
),
CV_32SC1
);
int
*
usedPtr
=
used
.
ptr
<
int
>
(
0
);
int
nfeatures
=
0
;
...
...
@@ -373,19 +378,13 @@ void sft::Octave::write( cv::FileStorage &fso, const FeaturePool& pool, const Ma
CvBoostTree
*
tree
;
CV_READ_SEQ_ELEM
(
tree
,
reader
);
if
(
!
thresholds
.
empty
())
traverse
(
tree
,
fso
,
nfeatures
,
usedPtr
,
thresholds
.
ptr
<
float
>
(
0
)
+
i
);
else
traverse
(
tree
,
fso
,
nfeatures
,
usedPtr
);
traverse
(
tree
,
fso
,
nfeatures
,
usedPtr
,
thresholds
.
ptr
<
double
>
(
0
)
+
i
);
}
//
fso
<<
"]"
;
// features
fso
<<
"features"
<<
"["
;
for
(
int
i
=
0
;
i
<
nfeatures
;
++
i
)
// fso << usedPtr[i];
pool
.
write
(
fso
,
usedPtr
[
i
]);
fso
<<
"]"
<<
"}"
;
...
...
@@ -409,7 +408,6 @@ bool sft::Octave::train(const Dataset& dataset, const FeaturePool& pool, int wea
// 1. fill integrals and classes
processPositives
(
dataset
,
pool
);
generateNegatives
(
dataset
);
// exit(0);
// 2. only sumple case (all features used)
int
nfeatures
=
pool
.
size
();
...
...
@@ -550,7 +548,6 @@ void sft::FeaturePool::fill(int desired)
if
(
std
::
find
(
pool
.
begin
(),
pool
.
end
(),
f
)
==
pool
.
end
())
{
// std::cout << f << std::endl;
pool
.
push_back
(
f
);
}
}
...
...
apps/sft/sft.cpp
View file @
23d0e361
...
...
@@ -100,16 +100,6 @@ int main(int argc, char** argv)
return
1
;
}
cv
::
FileStorage
fsr
(
cfg
.
outXmlPath
+
".raw.xml"
,
cv
::
FileStorage
::
WRITE
);
if
(
!
fsr
.
isOpened
())
{
std
::
cout
<<
"Training stopped. Output classifier Xml file "
<<
cfg
.
outXmlPath
+
".raw.xml"
<<
" can't be opened."
<<
std
::
endl
<<
std
::
flush
;
return
1
;
}
// ovector strong;
// strong.reserve(cfg.octaves.size());
fso
<<
cfg
.
cascadeName
<<
"{"
<<
"stageType"
<<
"BOOST"
...
...
@@ -120,16 +110,6 @@ int main(int argc, char** argv)
<<
"shrinkage"
<<
cfg
.
shrinkage
<<
"octaves"
<<
"["
;
fsr
<<
cfg
.
cascadeName
<<
"{"
<<
"stageType"
<<
"BOOST"
<<
"featureType"
<<
"ICF"
<<
"octavesNum"
<<
(
int
)
cfg
.
octaves
.
size
()
<<
"width"
<<
cfg
.
modelWinSize
.
width
<<
"height"
<<
cfg
.
modelWinSize
.
height
<<
"shrinkage"
<<
cfg
.
shrinkage
<<
"octaves"
<<
"["
;
// 3. Train all octaves
for
(
ivector
::
const_iterator
it
=
cfg
.
octaves
.
begin
();
it
!=
cfg
.
octaves
.
end
();
++
it
)
{
...
...
@@ -163,8 +143,6 @@ int main(int argc, char** argv)
boost
.
setRejectThresholds
(
thresholds
);
boost
.
write
(
fso
,
pool
,
thresholds
);
boost
.
write
(
fsr
,
pool
);
// std::cout << "thresholds " << thresholds << std::endl;
cv
::
FileStorage
tfs
((
"thresholds."
+
cfg
.
resPath
(
it
)).
c_str
(),
cv
::
FileStorage
::
WRITE
);
tfs
<<
"thresholds"
<<
thresholds
;
...
...
@@ -174,18 +152,6 @@ int main(int argc, char** argv)
}
fso
<<
"]"
<<
"}"
;
fsr
<<
"]"
<<
"}"
;
// // // 6. Set thresolds
// // cascade.prune();
// // // 7. Postprocess
// // cascade.normolize();
// // // 8. Write result xml
// // cv::FileStorage ofs(cfg.outXmlPath, cv::FileStorage::WRITE);
// // ofs << cfg.cascadeName << cascade;
std
::
cout
<<
"Training complete..."
<<
std
::
endl
;
return
0
;
}
\ No newline at end of file
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