Open Ehtasha opened 4 years ago
I have the same errors as well, while the pip install -e .
shows
Obtaining file:///content/onnx-tensorflow
Requirement already satisfied: onnx>=1.5.0 in /usr/local/lib/python3.6/dist-packages (from onnx-tf==1.5.0) (1.6.0)
Requirement already satisfied: PyYAML in /usr/local/lib/python3.6/dist-packages (from onnx-tf==1.5.0) (3.13)
Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from onnx>=1.5.0->onnx-tf==1.5.0) (1.12.0)
Requirement already satisfied: typing-extensions>=3.6.2.1 in /usr/local/lib/python3.6/dist-packages (from onnx>=1.5.0->onnx-tf==1.5.0) (3.6.6)
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from onnx>=1.5.0->onnx-tf==1.5.0) (1.17.5)
Requirement already satisfied: protobuf in /usr/local/lib/python3.6/dist-packages (from onnx>=1.5.0->onnx-tf==1.5.0) (3.10.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from protobuf->onnx>=1.5.0->onnx-tf==1.5.0) (42.0.2)
Installing collected packages: onnx-tf
Found existing installation: onnx-tf 1.5.0
Uninstalling onnx-tf-1.5.0:
Successfully uninstalled onnx-tf-1.5.0
Running setup.py develop for onnx-tf
Successfully installed onnx-tf
But when I try to import it, it shows
1 import onnx
----> 2 import onnx_tf
ModuleNotFoundError: No module named 'onnx_tf'
I am not sure is this the solution but it does solve the problem for me, in Google Colab.
You will need to install tensorflow-addons first, along with the tf, then git clone and install it.
!pip install tensorflow-addons
.......
Successfully installed google-auth-1.11.0 tensorboard-2.1.0 tensorflow-2.1.0 tensorflow-addons-0.7.1 tensorflow-estimator-2.1.0
Check version
import tensorflow as tf
import tensorflow_addons as tfa
print(tf.__version__)
print(tfa.__version__)
>>>2.1.0
>>>0.7.1
then git clone and install
!git clone https://github.com/onnx/onnx-tensorflow.git && cd onnx-tensorflow && pip install -e .
Installing collected packages: onnx-tf
Found existing installation: onnx-tf 1.5.0
Can't uninstall 'onnx-tf'. No files were found to uninstall.
Running setup.py develop for onnx-tf
Successfully installed onnx-tf
Final test import
from onnx_tf.backend import prepare
/content/onnx-tensorflow/onnx_tf/common/__init__.py:89: UserWarning: onnx_tf.common.get_outputs_names is deprecated. It will be removed in future release. Use TensorflowGraph.get_outputs_names instead.
warnings.warn(message)
It works at this point.
I also try to install onn-tf with my custom docker environment, the solution is to append the build directory after pip install -e .
to the sys.path, but before doing this, you have to make sure the tensorflow-addons is properly installed. You probabaly need to upgrade your tensorflow to 2.1 in order to install tensorflow-addons properly...
import sys
sys.path
sys.path.append('your onn-tf build path")
Please retry with the latest from master branch. Make sure you have tf 2.x, addons, and onnx can be either master or pip install.
@Ehtasha Have you tried it lately? Please use source build from the tf-1.x branch if you have tensorflow 1.x, and do source build from the master branch for tensorflow 2.x. You also need tensorflow-addons as described here, https://github.com/onnx/onnx-tensorflow#installation. Please report if any errors. I'd like to close this issue if working for you.
It's still not working. On google colab, I get an error (onnx_tf not found) when I run the following:
!pip install tensorflow-addons
import tensorflow as tf
import tensorflow_addons as tfa
print(tf.__version__)
print(tfa.__version__)
!git clone https://github.com/onnx/onnx-tensorflow.git && cd onnx-tensorflow && pip install -e .
from onnx_tf.backend import prepare
Can the onnx converter for tensorflow be used with tensorflow 1.14.x ?
Ah never mind, it works
This doesn't seem to work on Colab. The package gets installed but importing it fails for some reason.
import tensorflow as tf
tf.__version__
'2.2.0'
!pip install tensorflow-addons
!git clone https://github.com/onnx/onnx-tensorflow.git && cd onnx-tensorflow && pip install -e .
Requirement already satisfied: tensorflow-addons in /usr/local/lib/python3.6/dist-packages (0.8.3)
Requirement already satisfied: typeguard in /usr/local/lib/python3.6/dist-packages (from tensorflow-addons) (2.7.1)
Cloning into 'onnx-tensorflow'...
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 5004 (delta 0), reused 0 (delta 0), pack-reused 4996
Receiving objects: 100% (5004/5004), 1.33 MiB | 1.81 MiB/s, done.
Resolving deltas: 100% (3823/3823), done.
Obtaining file:///content/onnx-tensorflow
Collecting onnx>=1.6.0
Downloading https://files.pythonhosted.org/packages/36/ee/bc7bc88fc8449266add978627e90c363069211584b937fd867b0ccc59f09/onnx-1.7.0-cp36-cp36m-manylinux1_x86_64.whl (7.4MB)
|████████████████████████████████| 7.4MB 2.5MB/s
Requirement already satisfied: PyYAML in /usr/local/lib/python3.6/dist-packages (from onnx-tf==1.6.0) (3.13)
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from onnx>=1.6.0->onnx-tf==1.6.0) (1.18.5)
Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from onnx>=1.6.0->onnx-tf==1.6.0) (1.15.0)
Requirement already satisfied: protobuf in /usr/local/lib/python3.6/dist-packages (from onnx>=1.6.0->onnx-tf==1.6.0) (3.12.2)
Requirement already satisfied: typing-extensions>=3.6.2.1 in /usr/local/lib/python3.6/dist-packages (from onnx>=1.6.0->onnx-tf==1.6.0) (3.7.4.2)
Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from protobuf->onnx>=1.6.0->onnx-tf==1.6.0) (49.1.0)
Installing collected packages: onnx, onnx-tf
Running setup.py develop for onnx-tf
Successfully installed onnx-1.7.0 onnx-tf
from onnx_tf.backend import prepare
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-6913ab77a9da> in <module>()
----> 1 from onnx_tf.backend import prepare
ModuleNotFoundError: No module named 'onnx_tf'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
Update: Restarting the kernel and importing the package fixed it.
Still not working on google colab
This worked for me
%%bash
pip install onnx tensorflow-addons
git clone https://github.com/onnx/onnx-tensorflow.git && cd onnx-tensorflow && pip install -e .
and then
sys.path.append("./onnx-tensorflow")
sys.path.append("./onnx-tensorflow")
/bin/bash: -c: line 0: syntax error near unexpected token `"./onnx-tensorflow"' /bin/bash: -c: line 0: `sys.path.append("./onnx-tensorflow")'
sys.path.append("./onnx-tensorflow")
/bin/bash: -c: line 0: syntax error near unexpected token `"./onnx-tensorflow"' /bin/bash: -c: line 0: `sys.path.append("./onnx-tensorflow")'
@AlexandrParkhomenko Try to run import sys
beforehand.
sys.path.append("./onnx-tensorflow")
/bin/bash: -c: line 0: syntax error near unexpected token `"./onnx-tensorflow"' /bin/bash: -c: line 0: `sys.path.append("./onnx-tensorflow")'
@AlexandrParkhomenko Try to run
import sys
beforehand.
Thanks
pip install onnx-tf
i think this will fix your error .try it
Thanks! Successfully installed onnx in archlinux. Issue can be closed.
Just Restart the Kernel after you clone the git repo & install the requirements.txt file . then
from onnx_tf.backend import prepare
It Worked for me in colab pro :)
Solution: Change from 3.10 to 3.9 python version
I was following this https://docs.ultralytics.com/integrations/tflite/#usage. Converting a model to TFlite, it didnt work (my error was: No module named 'onnx2tf'). Then i changed from python 3.10 to python 3.9 and it worked.
Solution: Change from 3.10 to 3.9 python version
I'm trying to convert my PyTorch model into Tensorflow. I have successfully convert my PyTorch model into .onnx format using opset=11. But When I try to convert .onnx to tensorflow it gives me an Error:No module named 'onnx_tf'
but version is not showing when I print -> print(onnx.tf.version). Saying that 'has no attribute version'
ONNX-TF version: I have install using master branch. Using bellow comman I have install ONNX !git clone https://github.com/onnx/onnx-tensorflow.git
Tensorflow version: 1.15.0
I have .onnx file which is created using bellow function notice 'opset = 11' torch.onnx.export(model_pytorch, dummy_input, "filePath", verbose=False,opset_version=11)
And because of opset 11 I must need to install onnx using master repository as @chinhuang007 suggest me in this issue https://github.com/onnx/onnx-tensorflow/issues/516
---------------------------------- Error Statement ----------------------------------------- ModuleNotFoundError Traceback (most recent call last)