Python 无法找到模块 ‘official.legacy’ 和 ‘tensorflow.python.keras.layers.preprocessing’。

huangapple go评论70阅读模式
英文:

Python cannot find modules 'official.legacy' and 'tensorflow.python.keras.layers.preprocessing'

问题

我正在尝试在我的Windows计算机上安装并运行Tensorflow,目前不使用GPU,但即使按照Tensorflow Api Detection API教程中的所有步骤,没有任何错误,但我仍然无法运行测试脚本。

每当我运行时,我会收到以下错误消息:

Traceback (most recent call last):
  File "C:\Users\User\Documents\Tensorflow\models\research\object_detection\models\ssd_efficientnet_bifpn_feature_extractor.py", line 36, in <module>
    from official.legacy.image_classification.efficientnet import efficientnet_model
ModuleNotFoundError: No module named 'official.legacy'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\User\Documents\Tensorflow\models\research\object_detection\builders\model_builder_tf2_test.py", line 24, in <module>
    from object_detection.builders import model_builder
  File "C:\Users\User\Documents\Tensorflow\models\research\object_detection\builders\model_builder.py", line 70, in <module>
    from object_detection.models import ssd_efficientnet_bifpn_feature_extractor as ssd_efficientnet_bifpn
  File "C:\Users\User\Documents\Tensorflow\models\research\object_detection\models\ssd_efficientnet_bifpn_feature_extractor.py", line 38, in <module>
    from official.vision.image_classification.efficientnet import efficientnet_model
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\official\vision\image_classification\efficientnet\efficientnet_model.py", line 37, in <module>
    from official.vision.image_classification import preprocessing
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\official\vision\image_classification\preprocessing.py", line 25, in <module>
    from official.vision.image_classification import augment
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\official\vision\image_classification\augment.py", line 31, in <module>
    from tensorflow.python.keras.layers.preprocessing import image_preprocessing as image_ops
ModuleNotFoundError: No module named 'tensorflow.python.keras.layers.preprocessing'

我在网上找不到任何能帮助我的东西,我尝试将/models文件夹添加到PYTHONPATH,我安装了requirements.txt中的所有必需包,但错误仍然相同。由于我已经安装了Tensorflow 2.12.0,所以我不确定问题出在哪里。

英文:

I'm trying to install and run Tensorflow on my Windows computer without using the GPU for now, but even after having followed all the steps in the Tensorflow Api Detection API tutorial with no eror whatsoever but I still cannot run the test script.

Whenever I do I get this error:

Traceback (most recent call last):
  File &quot;C:\Users\User\Documents\Tensorflow\models\research\object_detection\models\ssd_efficientnet_bifpn_feature_extractor.py&quot;, line 36, in &lt;module&gt;
from official.legacy.image_classification.efficientnet import efficientnet_model
ModuleNotFoundError: No module named &#39;official.legacy&#39;

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;C:\Users\User\Documents\Tensorflow\models\research\object_detection\builders\model_builder_tf2_test.py&quot;, line 24, in &lt;module&gt;
from object_detection.builders import model_builder
  File &quot;C:\Users\User\Documents\Tensorflow\models\research\object_detection\builders\model_builder.py&quot;, line 70, in &lt;module&gt;
from object_detection.models import ssd_efficientnet_bifpn_feature_extractor as ssd_efficientnet_bifpn
  File &quot;C:\Users\User\Documents\Tensorflow\models\research\object_detection\models\ssd_efficientnet_bifpn_feature_extractor.py&quot;, line 38, in &lt;module&gt;
from official.vision.image_classification.efficientnet import efficientnet_model
  File &quot;C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\official\vision\image_classification\efficientnet\efficientnet_model.py&quot;, line 37, in &lt;module&gt;
from official.vision.image_classification import preprocessing
  File &quot;C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\official\vision\image_classification\preprocessing.py&quot;, line 25, in &lt;module&gt;
from official.vision.image_classification import augment
  File &quot;C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\official\vision\image_classification\augment.py&quot;, line 31, in &lt;module&gt;
from tensorflow.python.keras.layers.preprocessing import image_preprocessing as image_ops
ModuleNotFoundError: No module named &#39;tensorflow.python.keras.layers.preprocessing&#39;

I found nothing that could help me online, I tried adding the /models folder to PYTHONPATH, I installed all the required packages from the requirements.txt but the error remained the same. I'm not sure what's the problem here since I do have Tensorflow 2.12.0 installed.

答案1

得分: 0

你应该安装模块 tf-models-official

pip install tf-models-official

或者如果你已经安装了它,可以更新它的版本。

英文:

You should install the module tf-models-official:

pip install tf-models-official

or update its version if you already have it installed.

答案2

得分: 0

我找到了问题的原因。显然,我是在一个损坏的object_detection文件夹安装中运行我的命令,这意味着它只是那个文件夹,所有上级文件夹都缺失了。将文件夹更改为我的新干净安装后,问题完全解决了。

英文:

I faound the cause of the problem. I apprentl was running my command in a broken installation of the object_detection folder, meaning it was just that and had all the superior folders missing. Changing folder to my new clean installation solved the problem completely

huangapple
  • 本文由 发表于 2023年6月8日 01:23:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76425720.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定