python - Tensorflow VGG16属性错误:模块tensorflow没有属性get_default_graph?
问题描述
大家好,我刚开始学习机器学习并尝试在Jupyter Notebook
. 我正在尝试运行以下代码。我用谷歌搜索了错误并将tensorflow
版本更新为 2.3.1 和kersa
2.1.6。但它仍然抛出这个TypeError
。我看到还有另一种方法可以通过删除参数来修改 python 源代码axis
。但是如何更改 vgg16 源代码Jupyter Notebook
?我试图进入/use/local/lib
我的 macbook,但找不到 python 源文件。希望有人能帮忙!干杯
代码:
from keras.application.vgg16 import VGG16
vggmodel = VGG16(weight='imagenet', include_top=True)
vggmodel.summary()
更新:我找到了源文件并删除了轴参数。但是现在又抛出了另一个错误。
Tensorflow Attribute Error: module tensorflow has no attribute get_default_graph
AttributeError Traceback (most recent call last)
<ipython-input-14-5b351c8334f5> in <module>
----> 1 vggmodel = VGG16(weights='imagenet', include_top=True)
2 vggmodel.summary()
~/.local/lib/python3.7/site-packages/keras/applications/vgg16.py in VGG16(include_top, weights, input_tensor, input_shape, pooling, classes)
107
108 if input_tensor is None:
--> 109 img_input = Input(shape=input_shape)
110 else:
111 if not K.is_keras_tensor(input_tensor):
~/.local/lib/python3.7/site-packages/keras/engine/topology.py in Input(shape, batch_shape, name, dtype, sparse, tensor)
1455 name=name, dtype=dtype,
1456 sparse=sparse,
-> 1457 input_tensor=tensor)
1458 # Return tensor including _keras_shape and _keras_history.
1459 # Note that in this case train_output and test_output are the same pointer.
~/.local/lib/python3.7/site-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
89 warnings.warn('Update your `' + object_name +
90 '` call to the Keras 2 API: ' + signature, stacklevel=2)
---> 91 return func(*args, **kwargs)
92 wrapper._original_function = func
93 return wrapper
~/.local/lib/python3.7/site-packages/keras/engine/topology.py in __init__(self, input_shape, batch_size, batch_input_shape, dtype, input_tensor, sparse, name)
1317 if not name:
1318 prefix = 'input'
-> 1319 name = prefix + '_' + str(K.get_uid(prefix))
1320 super(InputLayer, self).__init__(dtype=dtype, name=name)
1321
~/.local/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py in get_uid(prefix)
66 """
67 global _GRAPH_UID_DICTS
---> 68 graph = tf.get_default_graph()
69 if graph not in _GRAPH_UID_DICTS:
70 _GRAPH_UID_DICTS[graph] = defaultdict(int)
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
解决方案
推荐阅读
- javascript - 通过 PHP 和 jQuery 注入 HTML 出错了
- kubernetes - 在 Kubernetes (GKE) 上创建 cockroachdb 用户证书的最后一步
- html - 定位 CSS 列布局中的特定列
- graphql - 在短 GraphQL 查询上返回 null
- reactjs - 带有 express 后端的 Create-react-app 在本地工作,但在部署到 heroku 时路由不正确
- ruby - 只要有更多内容要显示,Watir 就会向下滚动页面
- java - 在验证多个 URL 时无法在 java 中找到请求目标的有效证书路径
- javascript - D3 forceX/forceY 和 forceCenter 的区别
- python - 使用 asyncio 创建两个并发异步任务
- c++ - 为什么顶点数组对象会导致错误?