microsoft / MMdnn

MMdnn is a set of tools to help users inter-operate among different deep learning frameworks. E.g. model conversion and visualization. Convert models between Caffe, Keras, MXNet, Tensorflow, CNTK, PyTorch Onnx and CoreML.
MIT License
5.8k stars 965 forks source link

Fail to convert a TF model to caffe2 or Pytorch #490

Open bwang482 opened 6 years ago

bwang482 commented 6 years ago

Platform (like ubuntu 16.04/win10): Ubuntu 16.04

Python version: Python 3.5.5

Source framework with version (like Tensorflow 1.4.1 with GPU): Tensorflow 1.10.1 with GPU

Destination framework with version (like CNTK 2.3 with GPU): Caffe2 with CPU / Pytorch 0.4.1 with GPU

Pre-trained model path (webpath or webdisk path): No web path. It is a pre-trained cnn model in tensorflow

Error:

aaa@aaa:$ mmconvert -sf tensorflow -in cnn_tree.ckpt-51243.meta -iw cnn_tree.ckpt-51243 --dstNodeName output/Softmax -df pytorch -om tf2pytorch
/anaconda/envs/py35/lib/python3.5/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Parse file [cnn_tree.ckpt-51243.meta] with binary format successfully.
Tensorflow model file [cnn_tree.ckpt-51243.meta] loaded successfully.
Tensorflow checkpoint file [cnn_tree.ckpt-51243] loaded successfully. [21] variables loaded.
Tensorflow has not supported operator [Cast] with name [network/conv_layer/conv_node/conv_step/coefficients/coef_r/Cast].
Tensorflow has not supported operator [Cast] with name [network/conv_layer/conv_node/conv_step/coefficients/coef_l/Cast].
Tensorflow has not supported operator [Less] with name [network/conv_layer/conv_node/conv_step/combine/Tensordot/Less].
Tensorflow has not supported operator [ExpandDims] with name [network/conv_layer/conv_node/conv_step/trees/children_tensor/ExpandDims].
Tensorflow has not supported operator [ExpandDims] with name [network/conv_layer/conv_node/conv_step/trees/ExpandDims].
Tensorflow has not supported operator [GreaterEqual] with name [network/conv_layer/conv_node/conv_step/combine/Tensordot/GreaterEqual].
Tensorflow has not supported operator [Range] with name [network/conv_layer/conv_node/conv_step/combine/Tensordot/range].
Tensorflow has not supported operator [NotEqual] with name [network/conv_layer/conv_node/conv_step/coefficients/coef_r/count_nonzero/NotEqual].
Tensorflow has not supported operator [Cast] with name [network/conv_layer/conv_node/conv_step/combine/Tensordot/Cast_1].
Tensorflow has not supported operator [Cast] with name [network/conv_layer/conv_node/conv_step/combine/Tensordot/Cast].
Tensorflow has not supported operator [Cast] with name [network/conv_layer/conv_node/conv_step/coefficients/coef_r/count_nonzero/ToInt64].
Tensorflow has not supported operator [Fill] with name [network/conv_layer/conv_node/conv_step/coefficients/coef_r/ones].
Tensorflow has not supported operator [Fill] with name [network/conv_layer/conv_node/conv_step/coefficients/coef_l/ones].
Traceback (most recent call last):
  File "/home/ccrmad/.local/bin/mmconvert", line 11, in <module>
    sys.exit(_main())
  File "/home/ccrmad/.local/lib/python3.5/site-packages/mmdnn/conversion/_script/convert.py", line 102, in _main
    ret = convertToIR._convert(ir_args)
  File "/home/ccrmad/.local/lib/python3.5/site-packages/mmdnn/conversion/_script/convertToIR.py", line 115, in _convert
    parser.run(args.dstPath)
  File "/home/ccrmad/.local/lib/python3.5/site-packages/mmdnn/conversion/common/DataStructure/parser.py", line 22, in run
    self.gen_IR()
  File "/home/ccrmad/.local/lib/python3.5/site-packages/mmdnn/conversion/tensorflow/tensorflow_parser.py", line 309, in gen_IR
    func(current_node)
  File "/home/ccrmad/.local/lib/python3.5/site-packages/mmdnn/conversion/tensorflow/tensorflow_parser.py", line 703, in rename_Mul
    shape = shape[-1]
IndexError: list index out of range

There are a lot of not supported operators, and thus the reason the failure?

rainLiuplus commented 6 years ago

Hi @bluemonk482 , could you please provide your model?

bwang482 commented 6 years ago

@rainLiuplus Thanks for your reply! Here is the saved weights and graph of the model: https://www.dropbox.com/s/7j3d0zptjl8qo0h/cnn_tree.ckpt-51243.zip?dl=0

It is pretty small.

chungyau97 commented 5 years ago

@rainLiuplus @bluemonk482 How to convert it to pytorch? I'm using original author pretrained-model. mmconvert -sf tensorflow -in model-20180402-114759.meta -iw model-20180402-114759.ckpt-275.index --dstNodeName embeddings -df pytorch -om 20180402-114759.pth

Error: image

spaul13 commented 5 years ago

Anyone successfully able to convert tensorflow to caffe2?

I am getting the following error while conversion. Can anyone plz tell me how to resolve this error?

_paul90@cloud8:/export1/paul90/new_tensorflow/tensorflow$ mmconvert -sf tensorflow -in sp_birnn_ckpt/sp_model.ckpt.meta -iw sp_birnn_ckpt/sp_model.ckpt.index --dstNodeName GradientDescent -df caffe2 -om tf2Caffe2 TensorflowEmitter has not supported operator [StopGradient] with name [softmax_cross_entropy_with_logits_sg/labels_stop_gradient]. TensorflowEmitter has not supported operator [NoOp] with name [GradientDescent]. Traceback (most recent call last): File "/home/paul90/.local/bin/mmconvert", line 11, in sys.exit(_main()) File "/home/paul90/.local/lib/python2.7/site-packages/mmdnn/conversion/_script/convert.py", line 102, in _main ret = convertToIR._convert(ir_args) File "/home/paul90/.local/lib/python2.7/site-packages/mmdnn/conversion/_script/convertToIR.py", line 115, in _convert parser.run(args.dstPath) File "/home/paul90/.local/lib/python2.7/site-packages/mmdnn/conversion/common/DataStructure/parser.py", line 22, in run self.gen_IR() File "/home/paul90/.local/lib/python2.7/site-packages/mmdnn/conversion/tensorflow/tensorflow_parser.py", line 424, in gen_IR func(current_node) File "/home/paul90/.local/lib/python2.7/site-packages/mmdnn/conversion/tensorflow/tensorflow_parser.py", line 967, in rename_Slice shape = tensor_util.MakeNdarray(shape).tolist() File "/home/paul90/.local/lib/python2.7/site-packages/tensorflow/python/framework/tensor_util.py", line 597, in MakeNdarray tensor_dtype = dtypes.as_dtype(tensor.dtype) File "/home/paul90/.local/lib/python2.7/site-packages/tensorflow/python/framework/dtypes.py", line 719, in as_dtype raise TypeError("Cannot convert value %r to a TensorFlow DType." % typevalue) TypeError: Cannot convert value 0 to a TensorFlow DType.

grapefruitL commented 5 years ago

@spaul13 hi ! i got the same err on my mtcnn-tf-model2caffe work did you solve the problem ?

bin9000 commented 5 years ago

@grapefruitL I got the same problem and I solved. Try to install mmdnn again, following this website https://github.com/microsoft/MMdnn

bitwangdan commented 4 years ago

@spaul13 @grapefruitL hi, i got the same err, did you solve the problem ?