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
5ba8aa78
Commit
5ba8aa78
authored
May 07, 2019
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14460 from dkurt:dnn_tf_no_extra_clone
parents
455323ed
a6ed8f26
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
15 deletions
+19
-15
tf_graph_simplifier.cpp
modules/dnn/src/tensorflow/tf_graph_simplifier.cpp
+16
-12
tf_graph_simplifier.hpp
modules/dnn/src/tensorflow/tf_graph_simplifier.hpp
+1
-1
tf_importer.cpp
modules/dnn/src/tensorflow/tf_importer.cpp
+2
-2
No files found.
modules/dnn/src/tensorflow/tf_graph_simplifier.cpp
View file @
5ba8aa78
...
...
@@ -770,43 +770,47 @@ void RemoveIdentityOps(tensorflow::GraphDef& net)
}
}
Mat
getTensorContent
(
const
tensorflow
::
TensorProto
&
tensor
)
Mat
getTensorContent
(
const
tensorflow
::
TensorProto
&
tensor
,
bool
copy
)
{
const
std
::
string
&
content
=
tensor
.
tensor_content
();
Mat
m
;
switch
(
tensor
.
dtype
())
{
case
tensorflow
:
:
DT_FLOAT
:
{
if
(
!
content
.
empty
())
return
Mat
(
1
,
content
.
size
()
/
sizeof
(
float
),
CV_32FC1
,
(
void
*
)
content
.
c_str
()).
clone
(
);
m
=
Mat
(
1
,
content
.
size
()
/
sizeof
(
float
),
CV_32FC1
,
(
void
*
)
content
.
c_str
()
);
else
{
const
RepeatedField
<
float
>&
field
=
tensor
.
float_val
();
CV_Assert
(
!
field
.
empty
());
return
Mat
(
1
,
field
.
size
(),
CV_32FC1
,
(
void
*
)
field
.
data
()).
clone
(
);
m
=
Mat
(
1
,
field
.
size
(),
CV_32FC1
,
(
void
*
)
field
.
data
()
);
}
break
;
}
case
tensorflow
:
:
DT_DOUBLE
:
{
if
(
!
content
.
empty
())
return
Mat
(
1
,
content
.
size
()
/
sizeof
(
double
),
CV_64FC1
,
(
void
*
)
content
.
c_str
()).
clone
(
);
m
=
Mat
(
1
,
content
.
size
()
/
sizeof
(
double
),
CV_64FC1
,
(
void
*
)
content
.
c_str
()
);
else
{
const
RepeatedField
<
double
>&
field
=
tensor
.
double_val
();
CV_Assert
(
!
field
.
empty
());
return
Mat
(
1
,
field
.
size
(),
CV_64FC1
,
(
void
*
)
field
.
data
()).
clone
(
);
m
=
Mat
(
1
,
field
.
size
(),
CV_64FC1
,
(
void
*
)
field
.
data
()
);
}
break
;
}
case
tensorflow
:
:
DT_INT32
:
{
if
(
!
content
.
empty
())
return
Mat
(
1
,
content
.
size
()
/
sizeof
(
int32_t
),
CV_32SC1
,
(
void
*
)
content
.
c_str
()).
clone
(
);
m
=
Mat
(
1
,
content
.
size
()
/
sizeof
(
int32_t
),
CV_32SC1
,
(
void
*
)
content
.
c_str
()
);
else
{
const
RepeatedField
<
int32_t
>&
field
=
tensor
.
int_val
();
CV_Assert
(
!
field
.
empty
());
return
Mat
(
1
,
field
.
size
(),
CV_32SC1
,
(
void
*
)
field
.
data
()).
clone
(
);
m
=
Mat
(
1
,
field
.
size
(),
CV_32SC1
,
(
void
*
)
field
.
data
()
);
}
break
;
}
case
tensorflow
:
:
DT_HALF
:
{
...
...
@@ -825,20 +829,20 @@ Mat getTensorContent(const tensorflow::TensorProto &tensor)
}
// Reinterpret as a signed shorts just for a convertFp16 call.
Mat
halfsSigned
(
halfs
.
size
(),
CV_16SC1
,
halfs
.
data
);
Mat
floats
(
halfs
.
size
(),
CV_32FC1
);
convertFp16
(
halfsSigned
,
floats
);
return
floats
;
convertFp16
(
halfsSigned
,
m
);
break
;
}
case
tensorflow
:
:
DT_QUINT8
:
{
CV_Assert
(
!
content
.
empty
());
return
Mat
(
1
,
content
.
size
(),
CV_8UC1
,
(
void
*
)
content
.
c_str
()).
clone
();
m
=
Mat
(
1
,
content
.
size
(),
CV_8UC1
,
(
void
*
)
content
.
c_str
());
break
;
}
default:
CV_Error
(
Error
::
StsError
,
"Tensor's data type is not supported"
);
break
;
}
return
Mat
()
;
return
copy
?
m
.
clone
()
:
m
;
}
void
releaseTensor
(
tensorflow
::
TensorProto
*
tensor
)
...
...
modules/dnn/src/tensorflow/tf_graph_simplifier.hpp
View file @
5ba8aa78
...
...
@@ -21,7 +21,7 @@ void RemoveIdentityOps(tensorflow::GraphDef& net);
void
simplifySubgraphs
(
tensorflow
::
GraphDef
&
net
);
Mat
getTensorContent
(
const
tensorflow
::
TensorProto
&
tensor
);
Mat
getTensorContent
(
const
tensorflow
::
TensorProto
&
tensor
,
bool
copy
=
true
);
void
releaseTensor
(
tensorflow
::
TensorProto
*
tensor
);
...
...
modules/dnn/src/tensorflow/tf_importer.cpp
View file @
5ba8aa78
...
...
@@ -109,7 +109,7 @@ void parseTensor(const tensorflow::TensorProto &tensor, Mat &dstBlob)
dstBlob
.
create
(
shape
,
CV_32F
);
Mat
tensorContent
=
getTensorContent
(
tensor
);
Mat
tensorContent
=
getTensorContent
(
tensor
,
/*no copy*/
false
);
int
size
=
tensorContent
.
total
();
CV_Assert
(
size
==
(
int
)
dstBlob
.
total
());
...
...
@@ -509,7 +509,7 @@ void TFImporter::kernelFromTensor(const tensorflow::TensorProto &tensor, Mat &ds
dstBlob
.
create
(
shape
,
CV_32F
);
Mat
tensorContent
=
getTensorContent
(
tensor
);
Mat
tensorContent
=
getTensorContent
(
tensor
,
/*no copy*/
false
);
int
size
=
tensorContent
.
total
();
CV_Assert
(
size
==
(
int
)
dstBlob
.
total
());
...
...
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