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
Lozac'h Loic
otbtf
Commits
b5d53231
Commit
b5d53231
authored
Aug 03, 2018
by
remi cresson
Browse files
ENH: better exception messages
parent
5c0ec1a9
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/otbTensorflowMultisourceModelBase.h
View file @
b5d53231
...
...
@@ -108,6 +108,8 @@ protected:
TensorflowMultisourceModelBase
();
virtual
~
TensorflowMultisourceModelBase
()
{};
virtual
std
::
stringstream
GenerateDebugReport
(
DictListType
&
inputs
,
TensorListType
&
outputs
);
virtual
void
RunSession
(
DictListType
&
inputs
,
TensorListType
&
outputs
);
private:
...
...
include/otbTensorflowMultisourceModelBase.hxx
View file @
b5d53231
...
...
@@ -32,6 +32,40 @@ TensorflowMultisourceModelBase<TInputImage, TOutputImage>
m_InputPlaceholdersNames
.
push_back
(
placeholder
);
}
template
<
class
TInputImage
,
class
TOutputImage
>
std
::
stringstream
TensorflowMultisourceModelBase
<
TInputImage
,
TOutputImage
>
::
GenerateDebugReport
(
DictListType
&
inputs
,
TensorListType
&
outputs
)
{
// Create a debug report
std
::
stringstream
debugReport
;
// Describe the output buffered region
ImagePointerType
outputPtr
=
this
->
GetOutput
();
const
RegionType
outputReqRegion
=
outputPtr
->
GetRequestedRegion
();
debugReport
<<
"Output image buffered region: "
<<
outputReqRegion
<<
"
\n
"
;
// Describe inputs
for
(
unsigned
int
i
=
0
;
i
<
this
->
GetNumberOfInputs
()
;
i
++
)
{
const
ImagePointerType
inputPtr
=
const_cast
<
TInputImage
*>
(
this
->
GetInput
(
i
));
const
RegionType
reqRegion
=
inputPtr
->
GetRequestedRegion
();
debugReport
<<
"Input #"
<<
i
<<
":
\n
"
;
debugReport
<<
"Requested region: "
<<
reqRegion
<<
"
\n
"
;
debugReport
<<
"Tensor shape (
\"
"
<<
inputs
[
i
].
first
<<
"
\"
: "
<<
tf
::
PrintTensorShape
(
inputs
[
i
].
second
.
shape
())
<<
"
\n
"
;
}
// Show user placeholders
debugReport
<<
"User placeholders:
\n
"
;
for
(
auto
&
dict
:
this
->
GetUserPlaceholders
())
{
debugReport
<<
dict
.
first
<<
" "
<<
tf
::
PrintTensorInfos
(
dict
.
second
)
<<
"
\n
"
<<
std
::
endl
;
}
return
debugReport
;
}
template
<
class
TInputImage
,
class
TOutputImage
>
void
TensorflowMultisourceModelBase
<
TInputImage
,
TOutputImage
>
...
...
@@ -52,29 +86,7 @@ TensorflowMultisourceModelBase<TInputImage, TOutputImage>
if
(
!
status
.
ok
())
{
// Create a debug report
std
::
stringstream
debugReport
;
// Describe the output buffered region
ImagePointerType
outputPtr
=
this
->
GetOutput
();
const
RegionType
outputReqRegion
=
outputPtr
->
GetRequestedRegion
();
debugReport
<<
"Output image buffered region: "
<<
outputReqRegion
<<
"
\n
"
;
// Describe inputs
for
(
unsigned
int
i
=
0
;
i
<
this
->
GetNumberOfInputs
()
;
i
++
)
{
const
ImagePointerType
inputPtr
=
const_cast
<
TInputImage
*>
(
this
->
GetInput
(
i
));
const
RegionType
reqRegion
=
inputPtr
->
GetRequestedRegion
();
debugReport
<<
"Input #"
<<
i
<<
":
\n
"
;
debugReport
<<
"Requested region: "
<<
reqRegion
<<
"
\n
"
;
debugReport
<<
"Tensor shape (
\"
"
<<
inputs
[
i
].
first
<<
"
\"
: "
<<
tf
::
PrintTensorShape
(
inputs
[
i
].
second
.
shape
())
<<
"
\n
"
;
}
// Show user placeholders
debugReport
<<
"User placeholders:
\n
"
;
for
(
auto
&
dict
:
this
->
GetUserPlaceholders
())
{
debugReport
<<
dict
.
first
<<
" "
<<
tf
::
PrintTensorInfos
(
dict
.
second
)
<<
"
\n
"
<<
std
::
endl
;
}
std
::
stringstream
debugReport
=
GenerateDebugReport
(
inputs
,
outputs
);
// Throw an exception with the report
itkExceptionMacro
(
"Can't run the tensorflow session !
\n
"
<<
...
...
include/otbTensorflowMultisourceModelFilter.hxx
View file @
b5d53231
...
...
@@ -454,7 +454,18 @@ TensorflowMultisourceModelFilter<TInputImage, TOutputImage>
// The offset (i.e. the starting index of the channel for the output tensor) is updated
// during this call
// TODO: implement a generic strategy enabling FOE copy in patch-based mode (see tf::CopyTensorToImageRegion)
tf
::
CopyTensorToImageRegion
<
TOutputImage
>
(
outputs
[
i
],
outputAlignedReqRegion
,
outputPtr
,
outputReqRegion
,
bandOffset
);
try
{
tf
::
CopyTensorToImageRegion
<
TOutputImage
>
(
outputs
[
i
],
outputAlignedReqRegion
,
outputPtr
,
outputReqRegion
,
bandOffset
);
}
catch
(
itk
::
ExceptionObject
&
err
)
{
std
::
stringstream
debugMsg
=
this
->
GenerateDebugReport
(
inputs
,
outputs
);
itkExceptionMacro
(
"Error occured during tensor to image conversion.
\n
"
<<
"Context: "
<<
debugMsg
.
str
()
<<
"Error:"
<<
err
);
}
}
}
...
...
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