ordaktaktak commited on
Commit
39d5afd
1 Parent(s): 0e64315

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +55 -0
README.md CHANGED
@@ -1,3 +1,58 @@
1
  ---
2
  license: mit
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
  ---
4
+ # Background Removal
5
+ [U-Net](https://arxiv.org/abs/1505.04597v1) Like([VGG](https://paperswithcode.com/method/vgg) Encoder) Pretrained Model For Human Body Detection ([pytorch](https://pytorch.org/), [Semantic Segmentation](https://paperswithcode.com/task/semantic-segmentation))
6
+
7
+ #### **Quick Links**
8
+ - [Implementation](#Implementation)
9
+ - [Usage](#Usage)
10
+ - [Examples](#Examples)
11
+
12
+ ## Implementation
13
+ ### VGG Encoder Implementation
14
+ ```python
15
+ def VGGEncoder():
16
+ weights = VGG16_Weights.DEFAULT
17
+ base_model = vgg16(weights=weights)
18
+ base_model.training = False
19
+
20
+ encoder_seq = nn.ModuleList()
21
+ moduls = nn.Sequential()
22
+ for layer in list(base_model.features.children()):
23
+ if isinstance(layer, nn.modules.pooling.MaxPool2d):
24
+ encoder_seq.append(moduls)
25
+ moduls = nn.Sequential()
26
+ else:
27
+ moduls.append(layer)
28
+ return encoder_seq
29
+ ```
30
+
31
+ ## Usage:
32
+ ```python
33
+ detector = BodyDetector("model_weights/bgrm-bh.pth")
34
+ ```
35
+ Load model.
36
+
37
+ ```python
38
+ fname = RandomSample("background folder", '*')
39
+ bg = LoadImage(fname)
40
+ ```
41
+ Read background image.
42
+
43
+ ```python
44
+ fname = RandomSample("image folder")
45
+ img = LoadImage(fname)
46
+ img_resize = cv2.resize(img, (224, 224), interpolation = cv2.INTER_AREA)
47
+ ```
48
+ Read image in bgr mode and resize it to 224*224.
49
+
50
+ ```python
51
+ mask = detector.DetectBody(img_resize)
52
+ ```
53
+ Detect object(human body) area.
54
+
55
+ ```python
56
+ res = ReplaceBG(img, mask, bg)
57
+ ```
58
+ Replace current background with loaded background image.