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
27cddfb8
Commit
27cddfb8
authored
Jan 25, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10661 from alalek:parallel_kmeans
parents
3f116468
90aac764
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
25 deletions
+100
-25
perf_math.cpp
modules/core/perf/perf_math.cpp
+100
-25
kmeans.cpp
modules/core/src/kmeans.cpp
+0
-0
No files found.
modules/core/perf/perf_math.cpp
View file @
27cddfb8
...
...
@@ -3,13 +3,10 @@
using
namespace
std
;
using
namespace
cv
;
using
namespace
perf
;
using
std
::
tr1
::
make_tuple
;
using
std
::
tr1
::
get
;
typedef
perf
::
TestBaseWithParam
<
size_t
>
VectorLength
;
namespace
{
typedef
std
::
tr1
::
tuple
<
int
,
int
>
MaxDim_MaxPoints_t
;
typedef
perf
::
TestBaseWithParam
<
MaxDim_MaxPoints_t
>
MaxDim_MaxPoints
;
typedef
perf
::
TestBaseWithParam
<
size_t
>
VectorLength
;
PERF_TEST_P
(
VectorLength
,
phase32f
,
testing
::
Values
(
128
,
1000
,
128
*
1024
,
512
*
1024
,
1024
*
1024
))
{
...
...
@@ -39,47 +36,125 @@ PERF_TEST_P(VectorLength, phase64f, testing::Values(128, 1000, 128*1024, 512*102
SANITY_CHECK
(
angle
,
5e-5
);
}
PERF_TEST_P
(
MaxDim_MaxPoints
,
kmeans
,
testing
::
Combine
(
testing
::
Values
(
16
,
32
,
64
),
testing
::
Values
(
300
,
400
,
500
)
)
)
typedef
perf
::
TestBaseWithParam
<
testing
::
tuple
<
int
,
int
,
int
>
>
KMeans
;
PERF_TEST_P_
(
KMeans
,
single_iter
)
{
RNG
&
rng
=
theRNG
();
const
int
MAX_DIM
=
get
<
0
>
(
GetParam
());
const
int
MAX_POINTS
=
get
<
1
>
(
GetParam
());
const
int
K
=
testing
::
get
<
0
>
(
GetParam
());
const
int
dims
=
testing
::
get
<
1
>
(
GetParam
());
const
int
N
=
testing
::
get
<
2
>
(
GetParam
());
const
int
attempts
=
5
;
Mat
labels
,
centers
;
int
i
,
N
=
0
,
N0
=
0
,
K
=
0
,
dims
=
0
;
dims
=
rng
.
uniform
(
1
,
MAX_DIM
+
1
);
N
=
rng
.
uniform
(
1
,
MAX_POINTS
+
1
);
N0
=
rng
.
uniform
(
1
,
MAX
(
N
/
10
,
2
));
K
=
rng
.
uniform
(
1
,
N
+
1
);
Mat
data
(
N
,
dims
,
CV_32F
);
rng
.
fill
(
data
,
RNG
::
UNIFORM
,
-
0.1
,
0.1
);
const
int
N0
=
K
;
Mat
data0
(
N0
,
dims
,
CV_32F
);
rng
.
fill
(
data0
,
RNG
::
UNIFORM
,
-
1
,
1
);
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
int
base
=
rng
.
uniform
(
0
,
N0
);
cv
::
add
(
data0
.
row
(
base
),
data
.
row
(
i
),
data
.
row
(
i
));
}
declare
.
in
(
data
);
Mat
labels
,
centers
;
TEST_CYCLE
()
{
kmeans
(
data
,
K
,
labels
,
TermCriteria
(
TermCriteria
::
MAX_ITER
+
TermCriteria
::
EPS
,
1
,
0
),
attempts
,
KMEANS_PP_CENTERS
,
centers
);
}
SANITY_CHECK_NOTHING
();
}
PERF_TEST_P_
(
KMeans
,
good
)
{
RNG
&
rng
=
theRNG
();
const
int
K
=
testing
::
get
<
0
>
(
GetParam
());
const
int
dims
=
testing
::
get
<
1
>
(
GetParam
());
const
int
N
=
testing
::
get
<
2
>
(
GetParam
());
const
int
attempts
=
5
;
Mat
data
(
N
,
dims
,
CV_32F
);
for
(
i
=
0
;
i
<
N
;
i
++
)
data0
.
row
(
rng
.
uniform
(
0
,
N0
)).
copyTo
(
data
.
row
(
i
));
rng
.
fill
(
data
,
RNG
::
UNIFORM
,
-
0.1
,
0.1
);
const
int
N0
=
K
;
Mat
data0
(
N0
,
dims
,
CV_32F
);
rng
.
fill
(
data0
,
RNG
::
UNIFORM
,
-
1
,
1
);
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
int
base
=
rng
.
uniform
(
0
,
N0
);
cv
::
add
(
data0
.
row
(
base
),
data
.
row
(
i
),
data
.
row
(
i
));
}
declare
.
in
(
data
);
Mat
labels
,
centers
;
TEST_CYCLE
()
{
kmeans
(
data
,
K
,
labels
,
TermCriteria
(
TermCriteria
::
MAX_ITER
+
TermCriteria
::
EPS
,
30
,
0
),
attempts
,
KMEANS_PP_CENTERS
,
centers
);
}
Mat
clusterPointsNumber
=
Mat
::
zeros
(
1
,
K
,
CV_32S
);
SANITY_CHECK_NOTHING
();
}
PERF_TEST_P_
(
KMeans
,
with_duplicates
)
{
RNG
&
rng
=
theRNG
();
const
int
K
=
testing
::
get
<
0
>
(
GetParam
());
const
int
dims
=
testing
::
get
<
1
>
(
GetParam
());
const
int
N
=
testing
::
get
<
2
>
(
GetParam
());
const
int
attempts
=
5
;
Mat
data
(
N
,
dims
,
CV_32F
,
Scalar
::
all
(
0
));
const
int
N0
=
std
::
max
(
2
,
K
*
2
/
3
);
Mat
data0
(
N0
,
dims
,
CV_32F
);
rng
.
fill
(
data0
,
RNG
::
UNIFORM
,
-
1
,
1
);
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
int
base
=
rng
.
uniform
(
0
,
N0
);
data0
.
row
(
base
).
copyTo
(
data
.
row
(
i
));
}
declare
.
in
(
data
);
for
(
i
=
0
;
i
<
labels
.
rows
;
i
++
)
Mat
labels
,
centers
;
TEST_CYCLE
()
{
int
clusterIdx
=
labels
.
at
<
int
>
(
i
);
clusterPointsNumber
.
at
<
int
>
(
clusterIdx
)
++
;
kmeans
(
data
,
K
,
labels
,
TermCriteria
(
TermCriteria
::
MAX_ITER
+
TermCriteria
::
EPS
,
30
,
0
),
attempts
,
KMEANS_PP_CENTERS
,
centers
)
;
}
Mat
sortedClusterPointsNumber
;
cv
::
sort
(
clusterPointsNumber
,
sortedClusterPointsNumber
,
cv
::
SORT_EVERY_ROW
+
cv
::
SORT_ASCENDING
);
SANITY_CHECK_NOTHING
();
}
INSTANTIATE_TEST_CASE_P
(
/*nothing*/
,
KMeans
,
testing
::
Values
(
// K clusters, dims, N points
testing
::
make_tuple
(
2
,
3
,
100000
),
testing
::
make_tuple
(
4
,
3
,
500
),
testing
::
make_tuple
(
4
,
3
,
1000
),
testing
::
make_tuple
(
4
,
3
,
10000
),
testing
::
make_tuple
(
8
,
3
,
1000
),
testing
::
make_tuple
(
8
,
16
,
1000
),
testing
::
make_tuple
(
8
,
64
,
1000
),
testing
::
make_tuple
(
16
,
16
,
1000
),
testing
::
make_tuple
(
16
,
32
,
1000
),
testing
::
make_tuple
(
32
,
16
,
1000
),
testing
::
make_tuple
(
32
,
32
,
1000
),
testing
::
make_tuple
(
100
,
2
,
1000
)
)
);
SANITY_CHECK
(
sortedClusterPointsNumber
);
}
modules/core/src/kmeans.cpp
View file @
27cddfb8
This diff is collapsed.
Click to expand it.
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