python TensorFlow神经网络 机器学习 深度学习 (一)

TensorFlow

TensorFlow™ 是一个采用数据流图(data flow graphs),用于数值计算的开源软件库。节点(Nodes)在图中表示数学操作,图中的线(edges)则表示在节点间相互联系的多维数据数组,即张量(tensor)。它灵活的架构让你可以在多种平台上展开计算,例如台式计算机中的一个或多个CPU(或GPU),服务器,移动设备等等。TensorFlow 最初由Google大脑小组(隶属于Google机器智能研究机构)的研究员和工程师们开发出来,用于机器学习和深度神经网络方面的研究,但这个系统的通用性使其也可广泛用于其他计算领域。
在学这个期间,大脑要形成由若干神经元组成的神经网络的模型,这样就是快速进入学习这个机器学习,深度学习框架基础。

安装

click here这里不再赘述

进入简单代码入门

//矩阵相乘
import tensorflow as tf

matrix1 = tf.constant([[3, 3]])        //定义常量
matrix2 = tf.constant([[2],
                       [2]])
product = tf.matmul(matrix1, matrix2)  //矩阵相乘
//     method  a
sess = tf.Session()          //运行必须用到Session()
result = sess.run(product)
print result
sess.close()
//     method b
# with tf.Session() as sess:
#     result = sess.run(product)      //  sess.run() 启动整个神经网络
#     #print(result)

输出
########################################
[[12]]
########################################

//简单的神经网络图

《python TensorFlow神经网络 机器学习 深度学习 (一)》 矩阵相乘

下面的类似

//变量加法
import tensorflow as tf

state = tf.Variable(0, name='counter')     //定义变量,name可以不定义
#print state.name     //counter:0

one = tf.constant(1)

new_value = tf.add(state,one)     
update = tf.assign(state, new_value)   //  表示new_value 赋值给state的过程  

init = tf.initialize_all_variables()    //如果有变量,必须写上

with tf.Session() as sess:
    sess.run(init)
    for _ in range(5):
        sess.run(update)
        print sess.run(state)
########################################
1
2
3
4
5
########################################

//placeholder    占位符,先占着位置,最后在添加参数
import tensorflow as tf

input1 = tf.placeholder(tf.float32)  //参数格式有所种,但是类型一定要标明
input2 = tf.placeholder(tf.float32)

output = tf.mul(input1,input2)

with tf.Session() as sess:
    print sess.run(output, feed_dict={input1:[7.],input2:[2.]})   // 传入参数
########################################
[ 14.]
########################################

欢迎关注深度学习自然语言处理公众号

《python TensorFlow神经网络 机器学习 深度学习 (一)》 image

    原文作者:zenRRan
    原文地址: https://www.jianshu.com/p/ee73962eb7d0
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞