AttributeError:模块"tensorflow"没有属性"get_default_graph" [英] AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

查看:522
本文介绍了AttributeError:模块"tensorflow"没有属性"get_default_graph"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些与图像字幕相关的任务,并且已经像这样加载了初始模型的权重

I am doing some task related to image captioning and I have loaded the weights of inception model like this

model = InceptionV3(weights='imagenet')

但是我收到这样的错误:

But I am getting error like this:

AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

我该怎么办?请帮忙. 这是上面代码的完整输出.

What should I do? Please help. Here is the full output of above code.

1. -------------------------------------------------- ------------------------- AttributeError追溯(最新 最后呼叫)() 1#加载Inception v3模型 ----> 2个模型= InceptionV3(include_top = True,weights ='imagenet') 3#InceptionV3(weights ='imagenet')

1 . --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in () 1 # Load the inception v3 model ----> 2 model = InceptionV3(include_top=True,weights='imagenet') 3 # InceptionV3(weights='imagenet')

~/anaconda3/lib/python3.6/site-packages/keras/applications/__init__.py
in wrapper(*args, **kwargs)
     26             kwargs['models'] = models
     27             kwargs['utils'] = utils
---> 28         return base_fun(*args, **kwargs)
     29 
     30     return wrapper

~/anaconda3/lib/python3.6/site-packages/keras/applications/inception_v3.py
in InceptionV3(*args, **kwargs)
      9 @keras_modules_injection
     10 def InceptionV3(*args, **kwargs):
---> 11     return inception_v3.InceptionV3(*args, **kwargs)
     12 
     13 

~/anaconda3/lib/python3.6/site-packages/keras_applications/inception_v3.py
in InceptionV3(include_top, weights, input_tensor, input_shape,
pooling, classes, **kwargs)
    155 
    156     if input_tensor is None:
--> 157         img_input = layers.Input(shape=input_shape)
    158     else:
    159         if not backend.is_keras_tensor(input_tensor):

~/anaconda3/lib/python3.6/site-packages/keras/engine/input_layer.py
in Input(shape, batch_shape, name, dtype, sparse, tensor)
    176                              name=name, dtype=dtype,
    177                              sparse=sparse,
--> 178                              input_tensor=tensor)
    179     # Return tensor including _keras_shape and _keras_history.
    180     # Note that in this case train_output and test_output are the same pointer.

~/anaconda3/lib/python3.6/site-packages/keras/legacy/interfaces.py
in wrapper(*args, **kwargs)
     89                 warnings.warn('Update your `' + object_name + '` call to the ' +
     90                               'Keras 2 API: ' + signature, stacklevel=2)
---> 91             return func(*args, **kwargs)
     92         wrapper._original_function = func
     93         return wrapper

~/anaconda3/lib/python3.6/site-packages/keras/engine/input_layer.py
in __init__(self, input_shape, batch_size, batch_input_shape, dtype,
input_tensor, sparse, name)
     37         if not name:
     38             prefix = 'input'
---> 39             name = prefix + '_' + str(K.get_uid(prefix))
     40         super(InputLayer, self).__init__(dtype=dtype, name=name)
     41 

~/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py
in get_uid(prefix)
     72     """
     73     global _GRAPH_UID_DICTS
---> 74     graph = tf.get_default_graph()
     75     if graph not in _GRAPH_UID_DICTS:
     76         _GRAPH_UID_DICTS[graph] = defaultdict(int)

AttributeError: module 'tensorflow' has no attribute
'get_default_graph'

推荐答案

更改

Import keras.<something>.<something>

Import tensorflow.keras.<something>.<something>

其中某物"是指您要导入的模块.它对我有用.

where "something" refers to the module you want to import. It worked for me.

这篇关于AttributeError:模块"tensorflow"没有属性"get_default_graph"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆