当前位置:网站首页>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

边栏推荐
- In Net 6.0
- Learning about opencv (2)
- 论文笔记(SESSION-BASED RECOMMENDATIONS WITHRECURRENT NEURAL NETWORKS)
- IE7 set overflow attribute failure solution
- Matlab Simulink realizes fuzzy PID control of time-delay temperature control system of central air conditioning
- 服务器内存故障预测居然可以这样做!
- Formwork (III)
- PMM (percona monitoring and management) installation record
- Interview shock 68: why does TCP need three handshakes?
- Solve NPM -v sudden failure and no response
猜你喜欢

服务器内存故障预测居然可以这样做!

30分钟彻底弄懂 synchronized 锁升级过程

Data communication foundation STP principle

Like, "new programmer" e-book is free for a limited time!

SQL优化的魅力!从 30248s 到 0.001s

点赞,《新程序员》电子书限时免费领啦!

数通基础-TCPIP参考模型

Docker configuring MySQL Cluster

AR model in MATLAB for short-term traffic flow prediction

Leetcode 504. Hex number
随机推荐
Beginner of flask framework-04-flask blueprint and code separation
C language course design Tetris (Part 1)
Data communication foundation TCPIP reference model
SSG framework Gatsby accesses the database and displays it on the page
Leetcode 504. Hex number
汉诺塔II|汉诺塔4柱
Flask framework beginner-03-template
SPARK中 DS V2 push down(下推)的一些说明
Study notes of the first week of sophomore year
Interpretation of the standard of software programming level examination for teenagers_ second level
Write a script that can run in Bash / shell and PowerShell
Leetcode 504. 七进制数
挡不住了,纯国产PC已就位,美国的软硬件体系垄断正式被破
Draw arrows with openlayer
Explain automatic packing and unpacking?
时间序列异常检测
面试突击68:为什么 TCP 需要 3 次握手?
Distributed network communication framework: how to publish local services into RPC services
In Net 6.0
Show default image when wechat applet image cannot be displayed