• tensorflowwindows安装


    1.在python官网下载3.5 64位版本的python,并进行安装

        https://www.python.org/

       

        

      

    2.进行安装,配置环境变量 

    3.命令行执行pip3 install numpy

    4.命令行执行pip3 install tensorflow

    5.运行测试

     将以下代码保存到test.py中,然后通过python test.py运行

    import tensorflow as tf
    import numpy as np
    
    
    x_data = np.random.rand(100).astype(np.float32)
    y_data = x_data*0.1 + 0.3
    
    Weights = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
    biases = tf.Variable(tf.zeros([1]))
    
    y = Weights*x_data + biases
    
    loss = tf.reduce_mean(tf.square(y-y_data))
    
    optimizer = tf.train.GradientDescentOptimizer(0.5)
    train = optimizer.minimize(loss)
    
    init = tf.global_variables_initializer()  
    
    sess = tf.Session()
    sess.run(init)
    
    for step in range(201):
        sess.run(train)
        if step % 20 == 0:
            print(step, sess.run(Weights), sess.run(biases))

    运行结果(我们计算 x*0.1+0.3=y tensorflow通过x与y的值,逼近0.1和0.3)

    0 [-0.03866833] [ 0.56909722]
    20 [ 0.0400503] [ 0.33504695]
    40 [ 0.08370772] [ 0.30952457]
    60 [ 0.09557232] [ 0.30258846]
    80 [ 0.09879671] [ 0.30070347]
    100 [ 0.099673] [ 0.30019119]
    120 [ 0.09991115] [ 0.30005196]
    140 [ 0.09997585] [ 0.30001414]
    160 [ 0.09999346] [ 0.30000383]
    180 [ 0.09999823] [ 0.30000106]
    200 [ 0.09999952] [ 0.30000031]

    6.如果出现报错,则安装搜索Microsoft Visual C++ 2015 Redistributable Update 3安装

    https://www.microsoft.com/zh-CN/download/details.aspx?id=52685

    Traceback (most recent call last):
      File "D:Python35libsite-packages	ensorflowpythonpywrap_tensorflow_internal.py", line 18, in swig_import_helper
        return importlib.import_module(mname)
      File "D:Python35libimportlib\__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 986, in _gcd_import
      File "<frozen importlib._bootstrap>", line 969, in _find_and_load
      File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 577, in module_from_spec
      File "<frozen importlib._bootstrap_external>", line 914, in create_module
      File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
    ImportError: DLL load failed: 找不到指定的模块。
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "D:Python35libsite-packages	ensorflowpythonpywrap_tensorflow.py", line 41, in <module>
        from tensorflow.python.pywrap_tensorflow_internal import *
      File "D:Python35libsite-packages	ensorflowpythonpywrap_tensorflow_internal.py", line 21, in <module>
        _pywrap_tensorflow_internal = swig_import_helper()
      File "D:Python35libsite-packages	ensorflowpythonpywrap_tensorflow_internal.py", line 20, in swig_import_helper
        return importlib.import_module('_pywrap_tensorflow_internal')
      File "D:Python35libimportlib\__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
    ImportError: No module named '_pywrap_tensorflow_internal'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "test.py", line 1, in <module>
        import tensorflow as tf
      File "D:Python35libsite-packages	ensorflow\__init__.py", line 24, in <module>
        from tensorflow.python import *
      File "D:Python35libsite-packages	ensorflowpython\__init__.py", line 51, in <module>
        from tensorflow.python import pywrap_tensorflow
      File "D:Python35libsite-packages	ensorflowpythonpywrap_tensorflow.py", line 52, in <module>
        raise ImportError(msg)
    ImportError: Traceback (most recent call last):
      File "D:Python35libsite-packages	ensorflowpythonpywrap_tensorflow_internal.py", line 18, in swig_import_helper
        return importlib.import_module(mname)
      File "D:Python35libimportlib\__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 986, in _gcd_import
      File "<frozen importlib._bootstrap>", line 969, in _find_and_load
      File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 577, in module_from_spec
      File "<frozen importlib._bootstrap_external>", line 914, in create_module
      File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
    ImportError: DLL load failed: 找不到指定的模块。
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "D:Python35libsite-packages	ensorflowpythonpywrap_tensorflow.py", line 41, in <module>
        from tensorflow.python.pywrap_tensorflow_internal import *
      File "D:Python35libsite-packages	ensorflowpythonpywrap_tensorflow_internal.py", line 21, in <module>
        _pywrap_tensorflow_internal = swig_import_helper()
      File "D:Python35libsite-packages	ensorflowpythonpywrap_tensorflow_internal.py", line 20, in swig_import_helper
        return importlib.import_module('_pywrap_tensorflow_internal')
      File "D:Python35libimportlib\__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
    ImportError: No module named '_pywrap_tensorflow_internal'
    
    
    Failed to load the native TensorFlow runtime.
    
    See https://www.tensorflow.org/install/install_sources#common_installation_problems
    
    for some common reasons and solutions.  Include the entire stack trace
    above this error message when asking for help.
  • 相关阅读:
    Java集合框架知多少——干货!!!
    Java基础小记
    初识Java
    HTML5入门必知
    密码技术小结
    [MDK]Keil在下载程序一直提示更新J-Link
    Python 循环
    2021年7月14日
    bzoj 2653 middle (主席树+二分)
    bzoj 3932 [CQOI2015]任务查询系统 (主席树)
  • 原文地址:https://www.cnblogs.com/maobuji/p/6933165.html
Copyright © 2020-2023  润新知