Tensorflow安装入门教程

原创 sauren  2019-07-30 13:47  阅读 395 views 次 评论 27 条

TensorFlow是一个基于dataflow programming的符号数学系统,被广泛应用于各类machine learning算法的编程实现。

实验系统:Ubuntu 18.04

安装:

apt update
apt install python-pip

pip install tensorflow

第一个实验小程序:

import tensorflow as tf
import numpy as np

# 使用 NumPy 生成假数据(phony data), 总共 100 个点.
x_data = np.float32(np.random.rand(2, 100)) # 随机输入
y_data = np.dot([0.100, 0.200], x_data) + 0.300

# 构造一个线性模型
# 
b = tf.Variable(tf.zeros([1]))
W = tf.Variable(tf.random_uniform([1, 2], -1.0, 1.0))
y = tf.matmul(W, x_data) + b

# 最小化方差
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)

# 初始化变量
init = tf.initialize_all_variables()

# 启动图 (graph)
sess = tf.Session()
sess.run(init)

# 拟合平面
for step in xrange(0, 201):
    sess.run(train)
    if step % 20 == 0:
        print step, sess.run(W), sess.run(b)

# 得到最佳拟合结果 W: [[0.100  0.200]], b: [0.300]

运行:

python  test.py

 

 

本文地址:https://www.sk15.net/archives/243.html
版权声明:本文为原创文章,版权归 sauren 所有,欢迎分享本文,转载请保留出处!
高性能云服务器特惠

发表评论


表情

  1. Tyronemox
    Tyronemox @回复

    Useful knowledge. Regards. canadian pharmacy viagra

  2. RichardDearp
    RichardDearp @回复

    Seriously quite a lot of valuable information! viagra for women

  3. ErnestLip
    ErnestLip @回复

    You explained that terrifically. Tadalafil Sublingual Average Dose

  4. Larrytus
    Larrytus @回复

    With thanks, Plenty of advice!
    Purchase Zoloft 25mg Without Subscription

  5. Louishor
    Louishor @回复

    Nicely put, Appreciate it. drugs for sale

  6. ErnestLip
    ErnestLip @回复

    Very good posts, Appreciate it! How To Buy Tretinoin No Rx

  7. Louishor
    Louishor @回复

    Fantastic information, Cheers! buy cialis online

  8. Larrytus
    Larrytus @回复

    Truly plenty of beneficial facts! drugs for sale

  9. RichardDearp
    RichardDearp @回复

    Nicely put. Cheers. hemp seed oil

  10. Larrytus
    Larrytus @回复

    Very good info, Thanks a lot. sildenafil 100 mg

  11. RichardDearp
    RichardDearp @回复

    Good content. Kudos! viagra pills

  12. Larrytus
    Larrytus @回复

    Thank you! Quite a lot of material!
    northwest pharmacy canada

  13. KelSpipsy
    KelSpipsy @回复

    Levitra 10 Mg Quotazione Donepezil Online Order Buy Cialis Viagra Deutschland Shop Cialis India Pharmacy Topical Keflex Use

  14. Larrytus
    Larrytus @回复

    Really many of beneficial material. buy cialis online

  15. RichardDearp
    RichardDearp @回复

    Cheers! A good amount of information.
    https://viagrapycharm.com/

  16. Larrytus
    Larrytus @回复

    Nicely put. Many thanks! prednisone 5 mg

  17. Larrytus
    Larrytus @回复

    Nicely put. Thank you! diflucan 150 mg

  18. MatVory
    MatVory @回复

    Levothyroxine Buy Online Can Amoxicillin Cure Blackheads Cialis Almond

  19. Larrytus
    Larrytus @回复

    Seriously tons of superb facts! canadian online pharmacies legitimate

  20. KelSpipsy
    KelSpipsy @回复

    Viagra O Similari Amoxicillin And Mononucleosis Acquisto Levitra Senza Ricetta Buy Cialis Amoxicillin And Blood Pressure

  21. MatVory
    MatVory @回复

    Orislat Buy Online Canadian Ems Definicion De Kamagra Propecia Afectivo cialis 40 mg Viagra Super Plus Active Drug Cephalexin

  22. Larrytus
    Larrytus @回复

    Cheers, Valuable information. Purine Muscular Dystrophy Allopurinol

  23. Larrytus
    Larrytus @回复

    Nicely put, Many thanks. domperidone

  24. Larrytus
    Larrytus @回复

    Thanks! I appreciate it. Acheter Cialis Kamagra

  25. Larrytus
    Larrytus @回复

    Info clearly used!! finasterida

  26. Larrytus
    Larrytus @回复

    Wow plenty of excellent material! Phenergan Im

  27. Lesloardy
    Lesloardy @回复

    Laxa Tea buy cialis online Costa Rica Pharmacy Cialis Generic Zentel Discount Low Price Amex Accepted Next Day Delivery Illinois Viagra Uso En Jovenes