0%

1
2
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
export PYENV_VIRTUALENV_DISABLE_PROMPT=1

查看本机安装 Python 版本

1
pyenv versions

查看可安装 Python 版本

1
pyenv install -l

python 安装与卸载

1
2
$ pyenv install 2.7.3   # 安装python
$ pyenv uninstall 2.7.3 # 卸载python

python切换

1
2
$ pyenv global 2.7.3  # 设置全局的 Python 版本,通过将版本号写入 ~/.pyenv/version 文件的方式。
$ pyenv local 2.7.3 # 设置 Python 本地版本,通过将版本号写入当前目录下的 .python-version 文件的方式。通过这种方式设置的 Python 版本优先级较 global 高。

创建虚拟环境

1
$ pyenv virtualenv 2.7.10 env-2.7.10

列出当前虚拟环境

1
2
3
pyenv virtualenvs
pyenv activate env-name # 激活虚拟环境
pyenv deactivate #退出虚拟环境,回到系统环境

删除虚拟环境

1
2
pyenv uninstall my-virtual-env
rm -rf ~/.pyenv/versions/env-name # 或者删除其真实目录

更换 pip 源

1
2
3
4
5
6
vim ~/.pip/pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

http://einverne.github.io/post/2017/04/pyenv.html

1
2
3
4
5
6
7
a = Variable(torch.Tensor([1, 2, 3]))
print(a.size(0))
``

```python
if output.data.is_cuda:
output.data = output.data.cpu()
1
2
3
4
5
keypoints = []
for sample_data in test_data_batches:
keypoints.append(output.numpy())
keypoints = np.concatenate(keypoints, axis=0)

1
2
3
4
5
In [4]: 6.9 // 2
Out[4]: 3.0

In [5]: 6.9 / 2
Out[5]: 3.45

/data/ 和 data/的区别

/data是从根目录来的
data/是任意包含data的路径

reshape

1
a.reshape(2,4)

resize

1
a.resize(2,4)

transpose

1
b = a.transpose(1,0,2)

concatenate

1
2
3
4
5
6
7
8
9
10
11
>>> from numpy import *
>>> x = array([[1,2],[3,4]])
>>> y = array([[5,6],[7,8]])
>>> concatenate((x,y)) # default is axis=0
array([[1, 2],
[3, 4],
[5, 6],
[7, 8]])
>>> concatenate((x,y),axis=1)
array([[1, 2, 5, 6],
[3, 4, 7, 8]])

hstack

1
2
3
4
5
6
>>> from numpy import *
>>> a =array([[1],[2]]) # 2x1 array
>>> b = array([[3,4],[5,6]]) # 2x2 array
>>> hstack((a,b,a)) # only the 2nd dimension of the arrays is allowed to be different
array([[1, 3, 4, 1],
[2, 5, 6, 2]])

vstack

1
2
3
4
5
6
7
8
>>> from numpy import *
>>> a =array([1,2])
>>> b = array([[3,4],[5,6]])
>>> vstack((a,b,a)) # only the first dimension of the arrays is allowed to be different
array([[1, 2],
[3, 4],
[5, 6],
[1, 2]])

dtype

1
x_train = np.array([], dtype=np.float32)

unsqueeze

1
test_x = Variable(torch.unsqueeze(test_data.test_data, dim=1), volatile=True).type(torch.FloatTensor)[:2000]/255.   # shape from (2000, 28, 28) to (2000, 1, 28, 28), value in range(0,1)

zeros

1
np.zeros([20, 18])

squeeze, expand_dims

1
y = np.expand_dims(x, axis=0)

a[np.newaxis, :]

np.tile(a, [2,2])

np.append()

1
2
3

>>> np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]])
array([1, 2, 3, 4, 5, 6, 7, 8, 9])

静态库

编译时候放入可执行文件

生成

1
2
1. gcc -c main.cpp -o main.o
2. a.o b.o c.o => all.a

命名

1
libxxx.a

操作

1
2
ar rcs libmyhello.a hello.o
gcc -o hello main.c -static -L. -lmyhello

动态库

运行时候载入内存

命名

1
libxxxx.so.major.minor

操作

1
2
gcc -shared -fPIC -o libmyhello.so hello.o
gcc -o hello main.c -L. -lmyhello

执行时候如何定位动态库位置

1
2
LD_LIBRARY_PATH 里面记录了位置
export LD_LIBRARY_PATH=’pwd

这个目录自动包含

1
2
/lib
/usr/lib

在新安装一个库之后如何让系统能够找到他

如果安装在/lib或者/usr/lib下,那么ld默认能够找到,无需其他操作。

如果安装在其他目录,需要将其添加到/etc/ld.so.cache文件中,步骤如下

  1. 编辑/etc/ld.so.conf文件,加入库文件所在目录的路径
  2. 运行ldconfig,该命令会重建/etc/ld.so.cache文件

动态库查找目录

1
2
3
4
5
它先后搜索
1.elf文件的 DT_RPATH段
2.环境变量LD_LIBRARY_PATH
3./etc/ld.so.cache文件列表
4./lib/,/usr/lib目录找到库文件后将其载入内存,但是我们生成的共享库在当前文件夹下,并没有加到上述的4个路径的任何一个中,因此,执行后会出现错误)

查看依赖

1
ldd /bin/lnlibc.so.6

http://www.cppblog.com/deane/articles/165216.html

Tensor的内容以及信息

z = torch.Tensor(3,4)
x = z:nDimension() – 2
y = z:size() – y的值为size2的一维数组。3和4
t = z:nElement() – 12

1
ssh-keygen -t rsa
1
2
3
4
A主机上操作
$ cat /root/.ssh/id_rsa.pub | ssh root@远程服务器ip 'cat - >> ~/.ssh/authorized_keys'
B主机上操作
$ chmod 600 ~/.ssh/authorized_keys
1
2
3
$ vim /etc/ssh/sshd_config
PubkeyAuthentication yes //将该项改为yes
sudo service sshd restart

预测的时候数据如果只有一个,输出应该都是差不多的,
因为batch norm会对它正则化。

net结构文件找不到

在main.py 中import

load失败

1
2
3
4
torch.save(the_model.state_dict(), PATH)

the_model = TheModelClass(*args, **kwargs)
the_model.load_state_dict(torch.load(PATH))

load UnicodeDecodeError

1
2
3
4
5
from functools import partial
import pickle
pickle.load = partial(pickle.load, encoding="utf8")
pickle.Unpickler = partial(pickle.Unpickler, encoding="utf8")
model = torch.load(model_file, map_location=lambda storage, loc: storage, pickle_module=pickle)

https://github.com/CSAILVision/places365/issues/25