pytorch

Get probability of multi-token word in MASK position

橙三吉。 提交于 2020-12-05 11:57:31
问题 It is relatively easy to get a token's probability according to a language model, as the snippet below shows. You can get the output of a model, restrict yourself to the output of the masked token, and then find the probability of your requested token in the output vector. However, this only works with single-token words, e.g. words that are themselves in the tokenizer's vocabulary. When a word does not exist in the vocabulary, the tokenizer will chunk it up into pieces that it does know (see

Get probability of multi-token word in MASK position

梦想与她 提交于 2020-12-05 11:55:01
问题 It is relatively easy to get a token's probability according to a language model, as the snippet below shows. You can get the output of a model, restrict yourself to the output of the masked token, and then find the probability of your requested token in the output vector. However, this only works with single-token words, e.g. words that are themselves in the tokenizer's vocabulary. When a word does not exist in the vocabulary, the tokenizer will chunk it up into pieces that it does know (see

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

安稳与你 提交于 2020-12-05 11:19:27
问题 In a pytorch model training process I get this error: RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.LongTensor [128, 1]] is at version 8; expected version 7 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck! with stack trace sys:1: RuntimeWarning: Traceback of forward call that caused the error:

Pytorch: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead

大城市里の小女人 提交于 2020-12-04 15:08:09
问题 I have an error in my code which is not getting fixed any which way I try. The Error is simple, I return a value: torch.exp(-LL_total/T_total) and get the error later in the pipeline: RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead. Solutions such as cpu().detach().numpy() give the same error. How could I fix it? Thanks. 回答1: Error reproduced import torch tensor1 = torch.tensor([1.0,2.0],requires_grad=True) print(tensor1) print(type(tensor1))

Pytorch: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead

半腔热情 提交于 2020-12-04 15:07:51
问题 I have an error in my code which is not getting fixed any which way I try. The Error is simple, I return a value: torch.exp(-LL_total/T_total) and get the error later in the pipeline: RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead. Solutions such as cpu().detach().numpy() give the same error. How could I fix it? Thanks. 回答1: Error reproduced import torch tensor1 = torch.tensor([1.0,2.0],requires_grad=True) print(tensor1) print(type(tensor1))

给大家推荐:五个Python小项目,Github上的人气很高的

天大地大妈咪最大 提交于 2020-12-04 07:41:33
1.深度学习框架 Pytorch https://github.com/pytorch/pytorch PyTorch 是一个 Torch7 团队开源的 Python 优先的深度学习框架,提供两个高级功能: ● 强大的 GPU 加速 Tensor 计算(类似 numpy) ● 构建基于 tape 的自动升级系统上的深度神经网络 ● 你可以重用你喜欢的 python 包,如 numpy、scipy 和 Cython ,在需要时扩展 PyTorch。 2.deepfake 的深度学习技术 Facewap https://github.com/deepfakes/faceswap deepfake 的深度学习技术,这款工具本来的用途是用来识别和交换图片、视频中人物脸部图像的工具 。该项目有多个入口,你需要做的事: ● 收集照片 ● 从原始照片中提取面部图像 ● 在照片上训练模型 ● 使用模型转换源代码 3.神经网络库 keras https://github.com/keras-team/keras Keras 是一个极简的、高度模块化的神经网络库,采用 Python(Python 2.7-3.5.)开发,能够运行在 TensorFlow 和 Theano 任一平台,好项目旨在完成深度学习的快速开发。 特性: ● 可以快速简单的设计出原型(通过总模块化、极简性、和可扩展性) ●

白话Xavier | 神经网络初始化的工程选择

人走茶凉 提交于 2020-12-04 07:14:55
插播一个小新闻:最近建立了交流群~欢迎回复【加群】加入~ “Xavier”初始化方法是一种很有效的神经网络初始化方法,方法来源于2010年的一篇论文《Understanding the difficulty of training deep feedforward neural networks》。 论文的链接在这里:https://machinelearning.wustl.edu/mlpapers/paper_files/AISTATS2010_GlorotB10.pdf PyTorch代码 在介绍论文和理论之前,先讲一下如何使用在PyTorch中使用Xavier初始化: def _initialize_weights (self) : # print(self.modules()) for m in self.modules(): print(m) if isinstance(m, nn.Linear): # print(m.weight.data.type()) # input() # m.weight.data.fill_(1.0) init.xavier_uniform_(m.weight, gain= 1 ) print(m.weight) 通俗讲理论 论文提出的Xavier的主要思想: 每一层输出的方差应该尽量相等 。 前向传播 下面进行推导:

Runtime error 999 when trying to use cuda with pytorch

泪湿孤枕 提交于 2020-12-03 07:30:33
问题 I installed Cuda 10.1 and the latest Nvidia Driver for my Geforce 2080 ti. I try to run a basic script to test if pytorch is working and I get the following error: RuntimeError: cuda runtime error (999) : unknown error at ..\aten\src\THC\THCGeneral.cpp:50 Below is the code im trying to run: import torch torch.cuda.current_device() torch.cuda.is_available() torch.cuda.get_device_name(0) 回答1: Restarting my computer fixed this for me. But for a less invasive fix, you can also try this solution

GitHub 标星 2.5K+,U^2-Net 跨界肖像画,完美复刻人物细节!

孤街醉人 提交于 2020-12-02 16:40:53
来源 | Jack Cui 头图 | CSDN下载自视觉中国 今年提出的 U^2-Net 显著性检测算法,刷爆了 reddit 和 twitter,号称是 2020 年「地表最强」的静态背景分割算法,可以看下效果: 你以为今天要讲分割?错! U^2-Net 这两天又出新活,在 U^2-Net 网络架构基础上,实现了人物肖像画的生成,细节「完美」复刻。 我用自己的「歪脖子照」测试了下效果。 万年不变老规矩,继续手把手教学。 算法原理、环境搭建、效果实现,一条龙服务,尽在下文! U^2-Net 受 U-Net 网络的启发,U^2-Net 也是一种类似编码-解码(Encoder-Decoder)的网络结构。 研究者在此基础上,提出了新型残差 U-block(ReSidual U-block, RSU),融合不同尺寸接受野的特征,以捕获更多不同尺度的上下文信息。 RSU 网络与现有卷积块的结构对比如下: 最右边的结构,就是 RSU-L,L 表示编码器中的层数,C_in、C_out 分别表示输入和输出通道,M 表示 RSU 内层通道数。 具体而言,RSU 主要有三个组成部件,分别是一个输入卷积层、一个高度为 L 的类 U-Net 对称编码器 - 解码器结构以及一个通过求和来融合局部和多尺度特征的残差连接。 为了更好地理解设计理念,研究者在下图中对 RSU 与原始残差块进行了比较。 结果显示

视频超分:STVUN(Deep Space-Time Video Upsampling Networks)

旧巷老猫 提交于 2020-12-01 11:34:38
论文: 深度时空视频上采样网络 文章检索出处:2020 ECCV 代码: https://github.com/JaeYeonKang/STVUN-Pytorch 摘要 问题: 解决视频在空间和时间上的联合上采样问题的一种方法是逐个独立运行VSR和FI,效率低下。在VSR中,大多数方法都包括特征提取、对齐、融合和重构四个阶段。对于FI,该过程可分为特征提取、特征插值和重构。 贡献:1. 本文提出了一种用于时空视频上采样的端到端框架(STVUN),通过共享特征提取模块和重构模块,有效地将VSR和FI合并为一个联合框架。 2. 提出了基于时空权值的早期融合方法(EFST)来有效融合输入特征,而无需进行显示运动补偿。 3. 该框架能够在空间上上采样×4,在时间上上采样×∞。 4. 收集了STVT数据集,用于评估联合时空上采样任务。 方法 架构 网络由多个模块组成:编码器、空间上采样特征融合(EFST)、帧内插流量估计器和解码器。框架采用7个LR帧作为输入[0-7)。然后,它输出中心HR帧 Y ^ 3 \hat Y_3 Y ^ 3 ​ 以及N个HR中间帧 Y ^ T \hat Y_T Y ^ T ​ ,其中T∈[3,4]。 共享权重的编码器首先被用来提取每帧的特征。在空间上采样时使用EFST对编码特征进行融合,在时间上采样时使用计算出的流对编码特征进行插值。解码块由具有共享权重的解码器组成