Giter Site home page Giter Site logo

adriaciurana / draggan Goto Github PK

View Code? Open in Web Editor NEW
89.0 7.0 15.0 11.35 MB

Unofficial implementation of the DragGAN paper

License: MIT License

Python 94.99% Jupyter Notebook 3.81% Dockerfile 0.69% Shell 0.51%
artificial-intelligence artificial-neural-networks computer-vision deep-learning gan generative-adversarial-network generativeai machine-learning

draggan's Introduction

Unofficial implementation of the paper "Drag Your GAN: Interactive Point based Manipulation on the Generative Image Manifold"

✨ Try on Colab!

[Official repository] Drag Your GAN: Interactive Point-based Manipulation on the Generative Image Manifold

Xingang Pan, Ayush Tewari, Thomas Leimkühler, Lingjie Liu, Abhimitra Meka, Christian Theobalt
SIGGRAPH 2023 Conference Proceedings

Cover

Synthesizing visual content that meets users' needs often requires flexible and precise controllability of the pose, shape, expression, and layout of the generated objects. Existing approaches gain controllability of generative adversarial networks (GANs) via manually annotated training data or a prior 3D model, which often lack flexibility, precision, and generality. In this work, we study a powerful yet much less explored way of controlling GANs, that is, to "drag" any points of the image to precisely reach target points in a user-interactive manner, as shown in Fig.1. To achieve this, we propose DragGAN, which consists of two main components: 1) a feature-based motion supervision that drives the handle point to move towards the target position, and 2) a new point tracking approach that leverages the discriminative generator features to keep localizing the position of the handle points. Through DragGAN, anyone can deform an image with precise control over where pixels go, thus manipulating the pose, shape, expression, and layout of diverse categories such as animals, cars, humans, landscapes, etc. As these manipulations are performed on the learned generative image manifold of a GAN, they tend to produce realistic outputs even for challenging scenarios such as hallucinating occluded content and deforming shapes that consistently follow the object's rigidity. Both qualitative and quantitative comparisons demonstrate the advantage of DragGAN over prior approaches in the tasks of image manipulation and point tracking. We also showcase the manipulation of real images through GAN inversion.

TODO

  • Create docker for CPU and GPU.
  • Generalize for other models.
  • Improve code quality.
  • Create docstring.
  • Improve gradio app.

Install

This implementation of DragGAN works with the official version of styleganv2-ada in pytorch. To properly clone the repository please use the --recurse-submodules flag:

git clone --recurse-submodules https://github.com/adriaciurana/DragGAN.git

You can install the requirements using the following command:

pip install -r requirements.txt

I suggest to install pytorch separately with the CUDA version that you need.

Implementation

In the file drag_gan.py you will find the entire implementation of the paper. The implementation is efficient (only uses pytorch).

Use pytorch hooks that allow flexibility for future generative networks. From the constructor you must define which layers you want to use for the DragGAN (it would also be possible to change to another architecture if you inherits from BaseGenerator).

GUI

Cover

Additionally, a GUI has been created to be able to apply the paper on your own images.

python gradio_app.py

For now, I'm having trouble with gradio to improve the GUI for drawing masks ( gradio-app/gradio#2224 and https://github.com/gradio-app/gradio/topics/2054).

Citation

@inproceedings{pan2023draggan,
    title={Drag Your GAN: Interactive Point-based Manipulation on the Generative Image Manifold}, 
    author={Pan, Xingang and Tewari, Ayush, and Leimk{\"u}hler, Thomas and Liu, Lingjie and Meka, Abhimitra and Theobalt, Christian},
    booktitle = {ACM SIGGRAPH 2023 Conference Proceedings},
    year={2023}
}

Contributions

I'm glad you want to contribute and improve the code :) I'm not an expert in Gradio, so any suggestion is welcome.

draggan's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

draggan's Issues

TypeError: 'type' object is not subscriptable

Getting this error when trying to run 'python gradio_app.py'

Traceback (most recent call last):
File "gradio_app.py", line 11, in
from drag_gan.drag_gan import DragGAN
File "D:\Projects\Python\DragGAN\drag_gan\drag_gan.py", line 77, in
class DragGAN:
File "D:\Projects\Python\DragGAN\drag_gan\drag_gan.py", line 93, in DragGAN
def params(self) -> dict[str, Any]:
TypeError: 'type' object is not subscriptable

any idea how you can fix it?

upload image error

File "/data/conda/install/envs/ml/lib/python3.10/site-packages/gradio/routes.py", line 414, in run_predict
output = await app.get_blocks().process_api(
File "/data/conda/install/envs/ml/lib/python3.10/site-packages/gradio/blocks.py", line 1320, in process_api
result = await self.call_function(
File "/data/conda/install/envs/ml/lib/python3.10/site-packages/gradio/blocks.py", line 1048, in call_function
prediction = await anyio.to_thread.run_sync(
File "/data/conda/install/envs/ml/lib/python3.10/site-packages/anyio/to_thread.py", line 31, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "/data/conda/install/envs/ml/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
return await future
File "/data/conda/install/envs/ml/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 867, in run
result = context.run(func, *args)
File "/data/github/dd2/DragGAN/gradio_app.py", line 359, in on_change_model_pickle
return init_wrapper_drag_gan(model_pickle_file.name, global_state, seed)
File "/data/github/dd2/DragGAN/gradio_app.py", line 23, in init_wrapper_drag_gan
drag_gan, w_latent, image_raw = init_drag_gan(ref, device, int(seed))
File "/data/github/dd2/DragGAN/gradio_app.py", line 15, in init_drag_gan
drag_gan = DragGAN(network_pkl, device=device)
File "/data/github/dd2/DragGAN/drag_gan.py", line 107, in init
self._G = legacy.load_network_pkl(f)["G_ema"].to(device) # type: ignore
File "/data/github/dd2/DragGAN/stylegan2-ada-pytorch/legacy.py", line 21, in load_network_pkl
data = _LegacyUnpickler(f).load()
_pickle.UnpicklingError: invalid load key, '\xff'.

Not easy to STOP

Thank you for your work.
The UI is not easy to stop the background computing, even I click the "STOP" many times.

'DragGAN' object has no attribute '_G'

I have installed missing requirements manually but I am getting :

Exception has occurred: AttributeError
'DragGAN' object has no attribute '_G'
File "C:\Users\User\Downloads\DragGAN-main\DragGAN-main\drag_gan.py", line 114, in init
self._input_size = self._G.synthesis.img_resolution
File "C:\Users\User\Downloads\DragGAN-main\DragGAN-main\gradio_app.py", line 15, in init_drag_gan
drag_gan = DragGAN(network_pkl, device=device)
File "C:\Users\User\Downloads\DragGAN-main\DragGAN-main\gradio_app.py", line 181, in main
drag_gan, w_latent, image_orig = init_drag_gan(network_pkl, device, default_seed)
File "C:\Users\User\Downloads\DragGAN-main\DragGAN-main\gradio_app.py", line 824, in
app = main()
AttributeError: 'DragGAN' object has no attribute '_G'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.