• tensorflow安装


    环境:

      1.主机:Linux alvin-Lenovo-V310-14ISK 4.13.0-46-generic #51-Ubuntu SMP Tue Jun 12 12:36:29 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

      2.Python版本 :Python 2.7.14

    安装仅使用cpu的版本:

    1.执行安装命令:

    $ pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
    2.安装成功后打印信息如下:
    Installing collected packages: numpy, six, tensorflow
    Successfully installed numpy-1.16.4 six-1.12.0 tensorflow-0.5.0

    运行tensorflow中文社区上的简单demo如下:

     1 import tensorflow as tf
     2 import numpy as np
     3 
     4 # 使用 NumPy 生成假数据(phony data), 总共 100 个点.
     5 x_data = np.float32(np.random.rand(2, 100)) # 随机输入
     6 y_data = np.dot([0.100, 0.200], x_data) + 0.300
     7 
     8 # 构造一个线性模型
     9 # 
    10 b = tf.Variable(tf.zeros([1]))
    11 W = tf.Variable(tf.random_uniform([1, 2], -1.0, 1.0))
    12 y = tf.matmul(W, x_data) + b
    13 
    14 # 最小化方差
    15 loss = tf.reduce_mean(tf.square(y - y_data))
    16 optimizer = tf.train.GradientDescentOptimizer(0.5)
    17 train = optimizer.minimize(loss)
    18 
    19 # 初始化变量
    20 init = tf.initialize_all_variables()
    21 
    22 # 启动图 (graph)
    23 sess = tf.Session()
    24 sess.run(init)
    25 
    26 # 拟合平面
    27 for step in xrange(0, 201):
    28     sess.run(train)
    29     if step % 20 == 0:
    30         print step, sess.run(W), sess.run(b)
    31 
    32 # 得到最佳拟合结果 W: [[0.100  0.200]], b: [0.300]

    后续会更新一些tensorflow的应用示例

     

    以上为安装及演示社区上的 demo的过程。

    作者:Alvin2012
  • 相关阅读:
    HTTP 返回状态代码详细解释
    丁一的作业
    getIntent().getExtras().clear()未清空Bundle的数据
    activity android:launchMode="singleTask" 没用重现启动activity的问题
    判断email格式
    判断网络是否可用
    修改系统语言
    生成UUID
    css reset file
    智能指针(auto_ptr)vc版
  • 原文地址:https://www.cnblogs.com/live-program/p/10987205.html
Copyright © 2020-2023  润新知