【问题标题】:Importing TensorFlow "async" syntax errorImporting TensorFlow \"async\" syntax error
【发布时间】:2022-12-27 22:10:32
【问题描述】:

I am trying to use the module imageai for a project and ran the line "from imageai.Detection import ObjectDetection". However, when I do so, this error appears:

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/pywrap_tensorflow_internal.py:114
    def TFE_ContextOptionsSetAsync(arg1, async):
                                         ^
SyntaxError: invalid syntax

I found someone who had the same issue here: https://github.com/tensorflow/tensorflow/issues/20690 , but I'm not quite sure how to edit the last file of the trace where the error occurs. Does anyone have any tips on how to do this? Thanks!

I have tried looking at the above GitHub error but am not sure how to approach it.

【问题讨论】:

  • You installed a version of tensorflow that does not support Python 3.10, how did you do that exactly?
  • I'm not sure? I downloaded tensorflow using "pip install tensorflow" in my terminal.
  • Which version of TensorFlow did you install then?
  • I installed tensorflow 2 from this website: tensorflow.org/install
  • TensorFlow 2 has many versions, you need to be specific, you are having people guess the problem.

标签: tensorflow syntax-error


【解决方案1】:

ImageAI uses Pytorch as backend. So you need to install all the required libraries before installing and importing the imageai module.

Please use the code below to install imageai in your system:

pip install cython pillow>=7.0.0 numpy>=1.18.1 opencv-python>=4.1.2 torch>=1.9.0 --extra-index-url https://download.pytorch.org/whl/cpu torchvision>=0.10.0 --extra-index-url https://download.pytorch.org/whl/cpu pytest==7.1.3 tqdm==4.64.1 scipy>=1.7.3 matplotlib>=3.4.3 mock==4.0.3

pip install imageai --upgrade

Now, import the Object detection from imageai:

from imageai.Detection import ObjectDetection

Please refer this link for more details.

Note:You can easily install imageai in Google Colab with this code

!pip install imageai
from imageai.Detection import ObjectDetection

Hints:Please use below code to install, import and check the TensorFlow version

pip install tensorflow
import tensorflow as tf
tf.__version__

【讨论】:

    猜你喜欢
    • 2022-06-24
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 2020-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多