0%

在环境迁移的时候, loadsave 经常会出现问题,
这个时候使用latin编码就行

1
2
with open(mshelffile, 'rb') as f:
d = pickle.load(f, encoding='latin1')

1
find . -name \*.pyc -delete

1
2
import sys
sys.executable

1
Installed kernelspec env3.6 in /home/yinghong/.local/share/jupyter/kernels/env3.6


title: conv1d使用
date: 2018-07-30 21:21:34

tags:

1
2
3
4
>>> filters = torch.randn(33, 16, 3)
>>> inputs = torch.randn(20, 16, 50)
# 16是通道数
>>> F.conv1d(inputs, filters)


title: pytorch 随机数设置初始值
date: 2018-07-30 13:00:27

tags:

1
2
3
4
5
use_cuda = torch.cuda.is_available() and not args.no_cuda
device = torch.device('cuda' if use_cuda else 'cpu')
torch.manual_seed(args.seed)
if use_cuda:
torch.cuda.manual_seed(args.seed)


title: pytorch 0.4迁移
date: 2018-07-29 15:11:09

tags:

type()

1
2
3
本来是 type()
现在是 isinstance(x, torch.DoubleTensor),
x.type()

Tensor(1, requires_grad=True)

1
2
3
4
5
w = torch.ones(1, requires_grad=True) 
或者是
w = w.requires_grad_()
total = w + z
total.backward()

.data 和 .detach()使用

推荐使用.detach()

0.3.0里面sum区别

tensor.sum()would return a Python number, butvariable.sum()would return a vector of size(1,).

弃用volatile, 使用torch.no_grad()

1
2
3
4
5
with torch.no_grad():
y = x * 2

with torch.set_grad_enable(is_train):
y = x * 2

![](https://ws1.sinaimg.cn/large/006tKfTcly1ftrmk9u4xdj31au14awlt.jpg)

1
2
3
4
5
6
7
8
9
10
11
>>> import parse
>>> format_string = 'PN-{:0>9}'
>>> id = 123
>>> pn = format_string.format(id)
>>> pn
'PN-000000123'
>>> parsed = parse.parse(format_string, pn)
>>> parsed
<Result ('123',) {}>
>>> parsed[0]
'123'

Go to iTerm Preferences → Profiles, select your profile, then the Keys tab. Click Load Preset… and choose Natural Text Editing.