tf.nn.max_pool
- 用法
tf.nn.max_pool(
value,
ksize,
strides,
padding,
data_format='NHWC',
name=None
)
value: 4-D张量;
ksize: 过滤器尺寸,4个整数的列表或元祖,常用[1,2,2,1],[1,3,3,1];
- 示例
pool = tf.nn.max_pool(actived_conv, ksize=[1, 3, 3, 1],
strides=[1, 2, 2, 1], padding="SAME")
tf.contrib.slim
- conv2d
conv2d(
input,
out_channel,
size,
stride=1,
padding="SAME",
name=None
)
input: 输入张量;
out_channel: 过滤器深度;
size: 过滤器尺寸,[3,3];
- 示例
net = tf.contrib.slim.conv2d(input, 32, [3, 3])
max_pool2d
avg_pool2d
arg_scope
arg_scope(
list,
stride=None,
padding=None
)
list: 函数列表;
- 示例
slim = tf.contrib.slim
with slim.arg_scope([slim.conv2d, slim.max_pool2d, slim.avg_pool2d],
stride=1, padding='VALID'):
...
tf.concat
- 用法
tf.concat(
values,
axis,
name='concat'
)
values: 由一个或多个张量组成的列表;
axis: 要连接的维度;
- 示例
t1 = [[1, 2, 3], [4, 5, 6]]
t2 = [[7, 8, 9], [10, 11, 12]]
tf.concat([t1, t2], 0) # [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
tf.concat([t1, t2], 1) # [[1, 2, 3, 7, 8, 9], [4, 5, 6, 10, 11, 12]]
tf.train.BytesList
- 用法
BytesList(
value=[value]
)
value: 字符串类型的数据列表;
- 示例
import tensorflow as tf
import numpy as np
data1 = np.random.rand(2)
data2 = "this is a test data"
data1_bytes = data1.tostring()
data2_bytes = bytes(data2, encoding='utf-8')
data_byteslist = tf.train.BytesList(value=[data1_bytes, data2_bytes])
print(data_byteslist)
#value: "\347j\372\271\376t\354?\267,\270\302\355\220\345?"
#value: "this is a test data"
tf.train.Int64List
tf.train.FloatList
tf.train.Feature
- 用法
Feature(
bytes_list=tf.train.BytesList()
int64_list=tf.train.Int64List()
float_list=tf.train.FloatList()
)
bytes_list: 字符串属性;
int64_list: 整数属性;
float_list: 浮点数属性;
- 示例
tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))
tf.train.Feature(float_list=tf.train.FloatList(value=[value]))
tf.train.Features
- 用法
Features(
feature={}
)
feature: 传入一个字典,字典的key是字符串(feature名),值是tf.train.Feature对象;
- 示例
tf.train.Features(feature={
'data_int': tf.train.Feature(int64_list=tf.train.Int64List(value=[va]))
'data_bytes': ...
'data_float': ...
})
tf.train.Example
- 用法
Example(
features=tf.train.Features()
)
features: 属性对象集合;
- 示例
example = tf.train.Example(features=tf.train.Features(feature={
'data_int': tf.train.Feature(int64_list=tf.train.Int64List(value=[va]))
'data_bytes': ...
'data_float': ...
}))
- SerializeToString
#序列化
example_str = example.SerializeToString()
- FromString
#反序列化