# step1 加载包
import tensorflow as tf
import numpy as np

# step2 输入:随机产生数据
# Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data * 0.1 + 0.3

#step 3: 参数:定义参数并初始化
# Try to find values for W and b that compute y_data = W * x_data + b
# (We know that W should be 0.1 and b 0.3, but TensorFlow will
# figure that out for us.)
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = W * x_data + b

#steo 4:预测的值y,损失函数,求解器
# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)

# step 5:初始化
# Before starting, initialize the variables. We will 'run' this first.
init = tf.initialize_all_variables()

# step 6: 创建会话并运行初始化
# Launch the graph.
sess = tf.Session()
sess.run(init) # step 7: 迭代求解
# Fit the line.
for step in range(201):
sess.run(train)
if step % 20 == 0:
print(step, sess.run(W), sess.run(b)) # Learns best fit is W: [0.1], b: [0.3]

tensorflow2的更多相关文章

  1. 基于tensorflow2.0 使用tf.keras实现Fashion MNIST

    本次使用的是2.0测试版,正式版估计会很快就上线了 tf2好像更新了蛮多东西 虽然教程不多 还是找了个试试 的确简单不少,但是还是比较喜欢现在这种写法 老样子先导入库 import tensorflo ...

  2. Google工程师亲授 Tensorflow2.0-入门到进阶

    第1章 Tensorfow简介与环境搭建 本门课程的入门章节,简要介绍了tensorflow是什么,详细介绍了Tensorflow历史版本变迁以及tensorflow的架构和强大特性.并在Tensor ...

  3. TensorFlow2.0(1):基本数据结构—张量

    1 引言 TensorFlow2.0版本已经发布,虽然不是正式版,但预览版都发布了,正式版还会远吗?相比于1.X,2.0版的TensorFlow修改的不是一点半点,这些修改极大的弥补了1.X版本的反人 ...

  4. 『TensorFlow2.0正式版教程』极简安装TF2.0正式版(CPU&GPU)教程

    0 前言 TensorFlow 2.0,今天凌晨,正式放出了2.0版本. 不少网友表示,TensorFlow 2.0比PyTorch更好用,已经准备全面转向这个新升级的深度学习框架了. ​ 本篇文章就 ...

  5. 『TensorFlow2.0正式版』TF2.0+Keras速成教程·零:开篇简介与环境准备

    此篇教程参考自TensorFlow 2.0 + Keras Crash Course,在原文的基础上进行了适当的总结与改编,以适应于国内开发者的理解与使用,水平有限,如果写的不对的地方欢迎大家评论指出 ...

  6. TensorFlow2.0(9):TensorBoard可视化

    .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px so ...

  7. TensorFlow2.0(11):tf.keras建模三部曲

    .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px so ...

  8. TensorFlow2教程(目录)

    第一篇 基本操作 01 Tensor数据类型 02 创建Tensor 03 Tensor索引和切片 04 维度变换 05 Broadcasting 06 数学运算 07 前向传播(张量)- 实战 第二 ...

  9. tensorflow2.0安装

    版本: python3.5 Anaconda 4.2.0 tensorflow2.0 cpu版本 1.安装命令 pip3 install tensorflow==2.0.0.0a0 -i https: ...

  10. 《TensorFlow2深度学习》学习笔记(一)Tensorflow基础

    本系列笔记记录了学习TensorFlow2的过程,主要依据 https://github.com/dragen1860/Deep-Learning-with-TensorFlow-book 进行学习 ...

随机推荐

  1. ado.net C#如何实现数据库增删改查

    ado.net数据库访问技术将数据库中的数据,提取到内存中,展示给用户看还可以将内存中的数据写入数据库中去 并不是唯一的数据库访问技术,但是它是最底层的数据库访问技术也就是说是最麻烦但是是最不可缺少的 ...

  2. struct内存对齐1:gcc与VC的差别

    struct内存对齐:gcc与VC的差别 内存对齐是编译器为了便于CPU快速访问而采用的一项技术,对于不同的编译器有不同的处理方法. Win32平台下的微软VC编译器在默认情况下采用如下的对齐规则:  ...

  3. mac 终端 svn 命令(转)

    mac 终端 svn 命令 1.将文件checkout到本地目录 svn checkout path(path是服务器上的目录)   例如:svn checkout svn://192.168.1.1 ...

  4. 计算城市间的球面距离(C++实现)

    #include<iostream> #include<string> #include<cmath> #include<iomanip> using ...

  5. hihoCoder 1385 : A Simple Job(简单工作)

    hihoCoder #1385 : A Simple Job(简单工作) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 Institute ...

  6. C\C++ 获取当前路径

    C\C++ 获取当前路径   获取当前工作目录是使用函数:getcwd.cwd指的是“current working directory”,这样就好记忆了. 函数说明: 函数原型:char* getc ...

  7. remot debug

    哎,首先吐槽一下,尼玛这是什么编辑器居然不能直接复制粘贴我写好的东西,废话不多说.为什么可以远程调试呢?首先JAVA运行依赖JVM,所以你可以把这种 远程debug想象成两个或者多个JVM之间按照约定 ...

  8. E:Sudoku

    总时间限制: 2000ms 内存限制: 65536kB描述Sudoku is a very simple task. A square table with 9 rows and 9 columns ...

  9. Android 之 Activity的生命周期

  10. android动画的Interpolator

    1.Interpolator插值,控制一个动画变化过程中是线性匀速变化,还是加速变化,还是按照某种函数关系变化. 2.android提供的几种插值. 3.对上边提供的各个效果进行测试 (1)Accel ...