update for tensorflow v2 compatibility#917
update for tensorflow v2 compatibility#917vladmandic wants to merge 1 commit intomicrosoft:masterfrom
Conversation
Doch88
left a comment
There was a problem hiding this comment.
It makes it usable with TensorFlow 2. However, it can still only be used with TensorFlow 1 models. So, the name "update for TensorFlow v2 compatibility" is not so correct. Another problem is that this commit does not check TensorFlow version, so it breaks the compatibility with older versions of the framework.
Handling both tensorflow v2 and v1 could be done with try:
import tensorflow.compat.v1 as tf
except ImportError:
import tensorflow as tf(I hate that concept, but it works)
Not really as
True. I'm ok with naming it anything else... |
|
Is there a reason why this is not merged yet? would be cool to have it in the master branch. |
Because this project is abandoned. |
This PR updates
MMdnnforTensorFlowv2 compatibility by utilizing legacy support in TF2Main reason is that TF1 requires Python 3.7 or lower and new systems come with Python 3.8 which I did not want to downgrade
Change is basically switching imports from
tensorflowtotensorflow.compat.v1and setting appropriate flagsOnly additional change needed is definition of
flattenlayer as it has to be explicitly defined as legacy sincecontribnamespace no longer existsAdditional change in this PR is that emitted code does not use
Infconstant as any constant may be undefined depending on the TF backend usedFor example, Python or NodeJS with Tensorflow backend will resolve it fine, but GLSL code generated by TensorFlow/JS WebGL backend does not handle constants as constants in general do not exist in GLSL
I've tested this with converting Places365 ResNet152 model from Caffe to Tensorflow saved model and further using
tensorflowjs_convertto convert this new TF saved model to TFJS graph model and then tested both saved model and graph model using NodeJSTensorFlowbackend,WASMbackend andWebGLbackend