Framework
pyxiea
双鸭山大学研究生,对深度学习、自然语言处理、推荐系统感兴趣
展开
-
修饰符@tf.custom_gradient用法
修饰器tf.custom_gradient原创 2022-07-03 12:21:57 · 755 阅读 · 1 评论 -
numpy.triu()和numpy.tril()
triu():返回上三角(Upper triangle)。用k 指定对角线,主对角线为k=0,右上的对角线用k>0,左下的对角线用k<0,返回包括该对角线的上三角。tril():返回下三角(Lower triangle)。用k 指定对角线,主对角线为k=0,右上的对角线用k>0,左下的对角线用k<0,返回包括该对角线的下三角。In [1]: import numpy ...原创 2020-03-13 19:58:29 · 1057 阅读 · 0 评论 -
Tensorflow代码中使用global_step
在一个项目的代码中看到作者不是用epoch数量而是用一个名为n_updates的变量来控制训练何时结束的。代码如下。def train(model: Model): n_updates = 10000000 val_interval = 1000 start = time.time() best = float("inf") for i in range...原创 2019-08-13 09:45:39 · 1695 阅读 · 0 评论 -
tensorflow变量共享——单机多GPU下的参数共享/复用
写作本文的源头,是我作为一个新手,在看单机多GPU的tensorflow代码时,看到了一段很费解的代码,完整代码戳这里。因为不懂VariableScope和NameScope的作用和区别,看着这段好多个with的代码觉得非常乱。所以这里记录下自己的分析过程(笔记来的,散了吧):......from tensorflow.contrib import layersfrom tensorflow...原创 2019-08-12 19:52:59 · 1610 阅读 · 0 评论 -
tensorflow变量共享——VariableScope的reuse模式、tf.get_variable()、tf.Variable() 探索
Reusing模式会被子vs继承tf.get_variable_scope().reuse_variables()print('"'+tf.get_variable_scope().name+'"', tf.get_variable_scope().reuse)with tf.variable_scope('ss'): # ss是默认vs的子vs,故虽然没有使用reuse=True,wit...原创 2019-08-09 13:32:36 · 6434 阅读 · 5 评论 -
tf.concat实例用法与图解
tf.concat的参数为:tf.concat(values, axis, name='concat')其中的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...原创 2019-08-13 20:48:13 · 9489 阅读 · 0 评论 -
tf.scatter_nd特殊用法——按索引aggregate
一般用法见:https://blog.csdn.net/zlrai5895/article/details/80551056简单地说,scatter_nd根据indices来将updates中的元素“散布”到形状为shape并初始化为0的tensor中(称其为output),所以一般来说,shape的某个维度大小会比updates的对应维度的大小更大(小的tensor散布到大的tensor中),...原创 2019-08-08 17:00:36 · 824 阅读 · 0 评论 -
pytorch使用GPU
初始化device if torch.cuda.is_available(): if not opt.gpuid:#opt为命令行传入的参数对象 opt.gpuid = 0 opt.device = torch.device("cuda:%d" % opt.gpuid) else: opt.device =...原创 2019-07-16 09:57:40 · 11197 阅读 · 0 评论 -
pytorch如何实现可复现性
转自: https://blog.csdn.net/u010589524/article/details/89371919def seed_torch(seed=2018): random.seed(seed) os.environ['PYTHONHASHSEED'] = str(seed) np.random.seed(seed) torch.manual_s...原创 2019-07-16 09:09:14 · 2117 阅读 · 5 评论