The AFM Image-Editing tool allows for AI-supported modification of images using a variety of technologies.
Our repository includes implementation of the methods, examplary results and evaluation.
Additionally, we created jupyter notebooks to better understand the possibilities of our Image-Editing tool and an app for running the methods on a webserver using the Python Gradio library.
The tool supports the following functions:
git clone --recursive https://github.com/matt576/image-editing.git
cd image-editing
git submodule update --init --recursive
conda create -n image-editing-env python=3.8.10 \
-c nvidia/label/cuda12.1.0 \
-c conda-forge
conda activate image-editing-env
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
pip install diffusers["torch"] transformers
pip install -e "./diffusers[torch]"
pip install omegaconf==2.1.1
pip install pytorch-lightning==1.6.1
pip install einops==0.3.0
pip install -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers
pip install opencv-python
pip install -qr https://huggingface.co/briaai/RMBG-1.4/resolve/main/requirements.txt
pip install controlnet_aux
You should set the environment variable manually as described below, if you want to build a local GPU environment for Grounded-SAM:
First, to check which CUDA versions are available and the required path:
module avail
Then:
source /etc/profile.d/lmod.sh
module load cuda/12.1.0 # Should match CUDA version from pytorch
echo $CUDA_HOME #check if variable was automatically set to /storage/software/cuda/cuda-12.1.0, otherwise set manually with EXPORT...
export AM_I_DOCKER=False
export BUILD_WITH_CUDA=True
export CUDA_HOME=/storage/software/cuda/cuda-12.1.0
Otherwise, the program will run on CPU-only mode. The following error will occur if you don't follow the previous steps: "NameError: name '_C' is not defined".
If that happens, simply delete groundingDino from your environemnt and start over from setting the environemnt variable manually.
Install Segment Anything:
python -m pip install -e Grounded-Segment-Anything/segment_anything
Install Grounding DINO:
pip install --no-build-isolation -e Grounded-Segment-Anything/GroundingDINO # Follow previous CUDA_HOME steps carefully
In case you encounter path issues when running GroundedSAM-related functions, copy the GroundingDINO folder (found inside GroundedSAM submodule) into the code folder as an immediate temporary solution.
pip install easydict
pip install scikit-learn
pip install kornia
pip install hydra-core==1.1.0
pip install albumentations==0.5.2
pip install webdataset
pip install gradio
# Recommended version: 4.32.1
pip install ipykernel
Latent diffusion:
cd code
wget -O models/ldm_inpainting/last.ckpt https://heibox.uni-heidelberg.de/f/4d9ac7ea40c64582b7c9/?dl=1
LaMa:
curl -LJO https://huggingface.co/smartywu/big-lama/resolve/main/big-lama.zip
unzip big-lama.zip -d ~/image-editing/code/models/
rm big-lama.zip
GroundedSAM (SAM + GroundingDINO):
wget -O models/sam_vit_h_4b8939.pth https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth
wget -O models/groundingdino_swint_ogc.pth https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth
Latent Diffusion:
In the file: image-editing\src\taming-transformers\taming\data\utils.py change line 11:
from torch._six import string_classes
to
string_classes = str
In order to visualise the examples, we prepared a jupyter notebooks for each of the functions, located in the folder:
image-editing/code/notebooks/
These serve as tutorials to help getting familiar with the variety of possibilities provided by the Image-Editing tool and generate outputs for examplary images.
List of the available notebooks:
/1-Mask-Generation.ipynb
/2-Background-Blurring.ipynb
/3-Background-Replacement.ipynb
/4-Object-Removal.ipynb
/5-Inpainting.ipynb
/6-Outpainting.ipynb
/7-Restyling.ipynb
/8-Superresolution.ipynb
/9-Txt2Img.ipynb
Preview: https://huggingface.co/spaces/AFM-Image-Editing/image-editing
In this section, we introduce the guide and steps of how to use the gradio app.
In order to use all the capabilities of our tool in an user-friendly way, we developed an app in a form of webserver GUI using the Gradio library.
This allows any user to upload their own images or artificially generate them via txt2img prompting, apply the aforementioned functionalities with different input parameters, visualize and download the results.
Our program supports usage of more than just one model for a each function. The used model can be selected on the dropdown menus within each tab before generating the output image.

code/afm_gradio.py
and navigate to the main function to specify the input image- and mask paths you'd like to be opened when lauching the app.
For that, simply edit the variables 'original_image_path' and 'input_mask_path' with your desired inputs.
This is an optional step, since you can also upload an input image (e.g. via drag-and-drop) directly in the UI.
cd code
python afm_gradio.py
After that, a public- and a local links for the accessing the UI will be generated. If you're using GPUs via remote access (SSH/Tunnel), we recommend using the public link.
(Optional): For inpainting / object removal, you have the option of directly inputting the image coordinates (clicking on image or writing coordinates) into the task (pipeline tabs), or if you prefer, first generate a mask preview and load the output mask as input for the optional mask input tasks on the left hand side.
To allow users more flexibility, we included several models for each functionality.
This section describes the implemented pipelines and exact model checkpoints used in the tool.
Additionally this helps us evaluate the results and compare them to the state-of-the-art methods.
Latent Diffusion pipeline: ldm_inpainting/last
LaMa pipeline: big-lama/best
image-editing/code/outputs/eval
and contain generated images for the introduced models. The qualitative evaluation is based on objective and subjective comaparison of the models to state-of-the-art tools or end products distributed by companies like Google, and also between the published models themselves.
34 commits
Python
70.1%
Jupyter Notebook
28.2%
Rich Text Format
1.8%
The AFM Image-Editing tool allows for AI-supported modification of images using a variety of technologies.
Our repository includes implementation of the methods, examplary results and evaluation.
Additionally, we created jupyter notebooks to better understand the possibilities of our Image-Editing tool and an app for running the methods on a webserver using the Python Gradio library.
The tool supports the following functions:
git clone --recursive https://github.com/matt576/image-editing.git
cd image-editing
git submodule update --init --recursive
conda create -n image-editing-env python=3.8.10 \
-c nvidia/label/cuda12.1.0 \
-c conda-forge
conda activate image-editing-env
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
pip install diffusers["torch"] transformers
pip install -e "./diffusers[torch]"
pip install omegaconf==2.1.1
pip install pytorch-lightning==1.6.1
pip install einops==0.3.0
pip install -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers
pip install opencv-python
pip install -qr https://huggingface.co/briaai/RMBG-1.4/resolve/main/requirements.txt
pip install controlnet_aux
You should set the environment variable manually as described below, if you want to build a local GPU environment for Grounded-SAM:
First, to check which CUDA versions are available and the required path:
module avail
Then:
source /etc/profile.d/lmod.sh
module load cuda/12.1.0 # Should match CUDA version from pytorch
echo $CUDA_HOME #check if variable was automatically set to /storage/software/cuda/cuda-12.1.0, otherwise set manually with EXPORT...
export AM_I_DOCKER=False
export BUILD_WITH_CUDA=True
export CUDA_HOME=/storage/software/cuda/cuda-12.1.0
Otherwise, the program will run on CPU-only mode. The following error will occur if you don't follow the previous steps: "NameError: name '_C' is not defined".
If that happens, simply delete groundingDino from your environemnt and start over from setting the environemnt variable manually.
Install Segment Anything:
python -m pip install -e Grounded-Segment-Anything/segment_anything
Install Grounding DINO:
pip install --no-build-isolation -e Grounded-Segment-Anything/GroundingDINO # Follow previous CUDA_HOME steps carefully
In case you encounter path issues when running GroundedSAM-related functions, copy the GroundingDINO folder (found inside GroundedSAM submodule) into the code folder as an immediate temporary solution.
pip install easydict
pip install scikit-learn
pip install kornia
pip install hydra-core==1.1.0
pip install albumentations==0.5.2
pip install webdataset
pip install gradio
# Recommended version: 4.32.1
pip install ipykernel
Latent diffusion:
cd code
wget -O models/ldm_inpainting/last.ckpt https://heibox.uni-heidelberg.de/f/4d9ac7ea40c64582b7c9/?dl=1
LaMa:
curl -LJO https://huggingface.co/smartywu/big-lama/resolve/main/big-lama.zip
unzip big-lama.zip -d ~/image-editing/code/models/
rm big-lama.zip
GroundedSAM (SAM + GroundingDINO):
wget -O models/sam_vit_h_4b8939.pth https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth
wget -O models/groundingdino_swint_ogc.pth https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth
Latent Diffusion:
In the file: image-editing\src\taming-transformers\taming\data\utils.py change line 11:
from torch._six import string_classes
to
string_classes = str
In order to visualise the examples, we prepared a jupyter notebooks for each of the functions, located in the folder:
image-editing/code/notebooks/
These serve as tutorials to help getting familiar with the variety of possibilities provided by the Image-Editing tool and generate outputs for examplary images.
List of the available notebooks:
/1-Mask-Generation.ipynb
/2-Background-Blurring.ipynb
/3-Background-Replacement.ipynb
/4-Object-Removal.ipynb
/5-Inpainting.ipynb
/6-Outpainting.ipynb
/7-Restyling.ipynb
/8-Superresolution.ipynb
/9-Txt2Img.ipynb
Preview: https://huggingface.co/spaces/AFM-Image-Editing/image-editing
In this section, we introduce the guide and steps of how to use the gradio app.
In order to use all the capabilities of our tool in an user-friendly way, we developed an app in a form of webserver GUI using the Gradio library.
This allows any user to upload their own images or artificially generate them via txt2img prompting, apply the aforementioned functionalities with different input parameters, visualize and download the results.
Our program supports usage of more than just one model for a each function. The used model can be selected on the dropdown menus within each tab before generating the output image.

code/afm_gradio.py
and navigate to the main function to specify the input image- and mask paths you'd like to be opened when lauching the app.
For that, simply edit the variables 'original_image_path' and 'input_mask_path' with your desired inputs.
This is an optional step, since you can also upload an input image (e.g. via drag-and-drop) directly in the UI.
cd code
python afm_gradio.py
After that, a public- and a local links for the accessing the UI will be generated. If you're using GPUs via remote access (SSH/Tunnel), we recommend using the public link.
(Optional): For inpainting / object removal, you have the option of directly inputting the image coordinates (clicking on image or writing coordinates) into the task (pipeline tabs), or if you prefer, first generate a mask preview and load the output mask as input for the optional mask input tasks on the left hand side.
To allow users more flexibility, we included several models for each functionality.
This section describes the implemented pipelines and exact model checkpoints used in the tool.
Additionally this helps us evaluate the results and compare them to the state-of-the-art methods.
Latent Diffusion pipeline: ldm_inpainting/last
LaMa pipeline: big-lama/best
image-editing/code/outputs/eval
and contain generated images for the introduced models. The qualitative evaluation is based on objective and subjective comaparison of the models to state-of-the-art tools or end products distributed by companies like Google, and also between the published models themselves.
34 commits
Python
70.1%
Jupyter Notebook
28.2%
Rich Text Format
1.8%