当前位置:网站首页>Learning about tensorflow (II)
Learning about tensorflow (II)
2022-07-26 10:13:00 【SingleDog_ seven】
type :
list,np.array,tf.Tensor, among np.array And Tensor be similar , But there are problems : Not very good GPU bonus , No automatic derivation
scalar:1.1 dim=0
vec: [1.1] dim =1
matrix:[[1.1,2.2]] dim = 2
tensor:rank>2 , Generally speaking >0 Just go , occasionally scalar Also belong to tensor.
Use gpu And use cpu:
with tf.device('gpu'): #s Use gpu
b=tf.range(4)
print(b.device)
c=b.cpu()
print(c.device)
print(c.numpy)#numpy cpu
print(c.shape)
print(c.ndim) # dimension
print(tf.rank(c))see c Information about :

Judge whether it is tensor type :
# Judge whether it is tensor
a = tf.constant([1.])
b = np.array(4)
s=isinstance(a,tf.Tensor)
print(s)
s1=isinstance(b,tf.Tensor)
print(s1)
print(a.dtype) # The specific type ![]()
Conversion of types :
# Type conversion
a = np.array(5)
print(a.dtype)
aa = tf.convert_to_tensor(a,dtype=tf.int32)# Turn into tensor dtype Specify the conversion type
# Data type conversion generally uses cast
aaa = tf.cast(aa,dtype=tf.double)
# Boolean and plastic can also be transformed
# Turn into Varible, It has the property of derivation
w = tf.Variable(a)
w.name
w.trainable # Gradient information is required
# int(tensor)Initialization problem :
# Initialize to 0
tf.zeros([])
# Understood as a shape
a = tf.zeros([2,3,3])
tf.zeros_like(a)
#tf.zero(a.shape)
#shape = (2,3,3)
#tf.zeros a.shape Functions are similar
# Initialize to 1
tf.ones()
# Initialize to 9( Customizable )
tf.fill([2,2],9)
# Random initialization
tf.random.normal([2,2],mean=1,stddev=1)
#mean mean value stddev variance
# Don't specify Normal is 0 Of
tf.random.truncated_normal() # truncation The gradient of 0-- The gradient disappears Better performance zeros-- Initialize to 0,ones-- Initialize to 1,fill-- Custom initialization ,random.normal Random initialization
Distribution problem :
# Uniform distribution
tf.random.uniform([2,2],minval=0,maxval=1)
# Break up randomly
idx = tf.range(10)
idx = tf.random.shuffle(idx)
a = tf.random.normal([10,784])
b = tf.random.uniform([10],maxval=10,dtype=tf.int32)
a = tf.gather(a,idx) # same idx
b = tf.gather(b,idx)
This is a simplified method of summing :
loss = tf.keras.losses.mes() #(y-out) And Dim = 3 It's more about dealing with natural language
Dim = 4 More pictures
DIm = 5 Multitasking

边栏推荐
- C language course design Tetris (Part 2)
- protobuf的基本用法
- Error in render: "typeerror: cannot read properties of undefined (reading 'length')" --- error when calling interface
- 新增市场竞争激烈,中国移动被迫推出限制性超低价5G套餐
- 2021 windows penetration of "Cyberspace Security" B module of Shandong secondary vocational group (analysis)
- [MySQL database] a collection of basic MySQL operations - the basis of seeing (adding, deleting, modifying, and querying)
- Node memory overflow and V8 garbage collection mechanism
- IEEE conference upload font problem
- Rowselection emptying in a-table
- 时间序列异常检测
猜你喜欢

Session based recommendations with recurrent neural networks

Due to fierce competition in the new market, China Mobile was forced to launch a restrictive ultra-low price 5g package

How to write a million reading article

B站这个视频我是跪着看完的

Map key not configured and uniapp routing configuration and jump are reported by the uniapp < map >< /map > component

【有奖提问】向图灵奖得主、贝叶斯网络之父 Judea Pearl 提问啦

数通基础-TCPIP参考模型

MySQL 5.7.25 source code installation record

Azkaban【基础知识 01】核心概念+特点+Web界面+架构+Job类型(一篇即可入门Azkaban工作流调度系统)

30分钟彻底弄懂 synchronized 锁升级过程
随机推荐
SPARK中 DS V2 push down(下推)的一些说明
云原生(三十六) | Kubernetes篇之Harbor入门和安装
Study notes of the first week of sophomore year
Uniapp error 7 < Map >: marker ID should be a number
regular expression
Uni app learning summary
How to write a million reading article
Docker configuring MySQL Cluster
MySQL function
Leetcode 504. 七进制数
The use of MySQL in nodejs
The charm of SQL optimization! From 30248s to 0.001s
Sqoop【付诸实践 02】Sqoop1最新版 全库导入 + 数据过滤 + 字段类型支持 说明及举例代码(query参数及字段类型强制转换)
Replay the snake game with C language (II) end
Tableviewcell highly adaptive
反射机制的原理是什么?
Reproduce the snake game in C language (I) build pages and construct snakes
Azkaban [basic knowledge 01] core concepts + features +web interface + Architecture +job type (you can get started with Azkaban workflow scheduling system in one article)
Data communication foundation - layer 2 switching principle
Mysql5.7.25 master-slave replication (one-way)