您的位置:首页 > 其它

TensorFlow CNN 相关类与方法

2017-09-05 20:05 429 查看

embedding

tf.nn.embedding_lookup(params,ids,...)


通过id找对应的tensor.

在 Text-CNN中, 输入的word对应着一个tensor, 这个参数是可学习的, 就会用到这个函数.

示例:

embedding_shape = [vocab_size, embedding_size]
embedding_weight = tf.Variable(
tf.random_uniform(embedding_shape, -1.0, 1.0),
name="W",
dtype=tf.float32)
embedded_chars = tf.nn.embedding_lookup(self.embedding_weight, input_data)


one-hot

tf.one-hot(indices, depth, on_value=None, off_value=None,axis=None, dtype=None, name=None)


tensorflow.python.ops.array_ops.one_hot()
.

Returns a one-hot tensor.

conv2d

tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None,data_format=None, name=None)


tensorflow.python.ops.gen_nn_ops.conv2d()
,

Computes a 2-D convolution given 4-D
input
and
filter
tensors. 参数见下:

input

a tensor of shape
[batch, in_height, in_width, in_channels]


filter

a tensor of shape
[filter_height, filter_width, in_channels, out_channels]


strides

A list of
ints
. 1-D tensor of length 4. The stride of the sliding window for each dimension of
input
. 一般情况下, strides=[1,1,1,1].

padding

A
string
from:
"SAME", "VALID"
.

SAME 对应的就是 zero-padding, 卷积后尺寸不变. VALID 对应的就是不填充, 卷积后尺寸为
input_size-filter_size+1
.

Why call it a 2-D convolution, because it flattens the filter to a 2-D matrix with shape
[filter_height * filter_width * in_channels, output_channels]
.

max_pool

tf.nn.max_pool(value, ksize, strides, padding, data_format="NHWC", name=None)


Performs the max pooling on the input. 参数见下:

value

A 4-D
Tensor
with shape
[batch, height, width, channels]
and type
tf.float32
.

ksize

A list of ints that has length >= 4. The size of the window for each dimension of the input tensor.

strides

A list of ints that has length >= 4. The stride of the sliding window for each dimension of the input tensor.

一般情况下, strides=[1,ksize[1],ksize[2],1].

fully-connected

使用
tf.matmul()
即可.

argmax

tf.argmax(input,axis=None,name=None,dimension=None,output_type=dtypes.int64)


tensorflow.python.ops.math_ops.argmax()
.

类似于 numpy.argmax(), it returns the index with the largest value across dimensions of a tensor.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cnn