技术前沿之TensorFlow(24) 点击:95 | 回复:3



PLC军团长

    
  • [版主]
  • 精华:9帖
  • 求助:31帖
  • 帖子:1460帖 | 7990回
  • 年度积分:457
  • 历史总积分:59176
  • 注册:2004年7月13日
发表于:2018-05-05 11:04:46
楼主

张量的阶、形状、数据类型

TensorFlow用张量这种数据结构来表示所有的数据.你可以把一个张量想象成一个n维的数组或列表.一个张量有一个静态类型和动态类型的维数.张量可以在图中的节点之间流通.

在TensorFlow系统中,张量的维数来被描述为.但是张量的阶和矩阵的阶并不是同一个概念.张量的阶(有时是关于如顺序度数或者是n维)是张量维数的一个数量描述.比如,下面的张量(使用Python中list定义的)就是2阶.

    t = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

你可以认为一个二阶张量就是我们平常所说的矩阵,一阶张量可以认为是一个向量.对于一个二阶张量你可以用语句t[i, j]来访问其中的任何元素.而对于三阶张量你可以用't[i, j, k]'来访问其中的任何元素.

数学实例Python 例子
0纯量 (只有大小)s = 483
1向量(大小和方向)v = [1.1, 2.2, 3.3]
2矩阵(数据表)m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
33阶张量 (数据立体)t = [[[2], [4], [6]], [[8], [10], [12]], [[14], [16], [18]]]
nn阶 (自己想想看)....

形状

TensorFlow文档中使用了三种记号来方便地描述张量的维度:阶,形状以及维数.下表展示了他们之间的关系:

形状维数实例
0[  ]0-D一个 0维张量.  一个纯量.
1[D0]1-D一个1维张量的形式[5].
2[D0, D1]2-D一个2维张量的形式[3, 4].
3[D0, D1, D2]3-D一个3维张量的形式 [1, 4, 3].
n[D0, D1, ... Dn]n-D一个n维张量的形式 [D0, D1, ... Dn].

形状可以通过Python中的整数列表或元祖(int list或tuples)来表示,也或者用TensorShape class.

数据类型

除了维度,Tensors有一个数据类型属性.你可以为一个张量指定下列数据类型中的任意一个类型:

数据类型Python 类型描述
DT_FLOATtf.float3232 位浮点数.
DT_DOUBLEtf.float6464 位浮点数.
DT_INT64tf.int6464 位有符号整型.
DT_INT32tf.int3232 位有符号整型.
DT_INT16tf.int1616 位有符号整型.
DT_INT8tf.int88  位有符号整型.
DT_UINT8tf.uint88  位无符号整型.
DT_STRINGtf.string可变长度的字节数组.每一个张量元素都是一个字节数组.
DT_BOOLtf.bool布尔型.
DT_COMPLEX64tf.complex64由两个32位浮点数组成的复数:实数和虚数.
DT_QINT32tf.qint32用于量化Ops的32位有符号整型.
DT_QINT8tf.qint8用于量化Ops的8位有符号整型.
DT_QUINT8tf.quint8用于量化Ops的8位无符号整型.

1分不嫌少!


楼主最近还看过



PLC军团长

  • [版主]
  • 精华:9帖
  • 求助:31帖
  • 帖子:1460帖 | 7990回
  • 年度积分:457
  • 历史总积分:59176
  • 注册:2004年7月13日
发表于:2018-05-07 14:24:56
1楼
Classtensorflow::Env Aninterfaceusedbythetensorflowimplementationtoaccessoperatingsystemfunctionalitylikethefilesystemetc. CallersmaywishtoprovideacustomEnvobjecttogetfinegraincontrol. AllEnvimplementationsaresafeforconcurrentaccessfrommultiplethreadswithoutanyexternalsynchronization. MemberSummary tensorflow::Env::Env() virtualtensorflow::Env::~Env() virtualStatustensorflow::Env::NewRandomAccessFile(conststring&fname,RandomAccessFile**result)=0 Createsabrandnewrandomaccessread-onlyfilewiththespecifiedname. virtualStatustensorflow::Env::NewWritableFile(conststring&fname,WritableFile**result)=0 Createsanobjectthatwritestoanewfilewiththespecifiedname. virtualStatustensorflow::Env::NewAppendableFile(conststring&fname,WritableFile**result)=0 Createsanobjectthateitherappendstoanexistingfile,orwritestoanewfile(ifthefiledoes_disibledevent="x_static-env-tensorflowenvdefault-">staticEnv*tensorflow::Env::Default() Returnsadefaultenvironmentsuitableforthecurrentoperatingsystem. SophisticatedusersmaywishtoprovidetheirownEnvimplementationinsteadofrelyingonthisdefaultenvironment. TheresultofDefault()belongstothislibraryandmustneverbedeleted.

PLC军团长

  • [版主]
  • 精华:9帖
  • 求助:31帖
  • 帖子:1460帖 | 7990回
  • 年度积分:457
  • 历史总积分:59176
  • 注册:2004年7月13日
发表于:2018-05-07 14:25:37
2楼
Classtensorflow::EnvWrapper AnimplementationofEnvthatforwardsallcallstoanotherEnv. MaybeusefultoclientswhowishtooverridejustpartofthefunctionalityofanotherEnv. MemberSummary tensorflow::EnvWrapper::EnvWrapper(Env*t) InitializesanEnvWrapperthatdelegatesallcallsto*t. virtualtensorflow::EnvWrapper::~EnvWrapper() Env*tensorflow::EnvWrapper::target()const ReturnsthetargettowhichthisEnvforwardsallcalls. Statustensorflow::EnvWrapper::NewRandomAccessFile(conststring&f,RandomAccessFile**r)override Createsabrandnewrandomaccessread-onlyfilewiththespecifiedname. Statustensorflow::EnvWrapper::NewWritableFile(conststring&f,WritableFile**r)override Createsanobjectthatwritestoanewfilewiththespecifiedname. Statustensorflow::EnvWrapper::NewAppendableFile(conststring&f,WritableFile**r)override Createsanobjectthateitherappendstoanexistingfile,orwritestoanewfile(ifthefiledoes_disibledevent="x_Thread_tensorflow_EnvWrapper_StartThread"> Returnsanewthreadthatisrunningfn()andisidentified(fordebugging/performance-analysis)by"name". Callertakesownershipoftheresultandmustdeleteiteventually(thedeletionwillblockuntilfn()stopsrunning).

PLC军团长

  • [版主]
  • 精华:9帖
  • 求助:31帖
  • 帖子:1460帖 | 7990回
  • 年度积分:457
  • 历史总积分:59176
  • 注册:2004年7月13日
发表于:2018-05-07 14:26:15
3楼
Classtensorflow::RandomAccessFile Afileabstractionforrandomlyreadingthecontentsofafile. MemberSummary tensorflow::RandomAccessFile::RandomAccessFile() virtualtensorflow::RandomAccessFile::~RandomAccessFile() virtualStatustensorflow::RandomAccessFile::Read(uint64offset,size_tn,StringPiece*result,char*scratch)const=0 Readsupto"n"bytesfromthefilestartingat"offset". MemberDetails tensorflow::RandomAccessFile::RandomAccessFile() virtualtensorflow::RandomAccessFile::~RandomAccessFile() virtualStatustensorflow::RandomAccessFile::Read(uint64offset,size_tn,StringPiece*result,char*scratch)const=0 Readsupto"n"bytesfromthefilestartingat"offset". "scratch[0..n-1]"maybewrittenbythisroutine.Sets"result"tothedatathatwasread(includingiffewerthan"n"bytesweresuccessfullyread).Mayset"result"topointatdatain"scratch[0..n-1]",so"scratch[0..n-1]"mustbelivewhen"*result"isused. OnOKreturnedstatus:"n"byteshavebeenstoredin"result".Onnon-OKreturnedstatus:[0..n]byteshavebeenstoredin"result". ReturnsOUT_OF_RANGEiffewerthannbyteswerestoredin"*result"becauseofEOF. Safeforconcurrentusebymultiplethreads.

热门招聘
相关主题

官方公众号

智造工程师