TensorFlow   1

分类: 1,protocol Buffer  处理结构化数据工具; (xml,json)

   2,Bazel        自动化构建工具, 编译;

tensor 张量;    张量就是多维数组;

flow  流;

两个阶段:1   定义计算图中所有的计算;

      2,执行计算;

张量tensor:

  1,多维数组;

  2,零阶张量表示标量(scalar),就是一个数;

  3,一阶张量表示为向量(vector), 是一维数组;

  。。。。。

     第n阶 --------------------------------n 维数组;

一个张量主要保存三个属性; name  名字、  shape 维度、     type  类型  ;

张量的使用:

  用途分类:1, 对中间计算结果的引用;

      2, 当计算图构造完成之后,张量可以用来获得计算结果,也就是得到真实数字;

1, 练习

[root@shenzhen ~]# cat /server/tensorflow/tensor1.py
#!/usr/local/bin/python3
#coding:utf-8 import tensorflow as tf
import numpy as np #create data
x_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 + biases loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss) #init = tf.initialize_all_variables()
init = tf.global_variables_initializer()
###create tensorflow structure start### sess = tf.Session()
sess.run(init) #very important for step in range(201):
sess.run(train)
if step % 20 == 0:
print(step, sess.run(Weights), sess.run(biases)) [root@shenzhen tensorflow]# python3 tensor1.py
2018-08-20 20:58:14.585672: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
0 [0.5822645] [0.00799593]
20 [0.27060172] [0.19762385]
40 [0.16020724] [0.26387033]
60 [0.12124781] [0.28724945]
80 [0.10749861] [0.2955002]
100 [0.10264634] [0.29841197]
120 [0.10093395] [0.29943955]
140 [0.10032961] [0.2998022]
160 [0.10011631] [0.2999302]
180 [0.10004105] [0.2999754]
200 [0.10001447] [0.29999134]

2,Session  会话 : 运行模型

[root@shenzhen tensorflow]# python3 tensor2.py
2018-08-21 20:02:22.863676: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
[[12]]
[root@shenzhen tensorflow]# vim tensor2.py
[root@shenzhen tensorflow]# python3 tensor2.py
2018-08-21 20:05:11.457492: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
[[12]]
[root@shenzhen tensorflow]# cat tensor2.py
#!/usr/local/bin/python3
#coding:utf-8 import tensorflow as tf matrix1 = tf.constant([[3,3]])
matrix2 = tf.constant([[2],
[2]])
product = tf.matmul(matrix1,matrix2) #matrix multiply np.dot(m1,m2) #method1
#sess = tf.Session()
#result = sess.run(product)
#print(result)
#sess.close() #method2
with tf.Session() as sess:
result2 = sess.run(product)
print(result2)

3, tensorflow   变量

创建变量;

[root@shenzhen tensorflow]# python3 tensor3.py
2018-08-21 20:48:45.724496: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
1
2
3
[root@shenzhen tensorflow]# cat tensor3.py
#!/usr/local/bin/python3
#coding:utf-8 import tensorflow as tf state = tf.Variable(0, name='counter')
#print(state.name)
one = tf.constant(1) new_value = tf.add(state, one)
update = tf.assign(state, new_value) init = tf.global_variables_initializer() #must have if define variable with tf.Session() as sess:
sess.run(init)
for _ in range(3):
sess.run(update)
print(sess.run(state))

tensorflow 传入值:

[root@shenzhen tensorflow]# python3 tensor4.py
2018-08-22 19:39:44.495986: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
[21.]
[root@shenzhen tensorflow]# cat tensor4.py
#!/usr/local/bin/python3
#coding:utf-8 import tensorflow as tf input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32) output = tf.multiply(input1,input2) with tf.Session() as sess:
print(sess.run(output, feed_dict={input1:[7.], input2:[3.]}))

框架tensorflow1的更多相关文章

  1. TensorFlow学习笔记(MNIST报错修正 适用Tensorflow1.3)

    在Tensorflow实战Google框架下的深度学习这本书的MNIST的图像识别例子中,每次都要报错   错误如下: Only call `sparse_softmax_cross_entropy_ ...

  2. 从TensorFlow 到 Caffe2:盘点深度学习框架

    机器之心报道 本文首先介绍GitHub中最受欢迎的开源深度学习框架排名,然后再对其进行系统地对比 下图总结了在GitHub中最受欢迎的开源深度学习框架排名,该排名是基于各大框架在GitHub里的收藏数 ...

  3. 开源框架---通过Bazel编译使用tensorflow c++ API 记录

    开源框架---通过Bazel编译使用tensorflow c++ API 记录 tensorflow python API,在python中借用pip安装tensorflow,真的很方便,几句指令就完 ...

  4. 【实践】如何利用tensorflow的object_detection api开源框架训练基于自己数据集的模型(Windows10系统)

    如何利用tensorflow的object_detection api开源框架训练基于自己数据集的模型(Windows10系统) 一.环境配置 1. Python3.7.x(注:我用的是3.7.3.安 ...

  5. 避免重复造轮子的UI自动化测试框架开发

    一懒起来就好久没更新文章了,其实懒也还是因为忙,今年上半年的加班赶上了去年一年的加班,加班不息啊,好了吐槽完就写写一直打算继续的自动化开发 目前各种UI测试框架层出不穷,但是万变不离其宗,驱动PC浏览 ...

  6. ABP入门系列(1)——学习Abp框架之实操演练

    作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...

  7. 旺财速啃H5框架之Bootstrap(五)

    在上一篇<<旺财速啃H5框架之Bootstrap(四)>>做了基本的框架,<<旺财速啃H5框架之Bootstrap(二)>>篇里也大体认识了bootst ...

  8. Angular企业级开发(5)-项目框架搭建

    1.AngularJS Seed项目目录结构 AngularJS官方网站提供了一个angular-phonecat项目,另外一个就是Angular-Seed项目.所以大多数团队会基于Angular-S ...

  9. Scrapy框架爬虫初探——中关村在线手机参数数据爬取

    关于Scrapy如何安装部署的文章已经相当多了,但是网上实战的例子还不是很多,近来正好在学习该爬虫框架,就简单写了个Spider Demo来实践.作为硬件数码控,我选择了经常光顾的中关村在线的手机页面 ...

随机推荐

  1. Python 协程并发爬虫网页

    简单爬虫实例: 功能:通过urllib.request实现网站爬虫,捕获网站内容. from urllib import request def f(url): print("GET:%s& ...

  2. linux --- 6. 项目部署

    一.负载均衡 .准备三台机器,准备3台虚拟机,或者和俩同桌交流一下 192.168.226.128 是nginx资源服务器,返回页面的 192.168.226.129 用作nginx负载均衡服务器 1 ...

  3. udp套接字及利用socketserver模块实现并发以及并发编程

    一:基于udp协议(数据报协议)的套接字:和tcp协议的套接字对比而言,由于udp是无链接的,所以先启动哪一端都不会报错,而且udp也不会有粘包 现象,所以对比下来,tcp协议的话传输数据更加可靠,但 ...

  4. Angular4学习笔记(四)- 依赖注入

    概念 依赖注入是一种设计思想,并不是某一类语言所特有的,因此可以参考开涛大神关于学习Java语言的Spring框架时对其的解释: DI-Dependency Injection,即"依赖注入 ...

  5. Asp.net core 学习笔记 (library)

    refer : https://docs.microsoft.com/en-us/dotnet/core/tutorials/library-with-visual-studio https://do ...

  6. C#退出程序方法分类

    1.this.Close();   只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退出:

  7. CentOS6上ftp服务器搭建实战

    1.安装程序包 [root@node1 ~]$ yum install -y vsftpd[root@node1 ~]$ yum install -y lftp # 安装测试软件 2.启动vsftpd ...

  8. centos7.4安装nginx

    参考地址: https://blog.csdn.net/weixin_41048363/article/details/80236663 我这里没有使用阿帕奇之类的服务器,只搭建了node环境.所以并 ...

  9. C++中数组声名后不初始化,数组里的值都是0吗?

    这得看数组的申明情况: 1.全局/静态数组 如果申明的是全局/静态数组,系统会把数组的内容自动初始化为0. 2.局部数组 如果申明的是局部数组,数组的内容会是随机的,不一定是0.如函数内声明: int ...

  10. Spring cloud系列之Zuul配置项中sensitiveHeaders和ignoredHeaders

    sensitiveHeaders:会过滤客户端请求中的和该配置项匹配的headers比如: zuul: sensitiveHeaders: X-ABC 如果客户端在发请求是带了X-ABC,那么X-AB ...