Created by: luotao1
fix #8715 (closed) (inspired by https://github.com/tensorflow/tensorflow/pull/10366)