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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in conversion from Tensorflow Model to CNTK Model

coolrishi2005 opened this issue · comments

I have used the code at the link (https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/4_Utils/save_restore_model.py) to create and store a model in tensorflow.

I am converting the saved tensorflow model to cntk using the steps mentioned in MMdnn. At the final step of convresion, i.e. while generating CNTK Model from CNTK Code Snippet, I am getting some error.

Following is the traceback:

(C:\Program Files\Anaconda3\envs\py35) MMdnn-master\mmdnn\conversion\cntk>python -m mmdnn.conversion.examples.cntk.imagenet_test -n cntkModel_3_5.py -w IRModel_3_5.npy --dump cntkModel_3_5.dnn
Traceback (most recent call last):
File "C:\Program Files\Anaconda3\envs\py35\lib\runpy.py", line 184, in _run_mo
dule_as_main
"main", mod_spec)
File "C:\Program Files\Anaconda3\envs\py35\lib\runpy.py", line 85, in _run_cod
e
exec(code, run_globals)
File "C:\Program Files\Anaconda3\envs\py35\lib\site-packages\mmdnn\conversion
examples\cntk\imagenet_test.py", line 57, in
tester = TestCNTK()
File "C:\Program Files\Anaconda3\envs\py35\lib\site-packages\mmdnn\conversion
examples\cntk\imagenet_test.py", line 17, in init
super(TestCNTK, self).init()
File "C:\Program Files\Anaconda3\envs\py35\lib\site-packages\mmdnn\conversion
examples\imagenet_test.py", line 104, in init
self.MainModel = import(self.args.n)
File "D:\Rishi\Machine Learning\CNTK\MMdnn-master\mmdnn\conversion\cntk\cntkMo
del_3_5.py", line 31
Reshape_1 = cntk.reshape(Placeholder_1, shape = (,) name = 'Reshape_1'
)
^
SyntaxError: invalid syntax

Hi @coolrishi2005,
Thanks for helping test the converter. Tensorflow converter is in very initial state, any question and issue is welcome.

Fix some bugs and seems it works. Tensorflow -> IR command (step 1) is

python -m mmdnn.conversion._script.convertToIR -node add -f tensorflow -d IRModel_3_5 -n /tmp/model.ckpt.meta -w /tmp/model.ckpt

Note: Please specify the output node of tensorflow model, which can help the converter trims useless nodes. like -node add in above command.

For this model, we can get the output node from codes:

code

or from tensorboard

tensorboard

Thanks.

Thanks kitstar for the response.
The model has been converted successfully now from tf -> cntk.
The issue was due to those useless nodes only, which got trimmed while generating IR Code from tf.

hi there, i'm trying to convert a transformer model that is trained with tf to cntk model. I get the following error.

image

it seems it's not recognizing the attention layer. is there any way to get around that?

Hi @mhajiaghayi , could you please provide your model files?

hi namizz, how would you like me to send it to you? it's 800meg.

Hi @mhajiaghayi , any free cloud storage is ok.

hi @namizzz , you can find the model here https://1drv.ms/f/s!AqysHcfYW1hSgc57psU_Bh8MDND74A and I used the following script to convert it

mmconvert -sf tensorflow -in checkpoints\model-0.meta -iw checkpoints\model-0 --dstNodeName output/fwside1/fwside1/fully_connected/Relu -df cntk -om cntk-model

Hi @mhajiaghayi , MMdnn doesn't support RNN network now. Sorry,thanks!

hi @namizzz, would you please look at this model located in https://1drv.ms/f/s!AqysHcfYW1hSgc8KG_BnQRrwT7vCJA? . This model doesn't use any RNN or attention layer.
mmconvert -sf tensorflow -in checkpoints\model-0.meta -iw checkpoints\model-0 --dstNodeName output/fwside1/fwside1/fully_connected/Relu -df cntk -om cntk-model