目录
4、ImportError: attempted relative import with no known parent package
python和torch版本匹配
原repo中python为3.11,由于电脑当时支持的CUDA是11.4,所以torch装的版本是1.12.1+cu113,忽略了torch1.12只能适配3.10以下的python,改为3.10后即可。
torch安装
Previous PyTorch Versions | PyTorch
验证torch和CUDA是否正常安装
import torch
print(f"PyTorch version: {torch.__version__}")
print(f"CUDA version: {torch.version.cuda}")
print(f"Is CUDA available: {torch.cuda.is_available()}")
diffusers安装
直接用原repo中给的指令无法安装,去huggingface官网找到下面这个就安装成功了
https://huggingface.co/docs/diffusers/installation
pip install transformers
pip install accelerate
conda install -c conda-forge diffusers
xformers安装
版本对应
如果直接安装xformers,会把原来版本的torch卸载掉装成与最新的xformers对应的版本。那么要找到对应torch版本的xformers,可以查看不同版本分支下的requirements.txt文件,一般会有对torch版本的要求
https://github.com/facebookresearch/xformers/tree/v0.0.16
源码安装(Install from source)
cd ..
git clone --branch v0.0.16 https://github.com/facebookresearch/xformers.git
cd xformers
git submodule update --init --recursive
pip install -r requirements.txt
pip install -e .
cd MotionBooth
参考:【文生图系列】 Stable Diffusion v2复现教程-CSDN博客
其他环境的安装(requirements.txt)
直接输入下面这个命令会把原本的torch卸载安装最新版本
pip install -r requirements.txt
需要在requirements.txt中加入几行限制
torch==1.12.1+cu113
torchvision==0.13.1+cu113
torchaudio==0.12.1+cu113
权重下载
采用克隆的方式从huggingface上下载
1、用sudo指令安装git-lfs
sudo apt update
sudo apt install git-lfs
2、运行git lfs install
出现问题:
Error: Failed to call git rev-parse --git-dir: exit status 128
Git LFS initialized.
解决方法:初始化git仓库(图片内容来源参考博文)
3、运行git clone
运行完之后文件夹和小文件均可克隆,但是大文件会不成功,需要下载到本地然后再上传到服务器,大文件损坏就可能出现下面这个error。
_pickle.UnpicklingError: invalid load key, 'v'.
参考:git lfs install遇到的问题_git: 'lfs' is not a git command. see 'git --help'.-CSDN博客
4、ImportError: attempted relative import with no known parent package
方法一:直接按照参考中的加入__init__.py文件,可以为空。
方法二:不直接运行脚本,而是用(原repo中的做法)
python -m scripts.inference
参考:Python项目文件引用问题:ImportError: attempted relative import with no known parent package-CSDN博客
原repo中的错误
运行相机控制的时候报错,需要修改的内容如下: