TensorFlow 2.7正式版上线,支持Jax模型到TensorFlow Lite转换

开发 前端
TensorFlow2.7 正式发布,新版本包括对 tf.keras、tf.lite 等模块的改进;tf.data 现在可以支持自动分片(auto-sharding);添加实验性 API Experiment_from_jax 以支持从 Jax 模型到 TensorFlow Lite 的转换。

 

「调试代码(debug)是框架用户体验的关键部分,更轻松的调试意味着更快的迭代周期。在此版本中,我们通过三个主要更改对 TF/Keras 调试体验进行了广泛的重新设计,使其更高效、更有趣……」谷歌科学家,Keras 发明者 François Chollet 说道。

11 月 5 日,TensorFlow 官方发布了 2.7 正式版,距离上次 2.6.1 的更新刚过去一个月时间。

TensorFlow 2.7正式版上线,支持Jax模型到TensorFlow Lite转换

在 TensorFlow 博客上,官方简述了新版本的主要升级内容:

TensorFlow 2.7 主要变化

tf.keras:

  • Model.fit()、 Model.predict() 和 Model.evaluate()方法将不再把 (batch_size, ) 的输入数据上升为 (batch_size, 1)。这使得 Model 子类能够在其 train_step()/ test_step()/ predict_step()方法中处理标量数据;
  • Model.to_yaml()和 keras.models.model_from_yaml 方法已被替换为引发 RuntimeError,因为它们可能被滥用以导致任意代码执行。建议使用 JSON 序列化而不是 YAML,或者,一个更好的替代方案,序列化到 H5;
  • LinearModel 和 WideDeepModel 被移至 tf.compat.v1.keras.models. 命名空间( tf.compat.v1.keras.models.LinearModel 和 tf.compat.v1.keras.models.WideDeepModel),其 experimental 端点 tf.keras.experimental.models.LinearModel 和 tf.keras.experimental.models.WideDeepModel 被弃用;
  • 所有 tf.keras.initializers 类的 RNG 行为改变,这一变化将使初始化行为在 v1 和 v2 之间保持一致。

tf.lite:

  • 重命名 schema 中的 SignatureDef 表,以最大化与 TF SavedModel Signature 概念的奇偶校验。
  • 弃用 Makefile 构建,Makefile 用户需要将他们的构建迁移到 CMake 或 Bazel。
  • 弃用 tflite::OpResolver::GetDelegates。TfLite 的 BuiltinOpResolver::GetDelegates 所返回的列表现在总是空的。相反,建议使用新方法 tflite::OpResolver::GetDelegateCreators。

TF Core:

  • tf.Graph.get_name_scope() 现在总是返回一个字符串。之前当在 name_scope("") 或 name_scope(None) 上下文中调用时,它返回 None, 现在它返回空字符串;
  • tensorflow/core/ir/ 包含一个新的基于 MLIR 的 Graph dialect,它与 GraphDef 同构,并将用于替换基于 GraphDef(例如 Grappler)的优化;
  • 弃用并删除了形状推理中的 attrs() 函数,现在所有的属性都应该通过名字来查询。
  • 以下 Python 符号是在 TensorFlow 的早期版本中意外添加的,现在已被删除。每个符号都有一个替换项,但请注意替换项的参数名称是不同的:
      • tf.quantize_and_dequantize_v4(在 TensorFlow 2.4 中意外引入):改用 tf.quantization.quantize_and_dequantize_v2;
      • tf.batch_mat_mul_v3(在 TensorFlow 2.6 中意外引入):改用 tf.linalg.matmul;
      • tf.sparse_segment_sum_grad(在 TensorFlow 2.6 中意外引入):改用 tf.raw_ops.SparseSegmentSumGrad。

将 tensorflow::int64 重命名为 int_64_t(前者是后者的别名)。

模块化文件系统的迁移:

对 S3 和 HDFS 文件系统的支持已经迁移到一个基于模块化文件系统的方法,现在可以在 https://github.com/tensorflow/io 中使用。用户需要安装 tensorflow-io python 包,以支持 S3 和 HDFS。

TensorFlow 2.7 主要功能和改进

对 TensorFlow 调试经验的改进:以前,TensorFlow 错误堆栈跟踪涉及许多内部帧,读出这些帧可能具有挑战性,而且对最终用户而言不可操作。从 TF 2.7 开始,TensorFlow 在它引发的大多数错误中过滤内部帧,以保持堆栈跟踪简短、可读,并专注于最终用户可操作的内容。

通过在每个异常中添加传递给该层的参数值的完整列表,提高由 Keras Layer.__call__()引发的错误消息信息量。

tf.data:tf.data 服务现在支持自动分片(auto-sharding)。用户通过 tf.data.experimental.service.ShardingPolicy 枚举指定分片策略;tf.data.experimental.service.register_dataset 现在接受可选的 compression 参数。

Keras:tf.keras.layers.Conv 现在包含一个公共的 convolution_op 方法。此方法可用于简化 Conv 子类的实现,有两种方式使用这个新方法,第一种方法如下:

  1. class StandardizedConv2D(tf.keras.layers.Conv2D): 
  2.     def call(self, inputs): 
  3.       mean, var = tf.nn.moments(self.kernel, axes=[012], keepdims=True) 
  4.       return self.convolution_op(inputs, (self.kernel - mean) / tf.sqrt(var + 1e-10)) 

你也可以采用如下方法:

  1. class StandardizedConv2D(tf.keras.Layer): 
  2.     def convolution_op(self, inputs, kernel): 
  3.       mean, var = tf.nn.moments(kernel, axes=[012], keepdims=True) 
  4.       # Author code uses std + 1e-5 
  5.       return super().convolution_op(inputs, (kernel - mean) / tf.sqrt(var + 1e-10)) 
  • 向 tf.keras.metrics.Metric 添加了 merge_state() 方法以用于分布式计算;
  • 向 tf.keras.layers.TextVectorization 添加了 sparse 和 ragged 的选项,以允许来自层的 SparseTensor 和 RaggedTensor 输出。

tf.lite:添加 experimental API Experiment_from_jax 以支持从 Jax 模型到 TensorFlow Lite 的转换;支持 uint32 数据类型;添加实验量化调试器 tf.lite.QuantizationDebugger。

更多详情可查看:

https://github.com/tensorflow/tensorflow/releases/tag/v2.7.0

 

责任编辑:张燕妮 来源: 机器之心Pro
相关推荐

2018-04-15 21:49:29

开发者 TensorFlow谷歌

2019-01-11 14:32:09

TensorFlow 机器之心谷歌

2021-09-12 13:23:38

微软WSL机器学习

2021-07-13 08:43:00

GoogleTensorFlow AI

2022-06-15 14:48:39

谷歌TensorFlowMeta

2019-12-04 09:54:03

深度学习编程人工智能

2014-12-17 09:26:26

GoAndroid

2010-07-05 09:50:29

PythonPython 2.7

2013-02-28 09:33:58

DjangoPython

2009-02-09 15:44:37

Chrome 1.0正下载

2022-02-08 15:47:44

TensorFlow功能新版

2012-08-02 13:22:04

Chrome 21浏览器

2010-04-01 10:16:32

Hibernate

2011-05-20 10:18:51

RHEL 6.1红帽

2017-12-29 15:42:13

LinuxLite 3.8 Be正式版

2017-03-12 10:38:56

Chromewindows

2009-04-09 17:09:32

LinuxVirtualBox

2012-04-14 20:44:14

PhoneGap

2022-06-16 15:13:26

龙蜥操作系统自研操作系统

2011-05-18 09:29:30

IntelliJ
点赞
收藏

51CTO技术栈公众号