Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
942e9205
Commit
942e9205
authored
Aug 03, 2016
by
Vitaliy Lyudvichenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing of reshape layer to pass Torch test
parent
231546b7
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
18 deletions
+45
-18
blob.cpp
modules/dnn/src/blob.cpp
+7
-1
layer_loaders.cpp
modules/dnn/src/caffe/layer_loaders.cpp
+3
-2
fully_connected_layer.cpp
modules/dnn/src/layers/fully_connected_layer.cpp
+5
-3
lrn_layer.cpp
modules/dnn/src/layers/lrn_layer.cpp
+16
-12
lrn_layer.hpp
modules/dnn/src/layers/lrn_layer.hpp
+2
-0
torch_importer.cpp
modules/dnn/src/torch/torch_importer.cpp
+12
-0
No files found.
modules/dnn/src/blob.cpp
View file @
942e9205
...
@@ -364,9 +364,15 @@ BlobShape computeShapeByReshapeMask(const BlobShape &srcShape, const BlobShape &
...
@@ -364,9 +364,15 @@ BlobShape computeShapeByReshapeMask(const BlobShape &srcShape, const BlobShape &
{
{
if
(
srcRange
==
Range
::
all
())
if
(
srcRange
==
Range
::
all
())
srcRange
=
Range
(
0
,
srcShape
.
dims
());
srcRange
=
Range
(
0
,
srcShape
.
dims
());
else
{
int
sz
=
srcRange
.
size
();
srcRange
.
start
=
srcShape
.
canonicalAxis
(
srcRange
.
start
);
srcRange
.
end
=
(
srcRange
.
end
==
INT_MAX
)
?
srcShape
.
dims
()
:
srcRange
.
start
+
sz
;
}
CV_Assert
(
0
<=
srcRange
.
start
&&
srcRange
.
start
<=
srcRange
.
end
&&
srcRange
.
end
<=
srcShape
.
dims
());
CV_Assert
(
0
<=
srcRange
.
start
&&
srcRange
.
start
<=
srcRange
.
end
&&
srcRange
.
end
<=
srcShape
.
dims
());
Shape
dstShape
(
srcShape
.
dims
()
-
srcRange
.
size
()
+
maskShape
.
dims
(),
nullptr
);
BlobShape
dstShape
(
srcShape
.
dims
()
-
srcRange
.
size
()
+
maskShape
.
dims
(),
(
const
int
*
)
NULL
);
std
::
copy
(
srcShape
.
ptr
(),
srcShape
.
ptr
()
+
srcRange
.
start
,
dstShape
.
ptr
());
std
::
copy
(
srcShape
.
ptr
(),
srcShape
.
ptr
()
+
srcRange
.
start
,
dstShape
.
ptr
());
std
::
copy
(
srcShape
.
ptr
()
+
srcRange
.
end
,
srcShape
.
ptr
()
+
srcShape
.
dims
(),
dstShape
.
ptr
()
+
srcRange
.
start
+
maskShape
.
dims
());
std
::
copy
(
srcShape
.
ptr
()
+
srcRange
.
end
,
srcShape
.
ptr
()
+
srcShape
.
dims
(),
dstShape
.
ptr
()
+
srcRange
.
start
+
maskShape
.
dims
());
...
...
modules/dnn/src/caffe/layer_loaders.cpp
View file @
942e9205
#include "../precomp.hpp"
#include "../precomp.hpp"
#include "layer_loaders.hpp"
#include "layer_loaders.hpp"
#include <opencv2/dnn/shape_utils.hpp>
#include <opencv2/dnn/shape_utils.hpp>
#include <climits>
namespace
cv
namespace
cv
{
{
...
@@ -180,13 +181,13 @@ Ptr<Layer> createLayerFromCaffe<ReshapeLayer>(LayerParams ¶ms)
...
@@ -180,13 +181,13 @@ Ptr<Layer> createLayerFromCaffe<ReshapeLayer>(LayerParams ¶ms)
int
axis
=
params
.
get
<
int
>
(
"axis"
,
0
);
int
axis
=
params
.
get
<
int
>
(
"axis"
,
0
);
int
numAxes
=
params
.
get
<
int
>
(
"num_axes"
,
-
1
);
int
numAxes
=
params
.
get
<
int
>
(
"num_axes"
,
-
1
);
CV_Assert
(
numAxes
>=
-
1
);
CV_Assert
(
numAxes
>=
-
1
);
Range
applyingRange
=
(
numAxes
==
-
1
)
?
Range
::
all
(
)
:
Range
(
axis
,
axis
+
numAxes
);
Range
applyingRange
=
(
numAxes
==
-
1
)
?
Range
(
axis
,
INT_MAX
)
:
Range
(
axis
,
axis
+
numAxes
);
Shape
newShape
;
Shape
newShape
;
if
(
params
.
has
(
"dim"
))
if
(
params
.
has
(
"dim"
))
{
{
const
DictValue
&
paramShape
=
params
.
get
(
"dim"
);
const
DictValue
&
paramShape
=
params
.
get
(
"dim"
);
newShape
=
Shape
(
paramShape
.
size
(),
nullptr
);
newShape
=
Shape
::
all
(
paramShape
.
size
()
);
for
(
int
i
=
0
;
i
<
paramShape
.
size
();
i
++
)
for
(
int
i
=
0
;
i
<
paramShape
.
size
();
i
++
)
newShape
[
i
]
=
paramShape
.
get
<
int
>
(
i
);
newShape
[
i
]
=
paramShape
.
get
<
int
>
(
i
);
}
}
...
...
modules/dnn/src/layers/fully_connected_layer.cpp
View file @
942e9205
...
@@ -89,10 +89,12 @@ void FullyConnectedLayerImpl::allocate(const std::vector<Blob*> &input, std::vec
...
@@ -89,10 +89,12 @@ void FullyConnectedLayerImpl::allocate(const std::vector<Blob*> &input, std::vec
void
FullyConnectedLayerImpl
::
forward
(
std
::
vector
<
Blob
*>
&
input
,
std
::
vector
<
Blob
>
&
output
)
void
FullyConnectedLayerImpl
::
forward
(
std
::
vector
<
Blob
*>
&
input
,
std
::
vector
<
Blob
>
&
output
)
{
{
if
(
!
useOpenCL
)
#ifdef HAVE_OPENCL
forward_
<
Mat
>
(
input
,
output
);
if
(
useOpenCL
)
else
forward_
<
UMat
>
(
input
,
output
);
forward_
<
UMat
>
(
input
,
output
);
else
#endif
forward_
<
Mat
>
(
input
,
output
);
}
}
template
<
typename
XMat
>
template
<
typename
XMat
>
...
...
modules/dnn/src/layers/lrn_layer.cpp
View file @
942e9205
...
@@ -47,7 +47,6 @@
...
@@ -47,7 +47,6 @@
#include <opencv2/core/ocl.hpp>
#include <opencv2/core/ocl.hpp>
#include <opencv2/dnn/shape_utils.hpp>
#include <opencv2/dnn/shape_utils.hpp>
#include <algorithm>
#include <algorithm>
#include <type_traits>
namespace
cv
namespace
cv
{
{
...
@@ -205,6 +204,21 @@ void LRNLayerImpl::spatialNormalization(Blob &src, Blob &dst)
...
@@ -205,6 +204,21 @@ void LRNLayerImpl::spatialNormalization(Blob &src, Blob &dst)
spatialNormalization_
<
UMat
>
(
src
,
dst
);
spatialNormalization_
<
UMat
>
(
src
,
dst
);
}
}
//TODO: fix cv::boxFilter with BORDER_ISOLATED flag in CPU mode
template
<>
void
LRNLayerImpl
::
sqrBoxFilter_
<
Mat
>
(
const
Mat
&
src
,
Mat
&
dst
)
{
Mat
bufMat
=
buf
.
getRef
<
Mat
>
();
src
.
copyTo
(
bufMat
);
cv
::
sqrBoxFilter
(
bufMat
,
dst
,
dst
.
depth
(),
Size
(
size
,
size
),
Point
(
-
1
,
-
1
),
false
,
BORDER_CONSTANT
);
}
template
<>
void
LRNLayerImpl
::
sqrBoxFilter_
<
UMat
>
(
const
UMat
&
src
,
UMat
&
dst
)
{
cv
::
sqrBoxFilter
(
src
,
dst
,
dst
.
depth
(),
Size
(
size
,
size
),
Point
(
-
1
,
-
1
),
false
,
BORDER_CONSTANT
|
BORDER_ISOLATED
);
}
template
<
typename
XMat
>
template
<
typename
XMat
>
void
LRNLayerImpl
::
spatialNormalization_
(
Blob
&
srcBlob
,
Blob
&
dstBlob
)
void
LRNLayerImpl
::
spatialNormalization_
(
Blob
&
srcBlob
,
Blob
&
dstBlob
)
{
{
...
@@ -221,17 +235,7 @@ void LRNLayerImpl::spatialNormalization_(Blob &srcBlob, Blob &dstBlob)
...
@@ -221,17 +235,7 @@ void LRNLayerImpl::spatialNormalization_(Blob &srcBlob, Blob &dstBlob)
XMat
src
=
getPlane
(
srcMat
,
n
,
cn
);
XMat
src
=
getPlane
(
srcMat
,
n
,
cn
);
XMat
dst
=
getPlane
(
dstMat
,
n
,
cn
);
XMat
dst
=
getPlane
(
dstMat
,
n
,
cn
);
if
(
std
::
is_same
<
XMat
,
UMat
>::
value
)
sqrBoxFilter_
(
src
,
dst
);
{
cv
::
sqrBoxFilter
(
src
,
dst
,
dst
.
depth
(),
Size
(
size
,
size
),
Point
(
-
1
,
-
1
),
false
,
BORDER_CONSTANT
|
BORDER_ISOLATED
);
}
else
{
//TODO: fix cv::boxFilter with BORDER_ISOLATED flag in CPU mode
Mat
bufMat
=
buf
.
getRef
<
Mat
>
();
src
.
copyTo
(
bufMat
);
cv
::
sqrBoxFilter
(
bufMat
,
dst
,
dst
.
depth
(),
Size
(
size
,
size
),
Point
(
-
1
,
-
1
),
false
,
BORDER_CONSTANT
);
}
dst
.
convertTo
(
dst
,
dst
.
type
(),
alpha
/
(
size
*
size
),
1
);
dst
.
convertTo
(
dst
,
dst
.
type
(),
alpha
/
(
size
*
size
),
1
);
cv
::
pow
(
dst
,
beta
,
dst
);
cv
::
pow
(
dst
,
beta
,
dst
);
...
...
modules/dnn/src/layers/lrn_layer.hpp
View file @
942e9205
...
@@ -62,6 +62,8 @@ class LRNLayerImpl : public LRNLayer
...
@@ -62,6 +62,8 @@ class LRNLayerImpl : public LRNLayer
void
spatialNormalization
(
Blob
&
src
,
Blob
&
dst
);
void
spatialNormalization
(
Blob
&
src
,
Blob
&
dst
);
template
<
typename
XMat
>
template
<
typename
XMat
>
void
spatialNormalization_
(
Blob
&
src
,
Blob
&
dst
);
void
spatialNormalization_
(
Blob
&
src
,
Blob
&
dst
);
template
<
typename
XMat
>
void
sqrBoxFilter_
(
const
XMat
&
src
,
XMat
&
dst
);
public
:
public
:
...
...
modules/dnn/src/torch/torch_importer.cpp
View file @
942e9205
...
@@ -52,6 +52,12 @@ namespace dnn {
...
@@ -52,6 +52,12 @@ namespace dnn {
#if defined(ENABLE_TORCH_IMPORTER) && ENABLE_TORCH_IMPORTER
#if defined(ENABLE_TORCH_IMPORTER) && ENABLE_TORCH_IMPORTER
#include "THDiskFile.h"
#include "THDiskFile.h"
#ifdef NDEBUG
static
bool
dbgPrint
=
false
;
#else
static
bool
dbgPrint
=
true
;
#endif
enum
LuaType
enum
LuaType
{
{
TYPE_NIL
=
0
,
TYPE_NIL
=
0
,
...
@@ -290,6 +296,7 @@ struct TorchImporter : public ::cv::dnn::Importer
...
@@ -290,6 +296,7 @@ struct TorchImporter : public ::cv::dnn::Importer
}
}
String
key
=
readString
();
String
key
=
readString
();
if
(
dbgPrint
)
std
::
cout
<<
i
<<
"th key: "
<<
key
<<
"
\n
"
;
std
::
cout
<<
i
<<
"th key: "
<<
key
<<
"
\n
"
;
fpos
=
THFile_position
(
file
);
fpos
=
THFile_position
(
file
);
...
@@ -334,6 +341,8 @@ struct TorchImporter : public ::cv::dnn::Importer
...
@@ -334,6 +341,8 @@ struct TorchImporter : public ::cv::dnn::Importer
}
}
//Debug output
//Debug output
if
(
dbgPrint
)
{
std
::
cout
<<
"scalarParams:
\n
"
;
std
::
cout
<<
"scalarParams:
\n
"
;
std
::
cout
<<
scalarParams
;
std
::
cout
<<
scalarParams
;
...
@@ -342,6 +351,7 @@ struct TorchImporter : public ::cv::dnn::Importer
...
@@ -342,6 +351,7 @@ struct TorchImporter : public ::cv::dnn::Importer
for
(
it
=
tensorParams
.
begin
();
it
!=
tensorParams
.
end
();
it
++
)
for
(
it
=
tensorParams
.
begin
();
it
!=
tensorParams
.
end
();
it
++
)
std
::
cout
<<
it
->
first
<<
": Tensor "
<<
it
->
second
.
shape
()
<<
"
\n
"
;
std
::
cout
<<
it
->
first
<<
": Tensor "
<<
it
->
second
.
shape
()
<<
"
\n
"
;
}
}
}
void
readTorchTensor
(
int
indexTensor
,
int
typeTensor
)
void
readTorchTensor
(
int
indexTensor
,
int
typeTensor
)
{
{
...
@@ -435,6 +445,8 @@ struct TorchImporter : public ::cv::dnn::Importer
...
@@ -435,6 +445,8 @@ struct TorchImporter : public ::cv::dnn::Importer
String
className
=
readTorchClassName
();
String
className
=
readTorchClassName
();
String
nnName
;
String
nnName
;
if
(
dbgPrint
)
std
::
cout
<<
"Class: "
<<
className
<<
std
::
endl
;
std
::
cout
<<
"Class: "
<<
className
<<
std
::
endl
;
int
type
;
int
type
;
...
...
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