新手看过来!MMagic保姆级安装教程及常见错误解决方法!

MMagic是一个强大的图像处理工具,尤其擅长图像超分辨率技术。

本文将为你提供一份全面的MMagic环境配置指南,包括代码克隆、环境创建、依赖安装以及常见错误的解决方案,旨在帮助你快速上手MMagic。

如果您是初学者并且想要尝试使用MMagic,按照本文的步骤操作可以帮助您解决以下问题,并开始使用MMagic!

  • 从GitHub克隆MMagic的代码库。
  • 创建一个新的Python环境并激活它。
  • 安装MMagic运行所需的各种Python包和依赖。
  • 解决在安装过程中可能遇到的一些常见错误。
  • 通过一个简单的Python脚本示例,展示如何使用MMagic进行图像超分辨率处理。

如果你在使用MMagic的过程中遇到了各种技术和安装问题,可以直接评论区留言或者跟我沟通,我非常乐意为你提供帮助!

1. #克隆代码 https://github.com/open-mmlab/mmagic.git

git clone https://github.com/open-mmlab/mmagic.git

2.创建环境和激活环境

conda create -n torch2.0.1  python=3.10.12
conda activate torch2.0.1

3.安装所需要的包

3.1

pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu118

3.2 

pip install -U openmim

3.3

mim install 'mmcv==2.0.0'

3.4

mim install 'mmengine'

3.5

mim install 'mmagic'

3.6

pip install -r requirements.txt

requirements.txt文件含有以下包,不管有没有用,先一键安装:

albumentations

-e git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1#egg=clip

imageio-ffmpeg==0.4.4

mmdet >= 3.0.0

open_clip_torch

PyQt5

albumentations

-e git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1#egg=clip

controlnet_aux

# codecov

# flake8

# isort==5.10.1

# onnxruntime

# pytest

# pytest-runner

# yapf

coverage < 7.0.0

imageio-ffmpeg==0.4.4

interrogate

mmdet >= 3.0.0

pytest

transformers>=4.27.4

av

av==8.0.3; python_version < '3.7'

click  # required by mmagic/utils/io_utils.py

controlnet_aux

diffusers>=0.23.0

einops

face-alignment<=1.3.4

facexlib

lmdb

lpips

mediapipe

numpy

# MMCV depends opencv-python instead of headless, thus we install opencv-python

# Due to a bug from upstream, we skip this two version

# https://github.com/opencv/opencv-python/issues/602

# https://github.com/opencv/opencv/issues/21366

# It seems to be fixed in https://github.com/opencv/opencv/pull/21382

opencv-python!=4.5.5.62,!=4.5.5.64

pandas  # required by mmagic/models/editors/disco_diffusion/guider.py

Pillow

resize_right

tensorboard

transformers>=4.27.4

4.环境配置验证

**完成以上步骤后进入python交互窗口,检查环境是否安装成功?然后开始使用代码**

成功安装 MMagic 后,你可以很容易地上手使用 MMagic!仅需几行代码,你就可以使用 MMagic 完成文本生成图像!

from mmagic.apis import MMagicInferencer
sd_inferencer = MMagicInferencer(model_name='stable_diffusion')
text_prompts = 'A panda is having dinner at KFC'
result_out_dir = 'output/sd_res.png'
sd_inferencer.infer(text=text_prompts, result_out_dir=result_out_dir)

提示:在进入python交互窗口时,依次输入以上指令,会在前两个指令出现很多的报错,以下是解决报错方案:

4.1. 解决报错

以下是搭建环境输入>>> from mmagic.apis import MMagicInferencer和

>>> sd_inferencer = MMagicInferencer(model_name='stable_diffusion')出现的错误,请根据提示解决报错。

错误1:

>>>from mmagic.apis import MMagicInferencer

No module named 'diffusers.pipelines.controlnet_xs'

解决方法:

pip install diffusers==0.24.0

错误2:

>>> from mmagic.apis import MMagicInferencer

>>> sd_inferencer = MMagicInferencer(model_name='stable_diffusion')

ModuleNotFoundError: No module named 'albumentations'

解决方法:

python -m pip install albumentations

错误3:

>>> from mmagic.apis import MMagicInferencer

>>> sd_inferencer = MMagicInferencer(model_name='stable_diffusion')

KeyError: 'AsymmetricAutoencoderKL is already registered in model at mmagic.models.archs'

解决方法:退出交互窗口,重新进入:

>>> from mmagic.apis import MMagicInferencer

>>> sd_inferencer = MMagicInferencer(model_name='stable_diffusion')

错误4:

>>> from mmagic.apis import MMagicInferencer

>>> from mmagic.apis import MMagicInferencer

>>> sd_inferencer = MMagicInferencer(model_name='stable_diffusion')

OSError: [Errno 5] Input/output error: '/home/featurize/work/.local/lib/python3.10/site-packages/astor-0.8.1.dist-info/entry_points.txt'

解决方法:退出交互窗口,重新进入:

>>> from mmagic.apis import MMagicInferencer

>>> sd_inferencer = MMagicInferencer(model_name='stable_diffusion')

成功解决:

当出现以下标识时说明环境配置成功,可以运行代码:

5.输入交互指令

解决以上问题之后,依次输入:以下交互指令,

text_prompts = 'A panda is having dinner at KFC'
result_out_dir = 'output/sd_res.png'
sd_inferencer.infer(text=text_prompts, result_out_dir=result_out_dir)

交互窗口如下所示:


6.配置成功

完成以上步骤,就配置成功了。

  • 26
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值