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

TF 2.0 not support #700

Open duguqiankun opened 5 years ago

duguqiankun commented 5 years ago

Platform (like ubuntu 16.04/win10):

Python version:

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

Destination framework with version (like CNTK 2.3 with GPU):

Pre-trained model path (webpath or webdisk path):

Running scripts:

linmajia commented 5 years ago

@duguqiankun , thank you very much for the feedback. TensorFlow 2.0 is not officially released yet now. We will support it in future.

Harmageddon commented 4 years ago

Hi! This library looks promising. As TF2.0 has been officially released for some time, do you have concrete plans regarding the support?

xingbod commented 4 years ago

I successfully converted mxnet into TF2.0 model, the main idea is:

  1. firstly convert mxnet into IR
  2. generate keras code based on IR file
  3. Debug and modify the keras file, enbale tf2 running. (It is worth to note that TF2 comes with a native keras support, so you don't need to do so much modifications, just use the tf's keras and it will be ready.)

I have a blog which is in Chinese[中文],in this blog post, I convert mxnet model trained by InsightFace team, into TF2 model. Maybe it can help some guys. Here is the link: https://firstai.blog.csdn.net/article/details/108628300

craymichael commented 3 years ago

Hi, I forked this repository and added the tf-keras backend/framework. This is simply a port of keras to tf.keras and works with weights in HDF5 format. It seems to be working fine in TensorFlow 2.0, at least for my needs.

Example usage:

from tensorflow.keras import layers, Model
from tensorflow.keras.models import save_model
inp = layers.Input([10, 10, 3])
x = layers.Conv2D(5, 3)(inp)
x = layers.Flatten()(x)
x = layers.Dense(5)(x)
x = layers.Softmax()(x)
m = Model(inp, x)
save_model(m, 'model.h5', save_format='h5')  # cannot be in frozen graph format

To convert:

mmconvert -sf tf-keras -iw model.h5 -df pytorch -om model.pt

This yields the files model.pt and model.py.

Loading:

import torch
import imp

MainModel = imp.load_source('MainModel', 'model.py')
model = torch.load('model.pt')

Eval:

>>> model.eval()
KitModel(
  (conv2d): Conv2d(3, 5, kernel_size=(3, 3), stride=(1, 1))
  (dense): Linear(in_features=320, out_features=5, bias=True)
)

My Versions:

>>> import tensorflow as tf; import torch
>>> tf.__version__
'2.1.3'
>>> torch.__version__
'1.3.1'

craymichael/MMdnn