Tensorflow(1)

TensorFlow的tf.random_uniform( ) 函数的用法

tf.random_uniform(shape, minval=low,maxval=high,dtype)))

返回shape型矩阵,产生于low和high之间的值,属于均匀分布。

TensorFlow四舍五入:tf.round()函数的用法

tf.round( x, name=None ):

参数:x:一个Tensor,类型必须为float32和float64。name:操作名称(可选)。

返回:tf.round函数返回一个与x具有相同的形状和类型的Tensor。

TensorFlow的tf.cast( ) 函数的用法

tf.cast( x, dtype,name=None):将x的数据格式转化成dtype.

TensorFlow的tf.reshape( ) 函数的用法

tf.reshape(tensor, shape, name=Name): 

参数: tensor为被调整维度的张量。shape:参数为要调成的形状。name:操作名称(可选)。

返回:一个shape形状的新tensor. 

TensorFlow的tf.image.pad_to_bounding_box( ) 函数的用法

tf.image.pad_to_bounding_box( image, offset_height, offset_width, target_height, target_width )

参数:image:形状为[batch, height, width, channels]的4维张量,或形状为[height, width, channels]的3维张量。

 offset_height:在顶部添加零的行数。   offset_width:在左侧添加的零的列数。

target_height:输出图像的高度。         target_width :输出图像的宽度。

返回:

如果image是四维,则返回形状为[batch, target_height, target_width, channels]的四维浮点型张量;

如果image是三维的,则返回形状为[target_height, target_width, channels]的三维浮点型张量

TensorFlow的tf.image.resize_bilinear( ) 函数的用法

tf.image.resize_bulinear(images, size, name= None):调整imagessize使用双线性插值。

参数:images:一个4-D的张量[batch, height, width, channels]  size:裁剪后新图像的大小

TensorFlow的tf.constant( ) 函数的用法

tf.constant(value, dtype=None, shape=None,..):创建一个常数张量,传入list或者数值来填充

tensor = tf.constant([1, 2, 3, 4, 5]) => [1 2 3 4 5]

a = tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3]) => [[1. 2. 3.] [4. 5. 6.]]

TensorFlow的tf.tile( ) 函数的用法

tf.tile( input, multiples, name=None ): 平铺之意,用于在同一维度上的复制

参数:input, 输入            multiples: 同一维度上复制的次数。

TensorFlow的tf.slice( ) 函数的用法

tf.slice(input_, begin, size, name =None):从输入input数据中从以begin开始剪切size大小的切片。

TensorFlow的tf.stack( ) 函数的用法

tf.stack其作用类似于tf.concat,都是拼接两个张量,tf.stack则会在新的张量阶上拼接,产生的张量的阶数将会增加,axis是决定stack张量的维度方向(0:一维。1:二维。2:三维)。

a = tf.constant([[1,2,3],[3,4,5]]) # shape (2,3)
b = tf.constant([[7,8,9],[10,11,12]]) # shape (2,3)
ab = tf.stack([a,b], axis=0) # shape (2,2,3)

TensorFlow的tf.unstack( ) 函数的用法

将一个高阶数的张量在某个axis上分解为低阶数的张量

a = tf.constant([[1,2,3],[3,4,5]]) # shape (2,3)
b = tf.constant([[7,8,9],[10,11,12]]) # shape (2,3)
ab = tf.stack([a,b], axis=0) # shape (2,2,3)
a1 = tf.unstack(ab, axis=0)  # shape (2,3)

TensorFlow的tf.concat( ) 函数的用法

tf.concat相当于numpy中的np.concatenate函数,用于将两个张量在某一个维度(axis)合并起来

tf.concat拼接的是两个shape完全相同的张量,并且产生的张量的阶数不会发生变化.

a = tf.constant([[1,2,3],[3,4,5]]) # shape (2,3)
b = tf.constant([[7,8,9],[10,11,12]]) # shape (2,3)
ab1 = tf.concat([a,b], axis=0) # shape(4,3)
ab2 = tf.concat([a,b], axis=1) # shape(2,6)

猜你喜欢

转载自blog.csdn.net/u011095460/article/details/85036949
今日推荐