【20170630】TensorFlow与python学习(4)-简单例子
来源:互联网 发布:德比鞋 搭配 知乎 编辑:程序博客网 时间:2024/05/21 08:47
1.数学y=0.1*x+0.3的例子
#====TensorFlow学习=====================#例子一#=======================================import tensorflow as tfimport numpy as np#create datax_data=np.random.rand(100).astype(np.float32)y_data=x_data*0.1+0.3#create tensorflow structure start#Weights=tf.Variable(tf.random_uniform([1],-1.0,1.0))biases=tf.Variable(tf.zeros([1]))y=Weights*x_data+biasesloss =tf.reduce_mean(tf.square(y-y_data))optimizer=tf.train.GradientDescentOptimizer(0.5)train=optimizer.minimize(loss)init=tf.initialize_all_variables()#create tensorflow structure end#config = tf.ConfigProto()config.gpu_options.allow_growth = Truesess=tf.Session(config=config)sess.run(init)for step in range(201): sess.run(train) if step%20==0: print(step,sess.run(Weights),sess.run(biases))sess.close()
2.sess两种对话方式
#session会话学习import tensorflow as tfmatrix1 = tf.constant([[3,3]])matrix2 = tf.constant([[2],[2]])product = tf.matmul(matrix1,matrix2)#matrix multiply np.dot(m1,m2)#method 1 # config = tf.ConfigProto()# config.gpu_options.allow_growth = True# sess = tf.Session(config=config)# result = sess.run(product)# print(result)# sess.close()#method 2config = tf.ConfigProto()config.gpu_options.allow_growth = Truewith tf.Session(config=config) as sess: result=sess.run(product) print(result)
阅读全文
0 0
- 【20170630】TensorFlow与python学习(4)-简单例子
- 【20170630】TensorFlow与python学习(1)-安装
- [TensorFlow学习手记] 1-简单例子
- Tensorflow-简单的例子
- TensorFlow简单例子
- tensorflow 简单的例子
- 【20170630】TensorFlow与python学习(2)-Mnist入门
- 【20170630】TensorFlow与python学习(3)-Mnist进阶
- TensorFlow个人学习(下载安装&简单代码例子)
- 深度学习 tensorflow例子
- Python与机器学习之TensorFlow方法论
- tensorflow 学习(2) cnn例子
- 训练神经网络的简单例子(TensorFlow平台下Python实现)
- TensorFlow简单学习1
- Python与自然语言处理(三):Tensorflow基础学习
- Python与自然语言处理(四):TensorFlow基础学习2
- Tensorflow 搭建简单神经网络 | Python
- 简单理解TensorFlow textlinereader的例子
- MATLAB R2014a Builder JA总结
- 多点触控 图片的放大缩小 和 拖拽移动
- 单片机时钟程序(5)ds1302.h
- ubuntu 12.04版本的Qt5.4creator安装qwt6.1.3,亲测,可用
- 关于十六进制发送和显示(VS上位机和下位机)
- 【20170630】TensorFlow与python学习(4)-简单例子
- react学习(ES5和ES6两种写法的对比)
- flexbox-CSS3弹性盒模型flexbox布局完整版教程
- OpenCV 从浮点型数据的视差图中分割并滤除小的斑块
- 【maven&&tomcat】maven自动部署项目到tomcat
- 最短路径:弗洛伊德算法
- struts2基本配置
- binwalk的extract出来的内容
- JavaWeb(7)——Maven学习