ImportError: cannot import name ‘layer_utils‘ from ‘tensorflow_core解决无法导入的问题

本文探讨了如何在从TensorFlow 1.x到2.x版本迁移过程中,正确导入和使用Keras的layer_utils模块,并指导开发者如何避免常见问题。
#TF1.x
from keras.utils import layer_utils
#TF2.x
from tensorflow.python.keras.utils import layer_utils

直接加上tensorflow.python......

如何更改model.py文件内的代码,其次还碰到了E:\projrct_cut\mask rcnn_test\mrcnn\model.py:2336: SyntaxWarning: "is" with a literal. Did you mean "=="? if os.name is 'nt': 2025-03-20 12:37:50.671120: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 2025-03-20 12:37:51.497578: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. Traceback (most recent call last): File "E:\projrct_cut\mask rcnn_test\mrcnn\model.py", line 23, in <module> from tensorflow.keras import engine as KE ImportError: cannot import name 'engine' from 'tensorflow.keras' (C:\Users\S1999\AppData\Roaming\Python\Python39\site-packages\keras\_tf_keras\keras\__init__.py)这样的报错,还碰到了from samples.coco import coco标红的报错,我不光要更改model.py文件,我还需要更改哪里?我是直接从GitHub上下载的mask r-cnn项目,调试真困难,希望你能很详细的给出处理步骤。我的python版本是3.9, tensorflow版本2.19.0,代码中存在着很多import keras...等很多语句都标红。或者你给我推荐支持python3.9的内涵kerastensorflow1.版本或者2.
03-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值