
TensorFlow
沙子2019
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
tensorflow 强制使用cpu
这里写自定义目录标题 tensorflow 强制使用cpu原创 2022-03-20 17:41:59 · 676 阅读 · 0 评论 -
损失函数计算
1、均方差MSE loss = 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 · 833 阅读 · 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,1 target = tf.random.uniform([10], maxval=6, dtype=tf.int3原创 2021-12-28 17:55:17 · 832 阅读 · 0 评论 -
TensorFlow-张量与排序
1、扩张 每一纬度必须整数倍扩张 a = [[1,2,3]] a = tf.constant(a) x = tf.broadcast_to(a,[2, 6,3]) print(x) 2、创建Tensor 生成十行六列的Tensor tf.random.normal([10,6]) 3、原创 2021-12-24 17:46:10 · 1006 阅读 · 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]) 2loss1 s=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 · 137 阅读 · 0 评论 -
tensorflow输出
tf.sigmoid(a))tf.sigmoid(a)) 输出0到1的数字 tf.nn.softmax(a) 输出0到1,各数总和为1 tf.tanh(a) 输出-1到1原创 2021-09-23 14:42:29 · 106 阅读 · 0 评论 -
TensorFlow-where、scatter_nd、meshgrid
1、创建一个Tensor a = 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、创建布尔Tensor mask = a>0 [[ True False True] [False True Tru原创 2021-07-12 14:11:58 · 152 阅读 · 0 评论 -
TensorFlow-张量限幅
clip_by_value 按最大值最小值裁剪 a = tf.random.shuffle(tf.range(10)) print(tf.clip_by_value(a,2,7)) 新的tensor最小值为2,最大值为7 relu clip_by_norm 缩小数值,方向不变 gradient clipping 指定多层参数的缩放量原创 2021-07-09 15:10:42 · 162 阅读 · 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 · 140 阅读 · 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 · 129 阅读 · 0 评论 -
TensorFlow-合并与分割
1、合并 需指定要合并的轴,其它轴纬度值需要相同 tf.concat a=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 · 207 阅读 · 0 评论