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

Optimize graph & graph transform tools do not support NCHW #15034

Closed
khanrc opened this issue Dec 1, 2017 · 5 comments · Fixed by #16075
Closed

Optimize graph & graph transform tools do not support NCHW #15034

khanrc opened this issue Dec 1, 2017 · 5 comments · Fixed by #16075
Assignees
Labels

Comments

@khanrc
Copy link

khanrc commented Dec 1, 2017

I tried optimizing graph using both Graph transform tool and Optimize graph for inference. Both cases produced the same error because the fused batchnorm used not NCHW, but NHWC. I've got the error like this:

InvalidArgumentError (see above for traceback): Must provide as many biases as the channel dimension of the input tensor: [256] vs. 19 in [1,256,19,19]
	 [[Node: prefix/convblock/BatchNorm/FusedBatchNorm = BiasAdd[T=DT_FLOAT, data_format="NHWC", _device="/job:localhost/replica:0/task:0/device:GPU:0"](prefix/convblock/Conv2D, prefix/convblock/Conv2D_bn_offset)]

Although NCHW is faster than NHWC in GPU environment, why the tools do not support NCHW?

@aselle
Copy link
Contributor

aselle commented Dec 1, 2017

Could you provide a reproducible test case of what exactly you tried to do? Generally speaking, I think a lot of the tooling after training requires NHWC, as that was the only format when those were written. If you could provide a reproducible test case, we could work to improve it. @petewarden, do you have any other comments?

@aselle aselle added stat:awaiting response Status - Awaiting response from author type:bug Bug labels Dec 1, 2017
@khanrc
Copy link
Author

khanrc commented Dec 4, 2017

I tried:

python tensorflow/python/tools/optimize_for_inference.py \
--input ./ckpt/frozen_model.pb \
--output ./ckpt/optimized_model.pb \
--frozen_graph true \
--input_names Placeholder \
--output_names policy_head/softmax,value_head/value/Tanh

and

tensorflow/bazel-bin/tensorflow/tools/graph_transforms/transform_graph \
--in_graph='./ckpt/frozen_model.pb' \
--out_graph='./ckpt/transformed_model.pb' \
--inputs='Placeholder' \
--outputs='policy_head/softmax,value_head/value/Tanh' \
--transforms='
fold_constants(ignore_errors=true)
fold_batch_norms
fold_old_batch_norms
fuse_pad_and_conv
fuse_resize_and_conv
fuse_resize_pad_and_conv
'

In both cases, the error occurred in fused batchnorm. The frozen model worked well, but the optimized model and transformed model emitted error.

@aselle aselle removed the stat:awaiting response Status - Awaiting response from author label Dec 4, 2017
@tensorflowbutler
Copy link
Member

It has been 14 days with no activity and this issue has an assignee.Please update the label and/or status accordingly.

@tensorflowbutler
Copy link
Member

Nagging Assigneee: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.

@tensorflowbutler
Copy link
Member

Nagging Assignee: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants