서민정

docs: update 0412.md

...@@ -168,7 +168,9 @@ Input: Images ...@@ -168,7 +168,9 @@ Input: Images
168 168
169 Output: Multi-Scaled Feature Maps 169 Output: Multi-Scaled Feature Maps
170 170
171 -Backbone 네트워크에는 이미지들이 인풋으로 들어간다. 그리고 결과물로서는 피라미드 형태의 서로 다른 스케일을 갖는 피쳐맵을 얻을 수 있다. 백본 네트워크의 결과물로 얻어진 피쳐맵은 다음 단계인 Region Proposal Network와, ROI Heads 둘 모두의 Input으로 이용된다. 171 +Backbone 네트워크에는 이미지들이 인풋으로 들어간다. 그리고 결과물로서는 서로 다른 스케일을 갖는 이미지로부터 피라미드 형태의 피쳐맵을 얻을 수 있다. Base-RCNN-FPN의 결과 피쳐들은 각각 P2(1/4 크기), P3(1/8), P4(1/16), P5(1/32), P6(1/64)라 불린다. 백본 네트워크의 결과물로 얻어진 피쳐맵은 다음 단계인 Region Proposal Network와, ROI Heads 둘 모두의 Input으로 이용된다.
172 +
173 +`Q. Note that non-FPN (‘C4’) architecture’s output feature is only from the 1/16 scale. 는 어떤 의미인지 이해가 잘 되지 않는다.`
172 174
173 * Region Proposal Network 175 * Region Proposal Network
174 176
...@@ -176,7 +178,7 @@ Input: Mutli-Scaled Feature Maps ...@@ -176,7 +178,7 @@ Input: Mutli-Scaled Feature Maps
176 178
177 Output: Object Regions(Region Proposals) 179 Output: Object Regions(Region Proposals)
178 180
179 -Region Proposal Network에서는 Multi-Scaled Feature Maps를 바탕으로 Object Region을 얻는 과정을 거친다. 해당 물체가 위치한 박스를 얻는다고 보면 될 것 같다. 이 단계에서 얻은 결과는 ROI Heads의 Input으로도 이용된다. 181 +Region Proposal Network에서는 Multi-Scaled Feature Maps를 바탕으로 Object Region을 얻는 과정을 거친다. 1000개의 box proposals를 confidence score와 함께 얻는다. 이 단계에서 얻은 결과는 ROI Heads의 Input으로도 이용된다.
180 182
181 * ROI Heads 183 * ROI Heads
182 184
...@@ -187,11 +189,105 @@ Output: Box ...@@ -187,11 +189,105 @@ Output: Box
187 RPN과 매우 유사하지만 더 fine-tuned 된 박스를 얻어내는 과정이다. 189 RPN과 매우 유사하지만 더 fine-tuned 된 박스를 얻어내는 과정이다.
188 190
189 ![d2_detail](./images/d2_detail.png) 191 ![d2_detail](./images/d2_detail.png)
190 -https://medium.com/@hirotoschwert/digging-into-detectron-2-47b2e794fabd 여기서부터 내일!
191 192
192 193
194 +## Structure of the detectron2 repository
195 +
196 +Detectron2의 레포지토리 구조는 다음과 같이 이루어져있다.
197 +```
198 +// copy from Digging into Detectron2
199 +detectron2
200 +├─checkpoint <- checkpointer and model catalog handlers
201 +├─config <- default configs and handlers
202 +├─data <- dataset handlers and data loaders
203 +├─engine <- predictor and trainer engines
204 +├─evaluation <- evaluator for each dataset
205 +├─export <- converter of detectron2 models to caffe2 (ONNX)
206 +├─layers <- custom layers e.g. deformable conv.
207 +├─model_zoo <- pre-trained model links and handler
208 +├─modeling
209 +│ ├─meta_arch <- meta architecture e.g. R-CNN, RetinaNet
210 +│ ├─backbone <- backbone network e.g. ResNet, FPN
211 +│ ├─proposal_generator <- region proposal network
212 +│ └─roi_heads <- head networks for pooled ROIs e.g. box, mask heads
213 +├─solver <- optimizer and scheduler builders
214 +├─structures <- structure classes e.g. Boxes, Instances, etc
215 +└─utils <- utility modules e.g. visualizer, logger, etc
216 +```
217 +
218 +1. Backbone Network:
219 + FPN (backbone/fpn.py)
220 + └ ResNet (backbone/resnet.py)
221 +2. Region Proposal Network:
222 + RPN(proposal_generator/rpn.py)
223 + ├ StandardRPNHead (proposal_generator/rpn.py)
224 + └ RPNOutput (proposal_generator/rpn_outputs.py)
225 +3. ROI Heads (Box Head):
226 + StandardROIHeads (roi_heads/roi_heads.py)
227 + ├ ROIPooler (poolers.py)
228 + ├ FastRCNNConvFCHead (roi_heads/box_heads.py)
229 + ├ FastRCNNOutputLayers (roi_heads/fast_rcnn.py)
230 + └ FastRCNNOutputs (roi_heads/fast_rcnn.py)
231 +
232 +
233 +## Deeper into the Backbone Network
234 +> Backbone 네트워크의 역할은 input image로부터 feature를 추출하는 것이다.
235 +![backbone](./images/backbone.png)
236 +
237 +Backbone 네트워크의 **input**은 (B, 3, H, W) image이다. B, H, W는 batch 크기, 이미지의 높이 및 너비를 각각 나타낸다. 주의해야할 것은 input color channel의 순서가 RGB가 아닌 BGR이라는 점이다. RGB이미지를 넣었을 때, BGR에 비해 성능이 더 좋지 않은 결과를 얻을 것이다.
238 +
239 +**output**은 (B,C,H/S, W/S) feature maps이다. C와 S는 각각 채널의 크기와 stride를 의미한다.
240 +
241 +예를 들어, 높이 800, 너비 1280의 input image를 backbone 네트워크에 넣었을때, 결과물은 다음과 같이 나타난다.
242 +```
243 +# By default, C = 256
244 +output["p2"].shape -> torch.Size([1, 256, 200, 320]) # stride = 4
245 +output["p3"].shape -> torch.Size([1, 256, 100, 160]) # stride = 8
246 +output["p4"].shape -> torch.Size([1, 256, 50, 80]) # stride = 16
247 +output["p5"].shape -> torch.Size([1, 256, 25, 40]) # stride = 32
248 +output["p6"].shape -> torch.Size([1, 256, 13, 20]) # stride = 64
249 +```
250 +
251 +FPN을 통해 얻어진 feature를 시각화한 결과는 다음과 같다. P6는 P2에 비해 더 큰 receptive field를 가진다는 것을 결과를 통해 확인할 수 있다. 즉, FPN은 multi-scale의 feature maps를 뽑아낼 수 있다.
252 +![output of fpn](./images/output_of_fpn.png)
253 +
254 +Backbone 네트워크를 구성하고 있던 ResNet과, ResNet을 통한 FPN의 자세한 구조는 우선은 다음으로 미루겠다. (너무 어렵다 😥)
255 +
256 +## How to load ground truth from a dataset and how the loaded data are processed before being fed to the network
257 +Base-RCNN-FPN에서 ground truth data는 RPN과 Box Head에 사용된다.
258 +Annotation된 데이터는 Box label(물체의 위치와 사이즈를 나타낸다.)과 Category label(object class id)를 포함한다. 여기서 Category label은 ROI Heads를 위해 사용된다. 그 이유는 RPN은 object의 카테고리 분류를 학습하지 않기 때문이다.
259 +
260 +#### Loading annotation data
261 +
262 +#### Mapping data
263 +
264 +## Deeper into the Region Proposal Network
265 +
266 +## Deeper into the ROI(Box) Head
267 +
193 # Tutorial of Detectron2 268 # Tutorial of Detectron2
194 -https://colab.research.google.com/drive/16jcaJoc6bCFAQ96jDe2HwtXj7BMD_-m5#scrollTo=h9tECBQCvMv3 269 +하나 하나 설명을 적지 않으면 나중에 다시 까먹곤 해서, 우선 [Detectron2에서 공식적으로 제공하는 튜토리얼](https://colab.research.google.com/drive/16jcaJoc6bCFAQ96jDe2HwtXj7BMD_-m5#scrollTo=QHnVupBBn9eR)을 코드 블럭마다 쪼개어 설명을 달아보려고 한다.
270 +
271 +우선, dependency를 설치해준다. detectron2는 pytorch base이므로, 필요한 패키지들을 import 한다.
272 +```python
273 +# install dependencies:
274 +!pip install pyyaml==5.1
275 +import torch, torchvision
276 +print(torch.__version__, torch.cuda.is_available())
277 +!gcc --version
278 +# opencv is pre-installed on colab
279 +```
280 +
281 +이제, detectron2를 설치해주자.
282 +```python
283 +# install detectron2: (Colab has CUDA 10.1 + torch 1.8)
284 +# See https://detectron2.readthedocs.io/tutorials/install.html for instructions
285 +import torch
286 +assert torch.__version__.startswith("1.8") # need to manually install torch 1.8 if Colab changes its default version
287 +!pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.8/index.html
288 +# exit(0) # After installation, you need to "restart runtime" in Colab. This line can also restart runtime
289 +```
290 +
195 291
196 292
197 ### Reference 293 ### Reference
......

159 KB | W: | H:

70.7 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin