Spaces:
Running
Running
Update README.md
Browse files
README.md
CHANGED
@@ -1,71 +1,12 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: red
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.1.1
|
8 |
app_file: app.py
|
9 |
-
pinned:
|
10 |
license: apache-2.0
|
11 |
duplicated_from: rkoushikroy2/portrait_photo_generator
|
12 |
-
---
|
13 |
-
# Portrait Photo Generator
|
14 |
-
|
15 |
-
In this repo we are going to use image segmentation model(facebook/detr-resnet-50-panoptic) to generate portrait photo of any object present in a photo. Then we are going to make a deployable app using gradio and finally, we will host it in hugging face hub spaces.
|
16 |
-
|
17 |
-
## User Interface
|
18 |
-
Here is a screenshot of the interface. The app has been hosted in hugging face spaces. [Click Here]() to explore the deployed version.
|
19 |
-
![Interface Snapshot](interface_snapshot.png)
|
20 |
-
> You can drag and drop images in the top left image box. After you drop an image the image segmentaion model will process the image and provide a list of objects in the drowpdown menu in the right. Now, you can choose any object from the list and that objet will be foucsed in the Output image box. You can adjust the slider to adject the strength of the background blur. The whole interface is reactive and anything you change will trigger an auto refresh. You may find the example images in lower right useful.
|
21 |
-
|
22 |
-
## Protrait Image Generation Steps:
|
23 |
-
- Load segmentation model, pass your image, generate the masks and labels for each object present in the image.
|
24 |
-
- Make a list of objects from the "label" keys in the prediction dictionaries.
|
25 |
-
- Add a number identifier so that each object name can be unique. This is important for selecting a object.
|
26 |
-
- Image segmentation and background blurring method for selected object in the image:
|
27 |
-
- Take the mask provided by the segmentation model in the earlier stage.
|
28 |
-
- Divide by 255 to make the range 0 to 1.
|
29 |
-
- At this point the mask is 1 channel. Make it three channel by coping the single channel three times.
|
30 |
-
- Element wise multiply the input image and the three channel mask.
|
31 |
-
This will give an image where only the segmented part of the image will be present. This means, only the selected object pixels will be intact and other pixels will be black (0).
|
32 |
-
- Now, take the original image and blur it using any kind of blurring kernel. Here I used Gaussian Blur.
|
33 |
-
- After that, create a invert of the three channel mask created the previous steps.
|
34 |
-
- Element wise multiply the invert mask and blurred image.
|
35 |
-
This will give an image where the blurred background of the selected object will be present and
|
36 |
-
the pixels associate with the object of interest will be blank/black/value=0.
|
37 |
-
- Then, add up the segmented image and reverse segmented (blurred background portion).
|
38 |
-
This will give the desired portrait photo looking output.
|
39 |
-
- Smoothen the image.
|
40 |
-
|
41 |
-
## Gradio GUI Steps:
|
42 |
-
- Used block element for more control over the interface.
|
43 |
-
- Used image.change, slider.change and dropdown.change event handler for generating output each time any of these changes.
|
44 |
-
|
45 |
-
## Requirements
|
46 |
-
```
|
47 |
-
gradio
|
48 |
-
numpy
|
49 |
-
Pillow
|
50 |
-
torch
|
51 |
-
timm
|
52 |
-
transformers
|
53 |
-
```
|
54 |
-
```
|
55 |
-
pip install -r requirements.txt
|
56 |
-
```
|
57 |
-
|
58 |
-
## Run App
|
59 |
-
```
|
60 |
-
python app.py
|
61 |
-
```
|
62 |
-
|
63 |
-
## Files
|
64 |
-
| File | Contents |
|
65 |
-
|---|--- |
|
66 |
-
| [Segmentation Notebook](segmentation.ipynb) | Here the segmentation model to background blur part has been shown step by step.|
|
67 |
-
| [Gradio Notebook](gradio.ipynb) | You may experiment with different componets of a gradio app.|
|
68 |
-
| [Gradio App](app.py) | It is the main file of the deploed version of the portrait photo generator app.|
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
1 |
---
|
2 |
+
title: Image Dissector
|
3 |
+
emoji: π―π
π¦π¨βπ³πΌπ²
|
4 |
colorFrom: red
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.1.1
|
8 |
app_file: app.py
|
9 |
+
pinned: true
|
10 |
license: apache-2.0
|
11 |
duplicated_from: rkoushikroy2/portrait_photo_generator
|
12 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|