Files of TensorFlow

本文详细介绍了TensorFlow中常见的三种模型文件格式:.pb、.pbtxt和.proto,包括它们的定义、作用以及如何在实际操作中进行转换和应用。

TensorFlow的三种文件

1.1 前言

       在使用tensorflow模型时,.pb.pbtxt.proto这三种文件比较常见,本文将对这几种文件的区别及联系进行简单介绍,由于知识水平有限,目前只能提供一种感性认知。

1.2 定义比较

  • .pbtxt
    tensorflow配置文件,定义了网络结构,存储的是结构化数据,定义神经网络中每个节点要储存的信息,具体实例如下:
child_info {
    name: 'Jerry';
    age: 3;
    sex: 0;
}

child_info {
    name: 'Kerry';
    age: 4;
    sex: 0;
}
......
  • .proto
    protobuf是谷歌开源的数据存储语言,其文件以.proto为后缀,可以帮助读取结构化语言,具体实例如下:
syntax = "proto3";

package proto_test;

message Child {
    string name = 1;
    int32 age = 2;
    int32 sex = 3;        
}

message ChildInfo {
    repeated Child child_info = 1;        
}
  • .pb
    为二进制文件,是tensorflow的预训练模型,包含protobuf序列化后的数据,计算图,所有运算符细节,不包含Variable节点,但将其转化为常量,具体实例如下:
0a20 0a04 6461 7461 120b 506c 6163 6568
6f6c 6465 722a 0b0a 0564 7479 7065 1202
3001 0a58 0a23 666c 6174 7465 6e5f 392f
5265 7368 6170 652f 7368 6170 652f 5f31
315f 5f63 665f 5f31 3112 0543 6f6e 7374
2a1d 0a05 7661 6c75 6512 1442 1208 0312
0412 0208 0222 0801 0000 00ff ffff ff2a
0b0a 0564 7479 7065 1202 3003 0a58 0a23
666c 6174 7465 6e5f 382f 5265 7368 6170
652f 7368 6170 652f 5f31 305f 5f63 665f
5f31 3012 0543 6f6e 7374 2a1d 0a05 7661
6c75 6512 1442 1208 0312 0412 0208 0222
0801 0000 00ff ffff ff2a 0b0a 0564 7479
7065 1202 3003 0a56 0a21 666c 6174 7465
6e5f 372f 5265 7368 6170 652f 7368 6170

1.3 作用比较

上述三种文件的使用流程如下:

Alt text

  1. 通过终端命令$ ***/protos/*.proto -- python_out=.可将protos文件夹下的.proto文件转化为.py文件;
  2. .pbtxt文件是结构化数据,使用传统的数据读取方式且要快速方便的解析出其中的信息,并不容易。而使用protobuf则非常便捷,所以借助.py文件读取.pbtxt文件;
  3. .pb文件和读取后的.pbtxt文件结合起来进行相应的运算;

1.4 类比学习

       上面略带专业性的描述似乎还是有点难懂,与现实生活场景斗胆类比一下似乎更便于理解一些。
       我将.proto.pbtxt.pb三个文件与工厂进行一个类比,运行模型的过程就像工厂加工产品。.proto文件就像工厂设计师,它可以看懂工厂的简略设计图.pbtxt。工厂的简略设计图.pbtxt只定义了工厂有哪些厂房,以及厂房的功能。而.pb文件则定义了产品在各厂房间的流转顺序,以及各厂房如何实现自己的功能。输入的变量就像原料,经过各工厂间的流转,输出加工完成的产品。

2.5 Reference

一文看懂Protocol Buffer
TensorFlow 简单 pb (pbtxt) 文件读写
TensorFlow 到底有几种模型格式?

我们很容易掌握AI深度学习。让机器能够模仿人脑的思考方式,从而摆脱原来的固有数据库比较的限制。深度学习的发展课件:链接:https://pan.baidu.com/s/1Ck4GN9N0OCzQgH0MxZOqeQ 提取码:b74k随着机器学习, 深度学习的发展,很多人眼很难去直接量化的特征, 深度学习可以搞定, 这就是深度学习带给我们的优点和前所未有的吸引力。很多特征我们通过传统算法无法量化,或者说很难去做到的, 深度学习可以搞定。特别是在图像分类, 目标检测这些问题上取得了显著的提升。下图是近几年来深度学习在图像分类问题上取得的成绩。●   机器视觉缺陷检测的痛点●   仍存在下面主要的问题和难点 1) 受环境、光照、生产工艺和噪声等多重因素影响,检测系统的信噪比一般较低,微弱信号难以检出或不能与噪声有效区分。如何构建稳定、可靠、鲁棒的检测系统,以适应光照变化、噪声以及其他外界不良环境的干扰,是要解决的问题之一。 2) 由于检测对象多样、表面缺陷种类繁多、形态多样、复杂背景,对于众多缺陷类型产生的机理以及其外在表现形式之间的关系尚不明确,致使对缺陷的描述不充分,缺陷的特征提取有效性不高,缺陷目标分割困难;同时,很难找到“标准”图像作为参照,这给缺陷的检测和分类带来困难,造成识别率尚有待提高。 3) 机器视觉表面缺陷检测,特别是在线检测,其特点是数据量庞大、冗余信息多、特征空间维度高,同时考虑到真正的机器视觉面对的对象和问题的多样性,从海量数据中提取有限缺陷信息的算法能力不足,实时性不高。 4) 与机器视觉表面检测密切相关的人工智能理论虽然得到了很大的发展,但如何模拟人类大脑的信息处理功能去构建智能机器视觉系统还需要理论上的进一步研究,如何更好的基于生物视觉认识、指导机器视觉得检测也是研究人员的难点之一。 5) 从机器视觉表面检测的准确性方面来看,尽管一系列优秀的算法不断出现,但在实际应用中准确率仍然与满足实际应用的需求尚有一定差距,如何解决准确识别与模糊特征之间、实时性与准确性之间的矛盾仍然是目前的难点。 传统算法在某些特定的应用中已经取得了较好的效果,但仍然存在许多不足。例如:图像预处理步骤繁多且具有强烈的针对性,鲁棒性差;多种算法计算量惊人且无法精确的检测缺陷的大小和形状。而深度学习可以直接通过学习数据更新参数,避免了人工设计复杂的算法流程,并且有着极高的鲁棒性和精度。
### TensorFlow on ARM Installation and Usage #### Overview of TensorFlow Support for ARM Architecture TensorFlow provides support for various architectures including ARM, which is commonly used in mobile devices like smartphones and tablets. This allows developers to deploy machine learning models efficiently on these platforms. #### Installing TensorFlow Lite for Android ARM64 Devices For deploying TensorFlow models specifically tailored for Android devices with an ARM64 architecture, one can compile the TensorFlow Lite library using Bazel as shown below: ```bash bazel build -c opt //tensorflow/lite:libtensorflowLite.so --config=android_arm64 --cxxopt="-std=c++11"[^2] ``` This command compiles the `libtensorflowLite.so` shared object file optimized for performance on Android ARM64 systems while adhering to C++11 standards. #### Compiling TensorFlow Library for ARM Systems with Limited Memory Resources When working within environments that have limited memory resources such as embedded systems or low-end hardware running ARM processors, it's advisable to limit the number of parallel jobs during compilation to avoid resource exhaustion. The following example demonstrates how this could be achieved by setting up a two-threaded build process: ```bash bazel build --jobs=2 --config=opt //tensorflow/tools/lib_package:libtensorflow[^4] ``` By specifying `--jobs=2`, only two threads will handle tasks simultaneously throughout the entire building phase, reducing peak RAM consumption significantly without compromising too much speed. #### Python Package Installation Example for Older Versions Like TensorFlow 1.6.0 In some cases where specific versions are required due to compatibility reasons, direct installation from pre-built wheel files might become necessary. An instance involving TensorFlow version 1.6.0 installed via pip under Linux environment would look something similar to what follows: ```bash sudo pip install /tmp/tensorflow_pkg/tensorflow-1.6.0-py2-none-any.whl[^1] ``` Here, `/tmp/tensorflow_pkg/` represents the directory containing the downloaded `.whl` package intended for installation into the system-wide site-packages area accessible through root privileges (`sudo`). --related questions-- 1. What considerations should be taken when choosing between different TensorFlow releases? 2. How does optimizing TensorFlow builds impact application performance on ARM-based devices? 3. Can you provide guidance on troubleshooting common errors encountered during cross-compilation targeting ARM architectures? 4. Are there any best practices recommended for integrating TensorFlow applications onto IoT devices powered by ARM CPUs?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值