代码之家  ›  专栏  ›  技术社区  ›  Schilcote

Tensorflow没有常数(但有其他的一切?)

  •  -2
  • Schilcote  · 技术社区  · 8 年前

    我最近安装了Tensorflow pip 在新的Python 3.6.3安装上。

    以下代码:

    import tensorflow as tf
    
    msgconst = tf.Constant("henlo wrlod lol <4")
    thesession = tf.Session()
    print(thesession.run(msgconst))
    thesession.close()
    

    给出了错误

    Traceback (most recent call last):
      File "C:/Users/[my username]/PycharmProjects/TFlowTest/aergaetgaertgasrtg.py", line 3, in <module>
        msgconst = tf.Constant("henlo wrlod lol <4")
    AttributeError: module 'tensorflow' has no attribute 'Constant'
    

    问题不是有另一个名为 tensorflow 这是导入而不是真正的库;其他一切都存在。我可以做得很好:

    import tensorflow as tf
    from tensorflow.python.framework import ops
    ops.reset_default_graph()
    print(tf.test.is_built_with_cuda())
    print(tf.test.gpu_device_name())
    

    True
    2017-12-06 21:03:22.807800: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
    2017-12-06 21:03:23.147288: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties: 
    name: GeForce GTX 980M major: 5 minor: 2 memoryClockRate(GHz): 1.1265
    pciBusID: 0000:01:00.0
    totalMemory: 4.00GiB freeMemory: 3.32GiB
    2017-12-06 21:03:23.147553: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 980M, pci bus id: 0000:01:00.0, compute capability: 5.2)
    /device:GPU:0
    
    Process finished with exit code 0
    

    卸载和重新安装Tensorflow后仍然存在此问题;下面是pip在安装时打印的内容

    C:\Program Files\Python36-64\Scripts>pip install tensorflow-gpu --no-cache-dir
    Collecting tensorflow-gpu
      Downloading tensorflow_gpu-1.4.0-cp36-cp36m-win_amd64.whl (67.6MB)
        100% |████████████████████████████████| 67.6MB ...
    Requirement already satisfied: numpy>=1.12.1 in c:\program files\python36-64\lib\site-packages (from tensorflow-gpu)
    Requirement already satisfied: wheel>=0.26 in c:\program files\python36-64\lib\site-packages (from tensorflow-gpu)
    Requirement already satisfied: six>=1.10.0 in c:\program files\python36-64\lib\site-packages (from tensorflow-gpu)
    Requirement already satisfied: enum34>=1.1.6 in c:\program files\python36-64\lib\site-packages (from tensorflow-gpu)
    Requirement already satisfied: tensorflow-tensorboard<0.5.0,>=0.4.0rc1 in c:\program files\python36-64\lib\site-packages (from tensorflow-gpu)
    Requirement already satisfied: protobuf>=3.3.0 in c:\program files\python36-64\lib\site-packages (from tensorflow-gpu)
    Requirement already satisfied: html5lib==0.9999999 in c:\program files\python36-64\lib\site-packages (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow-gpu)
    Requirement already satisfied: werkzeug>=0.11.10 in c:\program files\python36-64\lib\site-packages (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow-gpu)
    Requirement already satisfied: markdown>=2.6.8 in c:\program files\python36-64\lib\site-packages (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow-gpu)
    Requirement already satisfied: bleach==1.5.0 in c:\program files\python36-64\lib\site-packages (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow-gpu)
    Requirement already satisfied: setuptools in c:\program files\python36-64\lib\site-packages (from protobuf>=3.3.0->tensorflow-gpu)
    Installing collected packages: tensorflow-gpu
    Successfully installed tensorflow-gpu-1.4.0
    

    有什么建议吗?

    1 回复  |  直到 8 年前
        1
  •  2
  •   Mike Williamson    8 年前

    你肯定不想听,但这是

    tf.constant(
    

    tf.Constant(
    

    (请注意,第一个未大写。)

    我只是在我的环境中玩了一下你的代码来注意到这一点,所以我可以说我实际上在使用你的代码时遇到了问题,但是当使用一个小用例时,它就起作用了 constant .

    推荐文章