22 4 1 编程 articles

Python读取配置文件

推荐使用configobj,无需配置文件有标题: 1 pip install configobj 使用方法如下: 1 2 3 4 5 from configobj import ConfigObj arg = ConfigObj('config.ini') val = arg['key']……

Continue reading

sklearn常用代码

训练集测试集拆分: 1 2 3 from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1000) 分类任务报告: 1 2 3 from sklearn.metrics import classification_report print(classification_report(y_true, y_pred, target_names=target_names))……

Continue reading

H5PY常用代码

写入数据: 1 2 3 4 import h5py f = h5py.File('data.h5', 'w') f.create_dataset('a', shape=(255, 1024, 768), dtype=np.uint8, chunks=(1, 1024, 768), data=a, compression='gzip', compression_opts=9) 读取数据 1 2 3 4 import h5py f = h5py.File('data.h5', 'r') a = f['a']……

Continue reading

在Ubuntu22.04安装Nvidia Driver

1、直接安装 1 2 sudo apt install --reinstall dkms linux-headers-$(uname -r) sudo apt install nvidia-utils-545 nvidia-driver-545 2、若安装后nvidia-smi提示异常,可尝试手动修复(需修改版本号) 1 2 ls -l /usr/src/nvidia* sudo dkms install -m nvidia -v 545.29.06……

Continue reading

在Ubuntu22.04安装CUDA10.2

1、编译/etc/apt/sources.list,加入以下行: deb [arch=amd64] http://archive.ubuntu.com/ubuntu focal main universe 2、安装GCC7: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 sudo apt-get update sudo apt-get install g++-7 gcc-7 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 7 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 7 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 11 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 12 sudo update-alternatives --config gcc sudo update-alternatives --config g++ EOF 3、安装CUDA10.2: 1 2 bash cuda_10.2.89_440.33.01_linux.run ln -sf /usr/bin/gcc-7……

Continue reading

conda配置SadTalker+wav2lip环境

安装: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 conda create -n sadtalker python=3.8 -y conda activate sadtalker conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 paddlepaddle-gpu==2.4.2 cudatoolkit=11.6 -c paddle -c pytorch -c conda-forge -y conda env config vars set LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/ubuntu/anaconda3/envs/sadtalker/include:/home/ubuntu/anaconda3/envs/sadtalker/lib conda update ffmpeg -y pip install dlib-bin pip install -r SadTalker/requirements.txt pip install gfpgan==1.3.8 gradio==3.24.1 socksio==1.0.0 pip install paddlehub==2.3.1 typeguard==2.13.3 #pip install jupyterlab jupyter-archives hub install first_order_motion==1.0.0 hub install fastspeech2_baker==1.0.0 hub install wav2lip EOF 删除: 1 2 3 4 5 conda deactivate conda env remove -n sadtalker conda env list EOF……

Continue reading

Hive常用代码

解析JSON: 1 SELECT CAST(GET_JSON_OBJECT(field, '$.json_path') AS string) 正则匹配 1 SELECT regexp_like('text', 'regex')……

Continue reading

Presto常用代码

解析JSON: 1 SELECT CAST(json_extract(field, '$.json_path') AS string) 正则匹配 1 SELECT regexp_like('text', 'regex') 定义查询变量 1 2 3 4 5 6 7 8 9 10 11 WITH VARIABLES AS ( SELECT '2022-11-01' AS mdt, '2022-11-31' AS edt ) SELECT a1column FROM app.table a INNER JOIN VARIABLES ON a1dt >= VARIABLES.mdt AND a.dt <= VARIABLES.edt……

Continue reading

opencv常用代码

读写包含中文文件名的图片 1 2 3 4 5 6 7 8 9 10 import cv2 import glob import numpy as np def read_image(path): return cv2.imdecode(np.fromfile(path, dtype=np.uint8), cv2.IMREAD_UNCHANGED) def save_image(path, img): cv2.imencode(".jpg", img)[1].tofile(path) 图片旋转 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import cv2 def rotateAndScale(img, scaleFactor=1.0, degreesCCW=30, borderValue=(255,255,255)): oldY, oldX = img.shape[:2] M = cv2.getRotationMatrix2D(center=(oldX / 2, oldY / 2), angle=degreesCCW, scale=scaleFactor) newX, newY = oldX * scaleFactor, oldY * scaleFactor r = np.deg2rad(degreesCCW) newX, newY = (abs(np.sin(r) * newY) + abs(np.cos(r) * newX), abs(np.sin(r) * newX) + abs(np.cos(r) * newY)) (tx, ty) = ((newX - oldX) / 2, (newY - oldY) / 2) M[0, 2] += tx M[1, 2] += ty return cv2.warpAffine(img, M, dsize=(int(newX), int(newY)), borderValue=borderValue)……

Continue reading

Pickle常用代码

写入数据: 1 2 3 4 5 import pickle, gzip def save_zipped_pickle(obj, fname, protocol=-1): with gzip.open(fname, 'wb') as f: pickle.dump(obj, f, protocol) 读取数据 1 2 3 4 5 6 import pickle, gzip def load_zipped_pickle(fname): with gzip.open(fname, 'rb') as f: loaded_object = pickle.load(f) return loaded_object……

Continue reading