![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
TensorFlow
沙子2019
这个作者很懒,什么都没留下…
展开
-
tensorflow 强制使用cpu
这里写自定义目录标题tensorflow 强制使用cpu原创 2022-03-20 17:41:59 · 586 阅读 · 0 评论 -
损失函数计算
1、均方差MSEloss = 1/n∑(y-out)²二番数代码:y = tf.constant([1, 2, 3, 0, 2])y = tf.one_hot(y, depth=4)y = tf.cast(y, dtype=tf.float32)out = tf.random.normal([5,4])#范数loss1 = tf.reduce_mean(tf.square(y-out))loss2 = tf.reduce_mean(tf.losses.MSE(y, out))原创 2022-01-07 11:30:33 · 751 阅读 · 0 评论 -
tensorflow基础操作
#添加参数,输出正态分布随机值相同tf.random.set_seed(2467)#输出的tensor符合正态分布output = tf.random.normal([10,6])可以把多个值伸缩到(0,1)output = tf.math.softmax(output,axis=1)print(output)#生成的值在该范围内遵循均匀分布 包含下限,不包含上限,默认0,1target = tf.random.uniform([10], maxval=6, dtype=tf.int3原创 2021-12-28 17:55:17 · 774 阅读 · 0 评论 -
TensorFlow-张量与排序
1、扩张每一纬度必须整数倍扩张a = [[1,2,3]]a = tf.constant(a)x = tf.broadcast_to(a,[2, 6,3])print(x)2、创建Tensor生成十行六列的Tensortf.random.normal([10,6])3、原创 2021-12-24 17:46:10 · 915 阅读 · 1 评论 -
tensorflow误差计算
创建数据级y = tf.constant([1,2,3,0,2])y = tf.one_hot(y, depth=4)y = tf.cast(y, dtype=tf.float32)out = tf.random.normal([5, 4])2loss1s=tf.square((y-out)) #相减再求平方print(tf.reduce_mean(s)) 求和后求平均数3loss2#norm 平方和开根号tf.square(tf.norm(y-out))/(5*4) 平方和开根号再平原创 2021-09-23 16:29:34 · 81 阅读 · 0 评论 -
tensorflow输出
tf.sigmoid(a))tf.sigmoid(a)) 输出0到1的数字tf.nn.softmax(a) 输出0到1,各数总和为1tf.tanh(a) 输出-1到1原创 2021-09-23 14:42:29 · 65 阅读 · 0 评论 -
TensorFlow-where、scatter_nd、meshgrid
1、创建一个Tensora = tf.random.normal([3,3])[[ 0.27786183 -0.4933894 0.40996674] [-0.58238053 0.12458259 1.265015 ] [-0.51049304 -1.1052276 1.0958437 ]], shape=(3, 3), dtype=float32)2、创建布尔Tensormask = a>0[[ True False True] [False True Tru原创 2021-07-12 14:11:58 · 106 阅读 · 0 评论 -
TensorFlow-张量限幅
clip_by_value按最大值最小值裁剪a = tf.random.shuffle(tf.range(10))print(tf.clip_by_value(a,2,7))新的tensor最小值为2,最大值为7reluclip_by_norm缩小数值,方向不变gradient clipping指定多层参数的缩放量原创 2021-07-09 15:10:42 · 97 阅读 · 0 评论 -
TensorFlow-填充与复制
1、填充 tf.pad填充顺序为左右上下,最右边为最内层a = tf.reshape(tf.range(9), [3,3])print(tf.pad(a,[[3,1],[4,0]]))2、原创 2021-07-08 16:30:25 · 88 阅读 · 0 评论 -
TensorFlow-数据统计
a = tf.ones([2, 3])1、平方和开根号tf.norm(a), tf.norm(a, ord=2)2、平方和tf.norm(a, ord=1)3、求全局最小值,最大值,平均值a = tf.random.normal([4,10])print(tf.reduce_min(a), tf.reduce_max(a), tf.reduce_mean(a))4、求1轴上最小值, 最大值, 平均值print(tf.reduce_min(a, axis=1), tf.reduce_m原创 2021-07-01 18:02:00 · 82 阅读 · 0 评论 -
TensorFlow-合并与分割
1、合并需指定要合并的轴,其它轴纬度值需要相同tf.concata=tf.ones([4,35,8])b=tf.ones([1,35,8])c = tf.concat([a,b],axis=0)print(c.shape)2、拼接按轴拼接,创建一个新的a=tf.ones([4,35,8])b=tf.ones([4,35,8])c=tf.stack([a,b],axis=-1)c=tf.stack([a,b], axis=1)print(c.shape)3、分离按轴平分a=原创 2021-07-01 17:28:24 · 144 阅读 · 0 评论