学习笔记

此博客为自己的一些学习过程,记录下来为了自己以后看

pytorch 0.3版本
>>> import torch
>>> from torch.autograd import Variable
>>> a = Variable(torch.zeros(2,2),requires_grad=True)
>>> type(a)
<class 'torch.autograd.variable.Variable'>
>>> b = torch.zeros(2,2)
>>> type(b)
<class 'torch.FloatTensor'>
>>> 


pytorch1.0版本
>>> import torch
>>> import torch.autograd as autograd
>>> a= torch.zeros(2,2,requires_grad=True)
>>> type(a)
<class 'torch.Tensor'>
>>> b=autograd.Variable(torch.zeros(2,2))
>>> type(b)
<class 'torch.Tensor'>
>>>




0.3版本与1.0版本的Variable用法不同
torch.FloatTensor()等方法的用法也不同

conda 安装指定版本的指定包

参考: https://blog.csdn.net/shin627077/article/details/78684524

清华镜像https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/linux-64/

https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64/

使用conda安装指定的包,不安装相应的依赖

最后我使用的方法:
到“https://anaconda.org/”或者“https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/linux-64/”下载所需的包,放到./anaconda3/pkgs/下面,进入该目录,用:
conda install --use-local 
可以安装成功。

使用pytorch0.3调用别人pytorch0.4的模型,出现错误

pytorch版本问题:AttributeError: 'module' object has no attribute '_rebuild_tensor_v2'

在自己使用load的py文件中添加如下代码即可 参考https://www.cnblogs.com/ranjiewen/p/9484323.html

Monkey-patch because I trained with a newer version.
# This can be removed once PyTorch 0.4.x is out.
# See https://discuss.pytorch.org/t/question-about-rebuild-tensor-v2/14560
import torch._utils
try:
    torch._utils._rebuild_tensor_v2
except AttributeError:
    def _rebuild_tensor_v2(storage, storage_offset, size, stride, requires_grad, backward_hooks):
        tensor = torch._utils._rebuild_tensor(storage, storage_offset, size, stride)
        tensor.requires_grad = requires_grad
        tensor._backward_hooks = backward_hooks
        return tensor
    torch._utils._rebuild_tensor_v2 = _rebuild_tensor_v2

pytorch0.4 和之前的老版本出现的Variable错误,直接上代码

pytorch 0.4
>>> import torch
>>> a = torch.ones(2,3)
>>> a
tensor([[1., 1., 1.],
        [1., 1., 1.]])
>>> a.requires_grad
False
>>> a.dtype
torch.float32


pytorch旧版本
>>> import torch
>>> import torch.autograd as autograd
>>> a = torch.ones(2,3)
>>> a

 1  1  1
 1  1  1
[torch.FloatTensor of size 2x3]
>>> a.requires_grad
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'torch.FloatTensor' object has no attribute 'requires_grad'
>>> b = autograd.Variable(torch.ones(2,3))
>>> b
Variable containing:
 1  1  1
 1  1  1
[torch.FloatTensor of size 2x3]

>>> b.requires_grad
False

总之pytorch0.4版本中创建tensor和创建variable使用的是一样的操作,但是旧版本tensor和Variable创建的方式是不一样的,很多情况下要注意这个问题

jupyter notebook:使用argparse包存在的问题及解决

https://blog.csdn.net/u012869752/article/details/72513141

错误:
__main__.py: error: unrecognized arguments: -f /public/home/student6/.local/share/jupyter/runtime/kernel-e4f4da77-dbf8-467b-88d5-d7f31e44a5e5.json
An exception has occurred, use %tb to see the full traceback. SystemExit: 2 
解决办法
parser = argparse.ArgumentParser()
parser.add_argument("--verbosity", help="increase output verbosity")
args = parser.parse_args(args=[])
print(args)
原文:https://blog.csdn.net/u012869752/article/details/72513141 

 

 

python 操作 sqlite 数据库(建表, 增删改查)

https://blog.csdn.net/y_silence_/article/details/79798123

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值