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

model = InceptionV3(weights='imagenet')

但是我得到这样的错误:
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

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

1。 -------------------------------------------------- ------------------------- AttributeError追溯(最新
最后调用)()
1#加载Inception v3模型
----> 2个模型= InceptionV3(include_top = True,weights ='imagenet')
3#InceptionV3(权重='图像网')
~/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>

其中“某物”是指您要导入的模块。它为我工作。

10-06 06:17