Skip to content

Commit 572d8ac

Browse files
authored
[Doc] update quickrun doc (open-mmlab#1842)
* [Doc] update quickrun doc * [Doc] update quickrun doc
1 parent 8c10ffc commit 572d8ac

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

docs/en/get_started/quick_run.md

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,36 @@
11
# Quick run
22

3-
After installing MMagic successfully, now you are able to play with MMagic!
4-
5-
To synthesize an image of a church, you only need several lines of codes by MMagic!
3+
After installing MMagic successfully, now you are able to play with MMagic! To generate an image from text, you only need several lines of codes by MMagic!
64

75
```python
8-
from mmagic.apis import init_model, sample_unconditional_model
9-
10-
config_file = 'configs/styleganv2/stylegan2_c2_8xb4-800kiters_lsun-church-256x256.py'
11-
# you can download this checkpoint in advance and use a local file path.
12-
checkpoint_file = 'https://download.openmmlab.com/mmediting/stylegan2/official_weights/stylegan2-church-config-f-official_20210327_172657-1d42b7d1.pth'
13-
device = 'cuda:0'
14-
# init a generative model
15-
model = init_model(config_file, checkpoint_file, device=device)
16-
# sample images
17-
fake_imgs = sample_unconditional_model(model, 4)
6+
from mmagic.apis import MMagicInferencer
7+
sd_inferencer = MMagicInferencer(model_name='stable_diffusion')
8+
text_prompts = 'A panda is having dinner at KFC'
9+
result_out_dir = 'output/sd_res.png'
10+
sd_inferencer.infer(text=text_prompts, result_out_dir=result_out_dir)
1811
```
1912

2013
Or you can just run the following command.
2114

2215
```bash
23-
python demo/mmagic_inference_demo_demo.py \
24-
configs/styleganv2/stylegan2_c2_lsun-church_256_b4x8_800k.py \
25-
https://download.openmmlab.com/mmediting/stylegan2/official_weights/stylegan2-church-config-f-official_20210327_172657-1d42b7d1.pth
26-
16+
python demo/mmagic_inference_demo.py \
17+
--model-name stable_diffusion \
18+
--text "A panda is having dinner at KFC" \
19+
--result-out-dir ./output/sd_res.png
2720
```
2821

29-
You will see a new image `unconditional_samples.png` in folder `work_dirs/demos/`, which contained generated samples.
22+
You will see a new image `sd_res.png` in folder `output/`, which contained generated samples.
3023

3124
What's more, if you want to make these photos much more clear,
3225
you only need several lines of codes for image super-resolution by MMagic!
3326

3427
```python
35-
import mmcv
36-
from mmagic.apis import init_model, restoration_inference
37-
from mmagic.utils import tensor2img
38-
28+
from mmagic.apis import MMagicInferencer
3929
config = 'configs/esrgan/esrgan_x4c64b23g32_1xb16-400k_div2k.py'
4030
checkpoint = 'https://download.openmmlab.com/mmediting/restorers/esrgan/esrgan_x4c64b23g32_1x16_400k_div2k_20200508-f8ccaf3b.pth'
4131
img_path = 'tests/data/image/lq/baboon_x4.png'
42-
model = init_model(config, checkpoint)
43-
output = restoration_inference(model, img_path)
44-
output = tensor2img(output)
45-
mmcv.imwrite(output, 'output.png')
32+
editor = MMagicInferencer('esrgan', model_config=config, model_ckpt=checkpoint)
33+
output = editor.infer(img=img_path,result_out_dir='output.png')
4634
```
4735

4836
Now, you can check your fancy photos in `output.png`.

requirements/docs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ docutils==0.16.0
22
modelindex
33
myst_parser
44
-e git+https://github.com/open-mmlab/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
5+
requests<=2.29.0
56
sphinx==4.5.0
67
sphinx-autoapi
78
sphinx-copybutton

0 commit comments

Comments
 (0)