update for tensorflow v2 compatibility #917
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR updates
MMdnn
forTensorFlow
v2 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
tensorflow
totensorflow.compat.v1
and setting appropriate flagsOnly additional change needed is definition of
flatten
layer as it has to be explicitly defined as legacy sincecontrib
namespace no longer existsAdditional change in this PR is that emitted code does not use
Inf
constant 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_convert
to convert this new TF saved model to TFJS graph model and then tested both saved model and graph model using NodeJSTensorFlow
backend,WASM
backend andWebGL
backend