目录
- jupyter的缩进与取消缩进
- jupyter压缩解压缩
- nvcc -V command cannot find
- Ubuntu安装命令
- Ubuntu压缩和解压缩
- Ubuntu查看当前目录下一级文件夹大小
- Ubuntu查看显卡信息
- ubuntu查看运行过的命令
- ubuntu查看程序的运行路径
- nvidia-smi看不到进程,但GPU显存占满
- 本地断网,服务器继续运行
- ubuntu清空syslog
- ubuntu压缩和解压
- yaml
- 删除文件、文件夹
- grid_sample
- unfold
- Python字典
- np.asarray和np.array
- numpy.meshgrid
- torch.meshgrid
- torch.flip,torch.rot90
- np.std和torch.std
- torch查看cuda
- torch.from_numpy() 和 torch.Tensor(), torch.tensor()
- torch的池化
- torch加载模型到cpu
- torchvision.transforms
- 将文件名列表存储为json格式
jupyter的缩进与取消缩进
缩进:选中内容,点tab 取消缩进 ctrl+[
jupyter压缩解压缩
nvcc -V command cannot find
参考
如果/usr/local/cuda/bin路径下有nvcc,就可能是cuda没有加入系统路径,如果没有nvcc,那重装吧
重装
参考
参考2
参考3
添加路径
vim ~/.bashrc
export LD_LIBRARY_PATH=/usr/local/cuda/lib
export PATH=$PATH:/usr/local/cuda/bin
source ~/.bashrc
Ubuntu安装命令
eg.
apt-get install zip
Ubuntu压缩和解压缩
Ubuntu查看当前目录下一级文件夹大小
du -h --max-depth=1
Ubuntu查看显卡信息
nvidia-smi
nvidia-smi -i 每秒刷新一次
watch -n 5 nvidia-smi 每五秒刷新一次
注意每一栏的含义
参考1
参考2
lspci | grep -i vga
可以通过返回的十六进制查询显卡
查询网址PCI ID Repository
lspci是有关总线的命令 lspci
ubuntu查看运行过的命令
history
ubuntu查看程序的运行路径
ls -al /proc/PID/cwd
nvidia-smi看不到进程,但GPU显存占满
fuser -v /dev/nvidia*
没有fuser
ps aux|grep root|grep python
然后kill -9 PID杀掉相关的进程
本地断网,服务器继续运行
nohup
nohup python train.py > output.txt &
nohup失效,断开ssh连接,服务器程序中断:ssh 退出时用exit
ubuntu清空syslog
首先要切换到root
sudo -i
cat /dev/null /var/log/syslog
如果要限制大小,就去修改配置文件
vim /etc/logrotate.d/rsyslog
ubuntu压缩和解压
参考
unzip -d /dir filename.zip 解压到指定目录下
yaml
参考
支持三种数据结构:对象、数组、字面量
yaml.load(f, Loader=yaml.FullLoader)
将python字典写入yaml文件,序列化
yaml.dump(data,f,encoding='utf-8',allow_unicode=True)
usually used as:
parser.add_argument('-opt', type=str, help='Path to option YMAL file.')
删除文件、文件夹
参考
删除文件 os.remove
删除空文件夹 os.rmdir
删除文件夹 shutil.rmtree
grid_sample
torch.nn.functional.grid_sample
torch.nn.functional.grid_sample(input, grid, mode='bilinear', padding_mode='zeros', align_corners=None)
unfold
Python字典
methods = dir(dict)
print(methods)
np.asarray和np.array
numpy.meshgrid
torch.meshgrid
x = torch.tensor([1, 2, 3])
y = torch.tensor([4, 5, 6])
grid_x, grid_y = torch.meshgrid(x, y, indexing='ij')
grid_x
grid_y
torch.equal(torch.cat(tuple(torch.dstack([grid_x, grid_y]))),
torch.cartesian_prod(x, y))
import matplotlib.pyplot as plt
xs = torch.linspace(-5, 5, steps=100)
ys = torch.linspace(-5, 5, steps=100)
x, y = torch.meshgrid(xs, ys, indexing='xy')
z = torch.sin(torch.sqrt(x * x + y * y))
ax = plt.axes(projection='3d')
ax.plot_surface(x.numpy(), y.numpy(), z.numpy())
plt.show()
yv, xv = torch.meshgrid([torch.arange(self.ny, device=device),torch.arange(self.nx, device=device)])
self.grid = torch.stack((xv, yv), 2).view((1, 1, self.ny, self.nx, 2)).float()
torch.flip,torch.rot90
torch.flip(input, dims) → Tensor
torch.flip会复制输入的张量,np.flip返回的是视图。
torch.rot90
参考
np.std和torch.std
参考
np.std用的公式采用1/n, torch.std默认参数unbiased=True,采用1/(n-1)
torch查看cuda
参考
torch.cuda.get_device_capability(device),
torch.cuda.get_device_name(device)
torch.from_numpy() 和 torch.Tensor(), torch.tensor()
torch.Tensor is an alias for the default tensor type (torch.FloatTensor)
torch的池化
torch加载模型到cpu
torch.load默认加载到gpu, 最好不要用torch.load(path).cpu() 这是先加载到gpu,再把模型放到gpu,直接torch.load(path,map_location=‘cpu’)
torchvision.transforms
transform=transforms.Compose([
transforms.RandomChoice([transforms.Resize(opt.loadSize, interpolation=1),
transforms.Resize(opt.loadSize, interpolation=2),
transforms.Resize(opt.loadSize, interpolation=3),
transforms.Resize((opt.loadSize, opt.loadSize), interpolation=1),
transforms.Resize((opt.loadSize, opt.loadSize), interpolation=2),
transforms.Resize((opt.loadSize, opt.loadSize), interpolation=3)]),
transforms.RandomChoice([transforms.RandomResizedCrop(opt.fineSize, interpolation=1),
transforms.RandomResizedCrop(opt.fineSize, interpolation=2),
transforms.RandomResizedCrop(opt.fineSize, interpolation=3)]),
transforms.RandomHorizontalFlip(),
transforms.ToTensor()])
随机选择一种resize方式,并随机进行一种中心随机的裁剪,依p(p=0.5默认)概率进行翻转,转换为tensor。
rrr
将文件名列表存储为json格式
以前都把文件名写入txt,但这样读取的时候还得再处理一遍,不如处理把列表存进json文件。存进去是列表,读出来也是
filename = 'useddata.json'
imgslist = []
flag = True
for curDir, dirs, files in os.walk("../traindata/mini-imagenet/images"):
for file in files:
imgslist.append(file)
if flag:
print(file)
flag = False
# imgslist.append(os.path.join(curDir, file))
# print(imgslist[0])
with open(filename,"w") as f:
json.dump(imgslist,f)
with open(filename) as f:
usedlist = json.load(f)
print(usedlist[1])