module 'tensorflow' has no attribute 'absolute_import'

image
这个error猝不及防,在查看了tensorflow API的版本后,做了如下更改

# from tensorflow import *
from tensorflow.python import *

module ‘XXX’ has no attribute ‘XXX’
解决方案:(1)module未导入成功;(2)版本容错问题。

error分析原因
本人环境是tensorflow 1.10
因为有朋友在tensorflow1.3版本上并无此错误,故直接查看了1.3版本与出错的init.py之间的区别,即做出了上述尝试,成功。

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

# pylint: disable=wildcard-import
from tensorflow.python import *  # 出错参考点
# pylint: enable=wildcard-import

from tensorflow.python.util.lazy_loader import LazyLoader
contrib = LazyLoader('contrib', globals(), 'tensorflow.contrib')
del LazyLoader

del absolute_import
del division
del print_function

# These symbols appear because we import the python package which
# in turn imports from tensorflow.core and tensorflow.python. They
# must come from this module. So python adds these symbols for the
# resolution to succeed.
# pylint: disable=undefined-variable
del python
del core

对比出错init

from __future__ import absolute_import
from tensorflow import *  # 与上面版本的init有出入

from .sg_util import sg_opt
from .sg_main import *
from .sg_logging import *
from .sg_train import *
from .sg_queue import sg_producer_func
from .sg_layer import sg_emb

from . import sg_optimize
from . import sg_data
from . import sg_initializer

from ._version import __version__


__author__ = 'namju.kim@kakaocorp.com'


#
# augmenting tensorflow Variable and Tensor type by injecting custom methods
#

modules = ['sg_activation', 'sg_metric', 'sg_layer', 'sg_loss', 'sg_transform', 'sg_net']
for mod in modules:
    sg_inject(__path__[0], mod)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值