首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AttributeError:模块'tensorflow.python.keras.api._v2.keras.backend‘没有特性“”set_image_dim_ordering“”

AttributeError:模块'tensorflow.python.keras.api._v2.keras.backend‘没有特性“”set_image_dim_ordering“”
EN

Stack Overflow用户
提问于 2019-07-02 19:54:39
回答 1查看 13.4K关注 0票数 4

最近,我尝试使用python在github中运行代码。代码位于:https://github.com/costapt/vess2ret,我使用了以下软件

TensorFlow-gpu-2.0-beta1 Keras :2.2.4操作系统:Windows 10 python:3.5 CUDA:10.0 cuDNN:10.0

我遇到了同样的问题,一些人已经在网上表现出来了。也就是说: AttributeError: module 'tensorflow‘没有'get_default_graph’属性,在我尝试按如下方式更改代码之后

从keras导入后端

更改为:

从tensorflow.keras导入后端

我遇到了另一个问题。也就是说: AttributeError: module 'tensorflow.python.keras.api._v2.keras.backend‘没有'set_image_dim_ordering’属性

我不知道现在该怎么办

代码语言:javascript
运行
复制
#Here are some codes which are related to the problem above.

import os
import keras
from tensorflow.keras import backend as K
from keras import objectives
from keras.layers import Input, merge
from keras.layers.advanced_activations import LeakyReLU
from keras.layers.convolutional import Convolution2D, Deconvolution2D
from keras.layers.core import Activation, Dropout
from keras.layers.normalization import BatchNormalization
from keras.models import Model
from keras.optimizers import Adam

KERAS_2 = keras.__version__[0] == '2'
try:
    # keras 2 imports
    from keras.layers.convolutional import Conv2DTranspose
    from keras.layers.merge import Concatenate
except ImportError:
    print("keras 2 layers could not be imported defaulting to keras1")
    KERAS_2 = False

K.set_image_dim_ordering('th') #here is where the problem occurs at

#The first problem.
Traceback (most recent call last):
  File "C:\zzProject_ML\vess2ret-master\train.py", line 326, in <module>
    batch_size=params.batch_size, is_binary=params.is_b_binary)
  File "C:\zzProject_ML\vess2ret-master\models.py", line 378, in g_unet
    i = Input(shape=(in_ch, 512, 512))
  File "C:\Users\10580\Anaconda3\envs\project_ML\lib\site-packages\keras\engine\input_layer.py", line 178, in Input
    input_tensor=tensor)
  File "C:\Users\10580\Anaconda3\envs\project_ML\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\10580\Anaconda3\envs\project_ML\lib\site-packages\keras\engine\input_layer.py", line 39, in __init__
    name = prefix + '_' + str(K.get_uid(prefix))
  File "C:\Users\10580\Anaconda3\envs\project_ML\lib\site-packages\keras\backend\tensorflow_backend.py", line 74, in get_uid
    graph = tf.get_default_graph()
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

#The second problem.
Using TensorFlow backend.
Traceback (most recent call last):
  File "C:\zzProject_ML\vess2ret-master\train.py", line 7, in <module>
    import models as m
  File "C:\zzProject_ML\vess2ret-master\models.py", line 25, in <module>
    K.set_image_dim_ordering('th')
AttributeError: module 'tensorflow.python.keras.api._v2.keras.backend' has no attribute 'set_image_dim_ordering'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-02 20:16:56

您在导入中混合了tf.keraskeras (它们不兼容),并且keras目前不支持TensorFlow2.0(尚未发布稳定版本)。

如果您必须使用TensorFlow2.0,那么您必须使用该版本中包含的tf.keras。如果你想使用keras,那么你需要降级到一个稳定的tensorflow版本。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56851895

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档