除了AutoGraph还有 ...... 这两天TensorFlow真是会搞事情

2018 年 7 月 20 日 人工智能头条

编辑 | Jane

出品 | 人工智能头条(公众号ID:AI_Thinker)


【人工智能头条导读】昨天谷歌发布了 TensorFlow 的一个新工具 —— AutoGraph,可以将 Python 代码快速转化到 TensorFlow 的体系里。目前测试来看,这个工具简化了构图流程,加强了 TensorFlow 调用 Python 时的性能。昨天晚上 TensorFlow 又宣布了下一代移动视觉应用支持的新版本 —— MobileNetV2。TensorFlow 官方教程中又不断新增V 1.9 的 eager execution 实例。这几天 TensorFlow 可真是一点没闲着呢。



AutoGraph


我们在 TensorFlow 中构建的计算图比较难理解,尤其是涉及复杂模型的场景,使用 Python 的一些语句,如 if 、while 或接受结构化输入的 print ( ) s时都会有一种无力感。而新工具 AutoGraph 的作用就是自动解决这个问题。


使用 autograph.convert() 装饰器来装饰函数,AutoGraph 将自动生成图可用的代码。


@autograph.convert()
def fizzbuzz(num):
  if num % 3 == 0 and num % 5 == 0:
      print('FizzBuzz')
  elif num % 3 == 0:
      print('Fizz')
  elif num % 5 == 0:
      print('Buzz')
  else:
      print(num)
  return num


with tf.Graph().as_default():
  # The result works like a regular op: takes tensors in, returns tensors.
  # You can inspect the graph using tf.get_default_graph().as_graph_def()
  num = tf.placeholder(tf.int32)
  result = fizzbuzz(num)
  with tf.Session() as sess:
    for n in range(10,16):
      sess.run(result, feed_dict={num:n})


源码中也是给出了 6 个示例,比如:


Assert


@autograph.convert()
def f(x):
  assert x != 0'Do not pass zero!'
  return x * x

with tf.Graph().as_default():  
  with tf.Session():
    try:
      print(f(tf.constant(0)).eval())
    except tf.errors.InvalidArgumentError as e:
      print('Got error message:\n    %s' % e.message)


Print


@autograph.convert()
def f(n):
  if n >= 0:
    while n < 5:
      n += 1
      print(n)
  return n

with tf.Graph().as_default():
  with tf.Session():
    f(tf.constant(0)).eval()


Lists


@autograph.convert()
def f(n):
  z = []
  # We ask you to tell us the element dtype of the list
  autograph.set_element_type(z, tf.int32)

  for i in range(n):
    z.append(i)
  # when you're done with the list, stack it
  # (this is just like np.stack)
  return autograph.stack(z) 

#tf_f = autograph.to_graph(f)

with tf.Graph().as_default():  
  with tf.Session():
    print(f(tf.constant(3)).eval())


If


@autograph.convert()
def nearest_odd_square(x):
  if x > 0:
    x = x * x
    if x % 2 == 0:
      x = x + 1
  return x

with tf.Graph().as_default():  
  with tf.Session() as sess:
    print(sess.run(nearest_odd_square(tf.constant(4))))
    print(sess.run(nearest_odd_square(tf.constant(5))))
    print(sess.run(nearest_odd_square(tf.constant(6))))


While Loop


@autograph.convert()
def square_until_stop(x, y):
  while x < y:
    x = x * x
  return x

with tf.Graph().as_default():  
  with tf.Session() as sess:
    print(sess.run(square_until_stop(tf.constant(4), tf.constant(100))))


Break


@autograph.convert()
def argwhere_cumsum(x, threshold):
  current_sum = 0.0
  idx = 0
  for i in range(len(x)):
    idx = i
    if current_sum >= threshold:
      break
    current_sum += x[i]
  return idx

N = 10
with tf.Graph().as_default():  
  with tf.Session() as sess:
    idx = argwhere_cumsum(tf.ones(N), tf.constant(float(N/2)))
    print(sess.run(idx))


大家知道这个消息后也纷纷跃跃欲试,不仅尝试了官方示例,还有自己的新发现。

 

via:微博用户@王咏刚

(https://weibo.com/ygwang?refer_flag=1001030103_)


via:微博用户@tobe-陈迪豪

(https://weibo.com/tobegit3hub?profile_ftype=1&is_ori=1#_0)


AutoGraph 打开了构建和训练模型的新思路,虽然现在还是实验工具,不过,官方表示会尽快转移到核心的 TensorFlow 中,建议未来可以尝试添加更多的功能到 AutoGraph 中,如果广大的开发爱好者们有自己的心得与建议也可以加入进来,不断完善。


GitHub 地址:

https://github.com/tensorflow/models/blob/master/samples/core/guide/autograph.ipynb


Colab 链接:

https://colab.research.google.com/github/tensorflow/models/blob/master/samples/core/guide/autograph.ipynb



MobileNetV2


昨天,TensorFlow 很高兴地宣布——发布 MobileNetV2 ,它将为下一代移动视觉应用提供支持。


去年,TensorFlow 引入了面向移动设备设计的通用型计算机视觉神经网络 ——MobileNetV1,可支持分类和检测等功能。在个人移动设备上运行深度网络可以提升用户体验,并允许随时随地访问,并且在安全性、隐私和能耗方面同样具有优势。随着让用户与现实世界实时交互的新应用的不断出现,对更高效神经网络的需求也逐渐增加。


MobileNetV2 在 MobileNetV1 的基础上进行了重大改进,并推动了移动视觉识别技术的发展,包括分类、对象检测和语义分割。


MobileNetV2 架构概览

蓝色块表示上面所示的复合卷积构建块

   

MobileNetV2 提高了速度(缩短了延迟时间)并提高了 ImageNet Top 1 的准确度


在检测方面,与新引入的 SSDLite 搭配使用时,在实现相同准确性的情况下,新模型的速度要比 MobileNetV1 快大约 35%。


为实现设备上语义分割,在近期宣布的 DeepLabv3 简化版中采用 MobileNetV2 作为特征提取器。与使用 MobileNetV1 作为特征提取器的性能相似,但前者的参数数量减少 5.3 倍,乘加运算数量减少 5.2 倍。


 更多内容大家可以参考:

1.MobileNets:Efficient Convolutional Neural Networks for Mobile Vision Applications, Howard AG, Zhu M, Chen B, Kalenichenko D, Wang W, Weyand T, Andreetto M, Adam H, arXiv:1704.04861, 2017.


2.MobileNetV2:Inverted Residuals and Linear Bottlenecks, Sandler M, Howard A, Zhu M, Zhmoginov A, Chen LC. arXiv preprint. arXiv:1801.04381, 2018.


3.Rethinking Atrous Convolution for Semantic Image Segmentation, Chen LC, Papandreou G, Schroff F, Adam H. arXiv:1706.05587, 2017.


4.Speed/accuracy trade-offs for modern convolutional object detectors, Huang J, Rathod V, Sun C, Zhu M, Korattikara A, Fathi A, Fischer I, Wojna Z, Song Y, Guadarrama S, Murphy K, CVPR 2017.


5.Deep Residual Learning for Image Recognition, He, Kaiming, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. arXiv:1512.03385,2015



TensorFlow官方教程:

新增1.9版eager execution实例


自上周新版本 V 1.9 发布以来,TensorFlow 官方教程中又不断新增 eager execution 实例,主要包括:注意力机器翻译、文本生成、图像自动描述等教程。大家又可以在周末开始一波操作了!



官方链接:

https://www.tensorflow.org/tutorials/



——【完】——



在线公开课NLP专场

精彩继续


时间:7月26日 20:00-21:00

扫描海报二维码,免费报名

添加微信csdnai,备注:公开课,加入课程交流群

登录查看更多
0

相关内容

一份循环神经网络RNNs简明教程,37页ppt
专知会员服务
170+阅读 · 2020年5月6日
斯坦福2020硬课《分布式算法与优化》
专知会员服务
117+阅读 · 2020年5月6日
专知会员服务
109+阅读 · 2020年3月12日
2019年机器学习框架回顾
专知会员服务
35+阅读 · 2019年10月11日
机器学习入门的经验与建议
专知会员服务
90+阅读 · 2019年10月10日
TensorFlow 2.0 学习资源汇总
专知会员服务
66+阅读 · 2019年10月9日
TensorFlow 2.0新特性之Ragged Tensor
深度学习每日摘要
18+阅读 · 2019年4月5日
利用 TensorFlow 实现排序和搜索算法
机器学习研究会
5+阅读 · 2017年11月23日
tensorflow项目学习路径
北京思腾合力科技有限公司
10+阅读 · 2017年11月23日
python数据分析师面试题选
数据挖掘入门与实战
6+阅读 · 2017年11月21日
终于!TensorFlow引入了动态图机制Eager Execution
深度学习世界
5+阅读 · 2017年11月1日
手把手教TensorFlow(附代码)
深度学习世界
15+阅读 · 2017年10月17日
手把手教你由TensorFlow上手PyTorch(附代码)
数据派THU
5+阅读 · 2017年10月1日
Arxiv
19+阅读 · 2018年10月25日
Arxiv
3+阅读 · 2018年2月22日
Arxiv
7+阅读 · 2018年1月30日
Arxiv
23+阅读 · 2017年3月9日
VIP会员
相关VIP内容
一份循环神经网络RNNs简明教程,37页ppt
专知会员服务
170+阅读 · 2020年5月6日
斯坦福2020硬课《分布式算法与优化》
专知会员服务
117+阅读 · 2020年5月6日
专知会员服务
109+阅读 · 2020年3月12日
2019年机器学习框架回顾
专知会员服务
35+阅读 · 2019年10月11日
机器学习入门的经验与建议
专知会员服务
90+阅读 · 2019年10月10日
TensorFlow 2.0 学习资源汇总
专知会员服务
66+阅读 · 2019年10月9日
相关资讯
TensorFlow 2.0新特性之Ragged Tensor
深度学习每日摘要
18+阅读 · 2019年4月5日
利用 TensorFlow 实现排序和搜索算法
机器学习研究会
5+阅读 · 2017年11月23日
tensorflow项目学习路径
北京思腾合力科技有限公司
10+阅读 · 2017年11月23日
python数据分析师面试题选
数据挖掘入门与实战
6+阅读 · 2017年11月21日
终于!TensorFlow引入了动态图机制Eager Execution
深度学习世界
5+阅读 · 2017年11月1日
手把手教TensorFlow(附代码)
深度学习世界
15+阅读 · 2017年10月17日
手把手教你由TensorFlow上手PyTorch(附代码)
数据派THU
5+阅读 · 2017年10月1日
Top
微信扫码咨询专知VIP会员