open-mmlab / mmagic

OpenMMLab Multimodal Advanced, Generative, and Intelligent Creation Toolbox. Unlock the magic 🪄: Generative-AI (AIGC), easy-to-use APIs, awsome model zoo, diffusion models, for text-to-image generation, image/video restoration/enhancement, etc.
https://mmagic.readthedocs.io/en/latest/
Apache License 2.0
6.95k stars 1.06k forks source link

Quick run[Docs] #2143

Open FelixBellaby opened 5 months ago

FelixBellaby commented 5 months ago

Branch

main branch https://mmagic.readthedocs.io/en/latest/

📚 The doc issue

The examples on the 'Quick run' introduction have to be run from the base of the git tree after installation. It would be better to use portable examples that test the installation tree.

Suggest a potential alternative/fix

This example does not rely on the existence of an 'output/' directory:

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

This example uses the previously created image and finds the config by name from the installation tree rather than digging the config source file out of the git tree:

from mmagic.apis import MMagicInferencer
checkpoint = 'https://download.openmmlab.com/mmediting/restorers/esrgan/esrgan_x4c64b23g32_1x16_400k_div2k_20200508-f8ccaf3b.pth'
editor = MMagicInferencer(model_name='esrgan', config_name='esrgan_x4c64b23g32_1xb16-400k_div2k', model_ckpt=checkpoint)
output = editor.infer(img='KFC_panda.png', result_out_dir='KFC_panda_hires.png')