-
Notifications
You must be signed in to change notification settings - Fork 823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Upsample op in CAFFE #625
Open
gasgallo
wants to merge
1
commit into
XiaoMi:master
Choose a base branch
from
gasgallo:feature/support-caffe-upsample
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review.
Thanks for your wonderful code, but as you know, we can not modify the caffe code and maintain a nonstandard version, perhaps we can make this pull request stay here and help the others, but it can not be merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about keeping the original Dockerfile as it was and create a
Dockerfile-upsample
that contains the patched version?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gasgallo I read the code and had a question, how about developping a
ResizeNearestNeighbor
op in caffe like in tensorflow? or developping aUpSample
op like in ONNX, in that cases, there are no need to change the mace's code?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lu229 can you elaborate? I'm not sure I understand what you mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gasgallo MACE support the
UpSample
operator for ONNX, and supportResizeNearestNeighbor
operator for Tensorflow, What I means is that, If you simulatedUpSample
op in CAFFE like in the ONNX, or simulatedResizeNearestNeighbor
op in CAFFE likein the Tensorflow, there is no need to modify MACE's c++ code(only need to modify the python code for convert). I think perhaps this is a better selection?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gasgallo Perhaps I did not understand your problem, why dose you need calling shape_inference before convert_ops? The shape inferences in ONNX and caffe and tensorflow are different, I think if you add the op in caffe, perhaps you need add it as the same the other caffe operators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lu229 because current caffe upsample layer is like onnx one, that provides a scale factor, therefore we need to know upsample input size to calculate its output size that is required by MACE resizenearestneighbor op.
The other option is that caffe upsample layer directly provides output shape, like happens in tf.image.resize_nearest_neighbor.
I was wondering if the first solution would work? If not, I will consider the second option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gasgallo Perhaps I still did not understand your problem, but I can try to reply. Yes you can refer to the
infer_shape_conv_pool_shape
function intools/python/transform/shape_inference.py
, which is used to infer the output shape ofconv
operator, when you infer theUpsample
's output shape, you can get the input shape by the_output_shape_cache
variable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lu229 sorry for confusion, I'll write more in detail right now.
My CAFFE upsample op is defined in a similar way as ONNX upsample op, that takes a
scale
parameter, so we don't know output shape a priori. For MACE we need to know output shape when callingself.add_tensor
.This works in
onnx_converter.py
because we can useself._graph_shapes_dict
object that contains all pre-computed shapes, and it is created inself.extract_shape_info
before callingself.convert_ops
.This is
convert_upsample
inonnx_converter.py
:And this is
run()
inonnx_converter.py
:In
caffe_converter.py
instead,shape_inferer.run()
is called afterself.convert_ops
, therefore all output shapes are not available during ops conversion, so I cannot compute output shape of upsample op.This is
run()
incaffe_converter.py
:And
shape_inferer.run()
cannot be called beforeself.convert_ops
because it requiresself._mace_net_def
to be already completely defined (that happens inself.convert_ops
).@lu229 Let me know if this makes my point clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gasgallo Thanks for your detailed description, now I understand your problem, yes you need to define the upsample as same as the other
Caffe
operators, for the shape inference inCaffe
andONNX
is different.