Skip to content
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 SpaceToDepth in frontend #183

Merged
merged 4 commits into from
May 21, 2018
Merged

Conversation

ruimashita
Copy link
Contributor

Add SpaceToDepth in frontend

@CLAassistant
Copy link

CLAassistant commented May 18, 2018

CLA assistant check
All committers have signed the CLA.

@tjingrant
Copy link
Collaborator

@ruimashita looks like there's an additional CI error caused by SpaceToDepth:

ERROR: test_space_to_depth (frontend.test_node.TestNode)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/onnx/onnx-tensorflow/test/frontend/test_node.py", line 86, in do_test_expected
    tf_output = sess.run(test_op, tf_feed_dict)
  File "/home/travis/virtualenv/python2.7.14/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 900, in run
    run_metadata_ptr)
  File "/home/travis/virtualenv/python2.7.14/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1135, in _run
    feed_dict_tensor, options, run_metadata)
  File "/home/travis/virtualenv/python2.7.14/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1316, in _do_run
    run_metadata)
  File "/home/travis/virtualenv/python2.7.14/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1335, in _do_call
    raise type(e)(node_def, op, message)
InvalidArgumentError: Only NHWC data_format supported on CPU. Got NCHW
	 [[Node: SpaceToDepth = SpaceToDepth[T=DT_FLOAT, block_size=2, data_format="NCHW", _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_in_0_0_0)]]
Caused by op u'SpaceToDepth', defined at:
  File "/opt/python/2.7.14/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/opt/python/2.7.14/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/opt/python/2.7.14/lib/python2.7/unittest/__main__.py", line 12, in <module>
    main(module=None)
  File "/opt/python/2.7.14/lib/python2.7/unittest/main.py", line 95, in __init__
    self.runTests()
  File "/opt/python/2.7.14/lib/python2.7/unittest/main.py", line 232, in runTests
    self.result = testRunner.run(self.test)
  File "/opt/python/2.7.14/lib/python2.7/unittest/runner.py", line 151, in run
    test(result)
  File "/opt/python/2.7.14/lib/python2.7/unittest/suite.py", line 70, in __call__
    return self.run(*args, **kwds)
  File "/opt/python/2.7.14/lib/python2.7/unittest/suite.py", line 108, in run
    test(result)
  File "/opt/python/2.7.14/lib/python2.7/unittest/suite.py", line 70, in __call__
    return self.run(*args, **kwds)
  File "/opt/python/2.7.14/lib/python2.7/unittest/suite.py", line 108, in run
    test(result)
  File "/opt/python/2.7.14/lib/python2.7/unittest/suite.py", line 70, in __call__
    return self.run(*args, **kwds)
  File "/opt/python/2.7.14/lib/python2.7/unittest/suite.py", line 108, in run
    test(result)
  File "/opt/python/2.7.14/lib/python2.7/unittest/case.py", line 393, in __call__
    return self.run(*args, **kwds)
  File "/opt/python/2.7.14/lib/python2.7/unittest/case.py", line 329, in run
    testMethod()
  File "/home/travis/build/onnx/onnx-tensorflow/test/frontend/test_node.py", line 67, in do_test_expected
    test_op = tf_op(*tf_param_list, **attrs)
  File "/home/travis/virtualenv/python2.7.14/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 2332, in space_to_depth
    return gen_array_ops.space_to_depth(input, block_size, data_format, name=name)
  File "/home/travis/virtualenv/python2.7.14/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 7638, in space_to_depth
    data_format=data_format, name=name)
  File "/home/travis/virtualenv/python2.7.14/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/travis/virtualenv/python2.7.14/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
    op_def=op_def)
  File "/home/travis/virtualenv/python2.7.14/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1718, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access
InvalidArgumentError (see above for traceback): Only NHWC data_format supported on CPU. Got NCHW
	 [[Node: SpaceToDepth = SpaceToDepth[T=DT_FLOAT, block_size=2, data_format="NCHW", _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_in_0_0_0)]]

@ruimashita
Copy link
Contributor Author

@tjingrant
Basically, The problem is design of frontend test, I think.
The above error cause from tensorflow CPU implementation, the error don't cause on GPU. If I want to pass the NCHW test, I have to hard work to implement tensorflow itself.
To avoid these situation, Ideally frontend test should be aside from tensorflow implementation. Frontend test divide from backend, and then we should create new integrate test front and back, I think.

But, It is hard for me to re-design frontend test.
To resolove the error realistic, I rewrote SpaceToDepth and the test.
Please review it.

transpose_unique_suffix = get_unique_suffix()
space_to_depth_unique_suffix = get_unique_suffix()
transpose_name = node.inputs[0] + "_T_" + transpose_unique_suffix
space_to_depth_name = node.inputs[0] + "_STD_" + space_to_depth_unique_suffix
Copy link
Collaborator

@fumihwh fumihwh May 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space_to_depth_name should be based on transpose_name
Or we should clearify the input is transposed. _T_STD_

before_transpose_node = helper.make_node(
"Transpose",
[node.inputs[0]], [transpose_name],
perm=[0, 3, 1, 2])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe could use get_perm_from_formats in backend.py

after_transpose_node = helper.make_node(
"Transpose",
[space_to_depth_name], [node.name],
perm=[0, 2, 3, 1])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here.

@ruimashita
Copy link
Contributor Author

@fumihwh
Thanks for comments.
I fixed.

@tjingrant
Copy link
Collaborator

@ruimashita thanks, we haven't really started to deal with the data format issue in the frontend, sorry that you have to worry about that issue..

@tjingrant tjingrant merged commit cd3768e into onnx:master May 21, 2018
@ruimashita
Copy link
Contributor Author

@tjingrant
Thanks a lot for your leads and managements of this open source.

@ruimashita ruimashita deleted the space_to_depth branch May 22, 2018 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants