pip install trash-cli
vi ~/.bashrc
alias rm='trash-put' #rm指令默认就是将文件移动到回收站 root/.local/share/Trash/files
alias rl='trash-list' #rl指令显示回收站的列表
source ~/.bashrc
python -m venv myvenv
conda deactivate
source venv/bin/activate
source venv/Scripts/activate
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
更换其他镜像:
pip install xxx -i https://pypi.org/simple
pip install -r requirements.txt
若安装失败可直接到下载链接下载, 如:
https://download.pytorch.org/whl/cu101/torch-1.7.1%2Bcu101-cp39-cp39-linux_x86_64.whl
从官网找到linux anaconda的下载地址
wget -i https://repo.anaconda.com/archive/Anaconda3-2021.11-Linux-x86_64.sh
bash Anaconda3-2021.11-Linux-x86_64.sh
# gunicorn.py
bind = "0.0.0.0:1872" # 服务器端口
workers = 1
timeout = 6000
# 访问日志和错误日志
accesslog = 'logs/gunicorn_acess.log'
errorlog = 'logs/gunicorn_error.log'
# 日志级别
loglevel = 'info'
$ gunicorn app:app -c gunicorn.py
# 或者
$ gunicorn app:app -b :1872 -w 10
通过 Celery 进行后台任务调度。
$ celery -A app.celery worker --concurrency=2
wsl2: https://docs.microsoft.com/zh-cn/windows/wsl/compare-versions
ps aux|grep python # 查看python程序
lsof -i:8060 # 查看端口占用情况
CUDA_VISIBLE_DEVICES=1,2 nohup python train_demo.py --model proto_trans_encoder --hidden_size 768 --trainN 5 --encoder bert --pretrain_ckpt pretrain/bert-base-uncased --Q 5 --batch_size 1 --K 5 --N 5 --lr 1e-1 --train_iter 10000 > result.log 2>&1 &
CUDA_VISIBLE_DEVICES
:选择运行的GPUnohup XXX > > result.log 2>&1 &
:后台运行python -m http.server 1872
import os
# 动态获取当前项目路径
PROJECT_ROOT = '/'.join(os.path.realpath(__file__).split('/')[:-1])
# 路径拼接
os.path.join(root, 'images')
x & y #交集
x | y #并集
x - y #差集
x ^ y #补集
PS: 当set中的元素为列表时,将列表转成对象(class\collections.namedtuple())即可使用。
将自定义的Dataset根据batch size大小、是否shuffle等封装成一个Batch Size大小的Tensor,用于后面的训练
def csv_writer(file_name, tsv_name):
with open(file_name, 'w', encoding='utf-8', newline='') as f:
tsv_w = csv.writer(f, delimiter='\t')
tsv_w.writerows(tsv_name)
def csv_reader(file_name):
with open(file_name, 'r', encoding='utf-8') as f:
tsv_r = csv.reader(f, delimiter='\t')
tsv_list = []
for row in tsv_r:
tsv_list.append(row)
return tsv_list
import collections
DataItem = collections.namedtuple("DataItem", ["event", "label"])
data = DataItem._make(['从来没有进行过应急评估', '应急管理不足'])
print(data['event']) # == data[0]
nvida-smi
:GPU占用率ps aux|grep XX
:显示XX所有程序# 原生
from torch import optim
pytorch_optim = optim.SGD
# 第三方库
import torch_optimizer as optim
pytorch_optim = optim.Lamb
for p in self.albert.parameters():
p.requires_grad = False