tf.nn,tf.layers,tf.contrib的區(qū)別(V1.0)三個(gè)模塊里都可以實(shí)現(xiàn)卷積層的操作,一直不太明白他們之間的區(qū)別。tf.nn 提供神經(jīng)網(wǎng)絡(luò)相關(guān)操作的支持,包括各種卷積操作、激活函數(shù)、pooling、歸一化、losses、分類操作、 embedding、RNN(dynamic_rnn bidirectional_dynamic_rnn raw_rnn)、Evaluationtf.layers 這個(gè)庫提供一系列的高級(jí)神經(jīng)網(wǎng)絡(luò)層、都是卷積相關(guān)的。tf.contrib.layers 提供 構(gòu)建計(jì)算圖中網(wǎng)絡(luò)層、正則化、摘要操作。是構(gòu)建計(jì)算圖的高級(jí)操作,但是contrib 模塊包含不穩(wěn)定和實(shí)驗(yàn)性的代碼,有可能以后API會(huì)改變。內(nèi)容更豐富,支持的操作更多。tf.reduce_mean(input_tensor, axis=None, keep_dims=False, name=None, reduction_indices=None)Computes the mean of elements across dimensions of a tensor.
對(duì)張量的某個(gè)維度上的元素進(jìn)行平均計(jì)算
Reduces input_tensor along the dimensions given in axis. Unless keep_dims is true, the rank of the tensor is reduced by 1 for each entry in axis. If keep_dims is true, the reduced dimensions are retained with length 1.
按照給定的軸axis在某個(gè)維度上縮減張量。
If axis has no entries, all dimensions are reduced, and a tensor with a single element is returned.
如果axis沒有輸入,所有維度都進(jìn)行縮減,返回只有一個(gè)元素的張量。
For example:
# 'x' is [[1., 1.]# [2., 2.]]tf.reduce_mean(x) ==> 1.5tf.reduce_mean(x, 0) ==> [1.5, 1.5]tf.reduce_mean(x, 1) ==> [1., 2.]Args:
input_tensor: The tensor to reduce. Should have numeric type. 輸入張量,數(shù)值型axis: The dimensions to reduce. If None (the default), reduces all dimensions.需要縮減的維度,如果空,縮減所有維度keep_dims: If true, retains reduced dimensions with length 1.如果真,保留縮減的維度為1name: A name for the Operation (optional).reduction_indices: The old (dePRecated) name for axis.老的方式,確定維度。——————————————————————————————————————————————————————————————————————tf.argmax(input, axis=None, name=None, dimension=None)
tf.argmax(input, axis=None, name=None, dimension=None)
See the guide: Math > Sequence Comparison and Indexing
Returns the index with the largest value across axes of a tensor. 返回的是張量按軸找最大值的index
Args:
input: A Tensor. Must be one of the following types: float32, float64, int64, int32, uint8, uint16, int16, int8, complex64, complex128, qint8, quint8, qint32, half.axis: A Tensor. Must be one of the following types: int32, int64. int32, 0 <= axis < rank(input). Describes which axis of the input Tensor to reduce across. For vectors, use axis = 0. 0--找每一列 1--找每一行name: A name for the operation (optional).Returns:
A Tensor of type int64. 返回的是最大值的位置,運(yùn)行sess才能顯示值。
Defined in tensorflow/python/ops/math_ops.py.
————————————————————————————————————————————————————————————————————————tf.reshape(tensor, shape, name=None)
Reshapes a tensor.
Given tensor, this operation returns a tensor that has the same values as tensor with shape shape.
If one component of shape is the special value -1, the size of that dimension is computed so that the total size remains constant. In particular, a shape of [-1] flattens into 1-D. At most one component of shape can be -1.
If shape is 1-D or higher, then the operation returns a tensor with shape shape filled with the values of tensor. In this case, the number of elements implied by shape must be the same as the number of elements in tensor.
如果shape中有一個(gè)位置喂-1,是為了其余位置的大小保持不變,-1的位置自適應(yīng)size。
For example:
# tensor 't' is [1, 2, 3, 4, 5, 6, 7, 8, 9]# tensor 't' has shape [9]reshape(t, [3, 3]) ==> [[1, 2, 3], [4, 5, 6], [7, 8, 9]]# tensor 't' is [[[1, 1], [2, 2]],# [[3, 3], [4, 4]]]# tensor 't' has shape [2, 2, 2]reshape(t, [2, 4]) ==> [[1, 1, 2, 2], [3, 3, 4, 4]]# tensor 't' is [[[1, 1, 1],# [2, 2, 2]],# [[3, 3, 3],# [4, 4, 4]],# [[5, 5, 5],# [6, 6, 6]]]# tensor 't' has shape [3, 2, 3]# pass '[-1]' to flatten 't'reshape(t, [-1]) ==> [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]# -1 can also be used to infer the shape# -1 is inferred to be 9:reshape(t, [2, -1]) ==> [[1, 1, 1, 2, 2, 2, 3, 3, 3], [4, 4, 4, 5, 5, 5, 6, 6, 6]]# -1 is inferred to be 2:reshape(t, [-1, 9]) ==> [[1, 1, 1, 2, 2, 2, 3, 3, 3], [4, 4, 4, 5, 5, 5, 6, 6, 6]]# -1 is inferred to be 3:reshape(t, [ 2, -1, 3]) ==> [[[1, 1, 1], [2, 2, 2], [3, 3, 3]], [[4, 4, 4], [5, 5, 5], [6, 6, 6]]]# tensor 't' is [7]# shape `[]` reshapes to a scalarreshape(t, []) ==> 7Args:
tensor: A Tensor.shape: A Tensor of type int32. Defines the shape of the output tensor.name: A name for the operation (optional).Returns:
A Tensor. Has the same type as tensor
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注