# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3.8.12 ('aiffel_3.8')
#     language: python
#     name: python3
# ---

# # 7. Object Detection
#
# **Object detection 문제와 이를 해결하기 위한 다양한 detection 모델들을 알아본다.**

# ## 7-1. 들어가며

# ```bash
# $ mkdir -p ~/aiffel/object_detection/images
# ```

# ## 7-2. 용어 정리

# ```bash
# $ ln -s ~/data/person.jpg ~/aiffel/object_detection/images/
# ```

# +
from PIL import Image, ImageDraw
import os

img_path=os.getenv('HOME')+'/aiffel/object_detection/images/person.jpg'
img = Image.open(img_path)

# [[YOUR CODE]]
draw = ImageDraw.Draw(img)
draw.rectangle((130, 30, 670, 450), outline=(0,255,0), width=2)

img
# -

# ```python
# # 정답 코드
#
# from PIL import Image, ImageDraw
# import os
#
# img_path=os.getenv('HOME')+'/aiffel/object_detection/images/person.jpg'
# img = Image.open(img_path)
#
# draw = ImageDraw.Draw(img)
# draw.rectangle((130, 30, 670, 450), outline=(0,255,0), width=2)
#
# img
# ```

# ## 7-3. Localization

# +
import tensorflow as tf
from tensorflow import keras

output_num = 1+4+3 # object_prob 1, bbox coord 4, class_prob 3

input_tensor = keras.layers.Input(shape=(224, 224, 3), name='image')
base_model = keras.applications.resnet.ResNet50(
    input_tensor=input_tensor,
    include_top=False,    
    weights='imagenet',
    pooling=None,
)
x = base_model.output
# [[YOUR CODE]]
preds = keras.layers.Conv2D(output_num, 1, 1)(x)
localize_model=keras.Model(inputs=base_model.input, outputs=preds)

localize_model.summary()
# -

# ```python
# # 정답 코드
#
# import tensorflow as tf
# from tensorflow import keras
#
# output_num = 1+4+3 # object_prob 1, bbox coord 4, class_prob 3
#
# input_tensor = keras.layers.Input(shape=(224, 224, 3), name='image')
# base_model = keras.applications.resnet.ResNet50(
#     input_tensor=input_tensor,
#     include_top=False,
#     weights='imagenet',
#     pooling=None,
# )
# x = base_model.output
# preds = keras.layers.Conv2D(output_num, 1, 1)(x)
# localize_model=keras.Model(inputs=base_model.input, outputs=preds)
#
# localize_model.summary()
# ```

# ## 7-4. Detection (1) 슬라이딩 윈도우, 컨볼루션

# ## 7-5. Detection (2) 앵커 박스, NMS

# ## 7-6. Detection Architecture

# ## 7-7. Anchor

StarcoderdataJupyterScriptsDedupFiltered