后台运行程序或shell
nohup bash train.sh > log 2>&1 &
服务器间文件传递
scp -r 当前服务器路径 目标用户@目标IP:目标服务器路径
查看文件夹大小
du -sh *
显示显卡状况
nvidia-smi
创建环境
conda create -n name python=3.x
删除环境
conda remove -n name --all
清华镜像安装pytorch
https://blog.csdn.net/qq_41375609/article/details/103574507
测试TensorFlow gpu
- 2.X
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
sess = tf.compat.v1.Session()
- 1.X
import tensorflow as tf
hello=tf.constant('hello,world')
sess=tf.Session()
print(sess.run(hello))
测试pytorch cuda
import torch
x = torch.Tensor([1.0])
xx = x.cuda()
print(xx)
用pip安装环境包时,结果安装到非当前环境
python3.8 -m pip install opencv-python
#3.8是为了区分环境,多个3.8环境就不加了
删除ps中多个进程
ps -ef|grep 关键词|grep -v grep|cut -c 9-15|xargs kill -9
筛选出含有关键字的 不含有grep的 截取pid 杀死pid
jupyter notebook
选择conda中的环境,需要安装
conda install nb_conda
https://blog.csdn.net/qq_36017609/article/details/104271429
Windows中python循环创建文件夹
https://www.cnblogs.com/monsteryang/p/6574550.html
import os
def mkdir(path):
# 引入模块
# 去除首位空格
path = path.strip()
# 去除尾部 \ 符号
path = path.rstrip("\\")
# 判断路径是否存在
# 存在 True
# 不存在 False
isExists = os.path.exists(path)
# 判断结果
if not isExists:
# 如果不存在则创建目录
# 创建目录操作函数
os.makedirs(path)
print(path + ' 创建成功')
return True
else:
# 如果目录存在则不创建,并提示目录已存在
print(path + ' 目录已存在')
return False
# 定义要创建的目录
mkpath = "G:\\"
for i in range(1 , 20):
mkdir(mkpath+str(i))
# 调用函数
批量命名文件夹
https://blog.csdn.net/ucs426/article/details/106522886/
import os, sys
myparth = r'D:\数据集'
files = os.listdir(myparth) # 列举该目录下所有的文件夹
i = 1
for file in files:
old_dir = os.path.join(myparth, file) # 原来的文件路径
# filename=os.path.split(old_dir)[0]
new_dir = os.path.join(myparth, 'single_'+str(i)) # 现在的文件路径
os.rename(old_dir, new_dir) # 重命名
i = i + 1
print(i)
复制子文件下所有文件到另一个文件夹
import os
import shutil
path = '旧'
new_path = '新'
for root ,dirs,files in os.walk(path):
for i in range(len(files)):
if (files[i][-3:] == 'jpg') or (files[i][-3:] == 'png')or (files[i][-3:] == 'PNG') or (files[i][-3:] == 'JPG') or (files[i][-3:] == 'mp4'):
file_path = root +'/'+files[i