tensorflow常用API学习

以下均为个人学习所见,如有错误请见谅:
来源: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
)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值