以下均为个人学习所见,如有错误请见谅:
来源:https://tensorflow.google.cn/versions/r1.13/api_docs/python/tf
import tensorflow as tf
tf.placeholder(dtype,shape=None,name=None) 占位
tf.Variable(initial-value, name=optional-name) 变量
tf.global_variables_initializer() 全局变量初始化
tf.random_normal(shape,mean=0.0,stddev=1.0,dtype=tf.float32,seed=None,name=None) 随机初始化
tf.zeros(shape,dtype=tf.float32,name=None) 初始化为零
tf.matmul(x,W) 矩阵相乘
tf.argmax(input,axis=None,name=None,dimension=None,output_type=tf.int64) 返回列表最大值的索引
tf.equal(x,y,name=None) 判断相等,返回bool类列表
tf.cast(x, dtype,name=None) 改变类型
tf.reduce_mean(input_tensor,axis=None,keepdims=None,name=None,reduction_indices=None,keep_dims=None) 取平均值
tf.Session() 会话
tf.subtract(x,y,name=None) 减法
tf.multiply(x,y,name=None) 乘法
图像API
tf.read_file(filename,name=None)
tf.image.decode_jpeg(contents,channels=0,ratio=1,fancy_upscaling=True,try_recover_truncated=False,acceptable_fraction=1,dct_method=’’,name=None)
tf.image.resize_images(images,size,method=ResizeMethod.BILINEAR,align_corners=False)
tf.nn
激活函数
tf.nn.softmax(logits,axis=None,name=None,dim=None)
tf.nn.relu(features,name=None)
tf.nn.tanh()
dropout
tf.nn.dropout(x,keep_prob,noise_shape=None,seed=None,name=None)
其他
tf.nn.in_top_k(predictions,targets,k,name=None)
卷积与池化
tf.nn.conv2d(input,filter,strides,padding,use_cudnn_on_gpu=True,data_format=‘NHWC’,dilations=[1, 1, 1, 1],name=None)
2-D 卷积 需要4-D “input”:[batch, in_height, in_width, in_channels] and “filter” :[filter_height, filter_width, in_channels, out_channels],strides = [1, stride, stride, 1].
tf.nn.max_pool(value,ksize,strides,padding,data_format=‘NHWC’,name=None)
ksize=[1,X,X,1],strides = [1, stride, stride, 1].
tf.train
优化器
tf.train.GradientDescentOptimizer(learning_rate)
tf.train.AdamOptimizer(learning_rate)
模型保存
tf.train.Saver()
其他
tf.train.create_global_step() #创建训练步数
tf.train.exponential_decay( #指数衰减
self.initial_learning_rate, self.global_step, self.decay_steps,
self.decay_rate, self.staircase, name=‘learning_rate’)
tf.losses
代价函数
tf.losses.softmax_cross_entropy(
onehot_labels,
logits,
weights=1.0,
label_smoothing=0,
scope=None,
loss_collection=tf.GraphKeys.LOSSES,
reduction=Reduction.SUM_BY_NONZERO_WEIGHTS
)
tf.losses.sigmoid_cross_entropy(
multi_class_labels,
logits,
weights=1.0,
label_smoothing=0,
scope=None,
loss_collection=tf.GraphKeys.LOSSES,
reduction=Reduction.SUM_BY_NONZERO_WEIGHTS
)
tf.losses.sparse_softmax_cross_entropy(
labels,
logits,
weights=1.0,
scope=None,
loss_collection=tf.GraphKeys.LOSSES,
reduction=Reduction.SUM_BY_NONZERO_WEIGHTS
)