<jupyter_start><jupyter_text>항공영상에서 객체탐지를 위한 학습시키기 작성자:   건국대학교 신기술융합학과 석사과정 김혜진\수정자:   건국대학교 신기술융합학과 석사과정 원태연작성일자: 2019-10-04\수정일자: 2021-03-15목표:     누구나 객체탐지를 쉽게 할 수 있다.자세한 내용은 [여기서](https://github.com/DuaNoDo/object-detection) 보기   소스코드 다운로드<jupyter_code># google drive 마운트 

from google.colab import drive
drive.mount('/content/drive')
# 아나콘다 설치
!wget -c https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh
!bash ./Anaconda3-5.1.0-Linux-x86_64.sh -b -f -p /usr/local
#학습에 필요한 tensorflow-gpu를 설치 
#중간에 y 엔터 눌러줘야함
!conda install -c anaconda tensorflow-gpu==1.15.0

# 현재 경로 확인
!pwd
# 경로 변경

%cd drive/My Drive/
# 소스코드 다운로드

!git clone https://github.com/DuaNoDo/object-detection.git
# 경로 변경

%cd object-detection
# coco weight 파일 다운로드 

!wget https://github.com/matterport/Mask_RCNN/releases/download/v1.0/mask_rcnn_coco.h5<jupyter_output>--2021-03-15 13:38:53--  https://github.com/matterport/Mask_RCNN/releases/download/v1.0/mask_rcnn_coco.h5
Resolving github.com (github.com)... 172.16.58.34
Connecting to github.com (github.com)|192.168.3.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-releases.githubusercontent.com/107595270/1f48ee60-bf1e-11e7-8bf6-7c269c8ff900?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210315%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210315T133853Z&X-Amz-Expires=300&X-Amz-Signature=520d950cff299ae117bb14ef51146b1c841965920d961952d27be7b2552ff4d1&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=107595270&response-content-disposition=attachment%3B%20filename%3Dmask_rcnn_coco.h5&response-content-type=application%2Foctet-stream [following]
--2021-03-15 13:38:53--  https://github-releases.githubusercontent.com/107595270/1f48ee60-bf1e-11e7-8bf6-7c269c8ff900?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=<KEY>[...]<jupyter_text>실험 환경 구성<jupyter_code># 필수 라이브러리 설치
!pip install -r requirements_gpu.txt

!pip install -U scikit-image==0.16.2
!pip install keras==2.2.4<jupyter_output>Collecting keras==2.2.4
  Downloading Keras-2.2.4-py2.py3-none-any.whl (312 kB)
[K     |████████████████████████████████| 312 kB 4.2 MB/s 
[?25hRequirement already satisfied: numpy>=1.9.1 in /usr/local/lib/python3.7/site-packages (from keras==2.2.4) (1.19.1)
Requirement already satisfied: keras-preprocessing>=1.0.5 in /usr/local/lib/python3.7/site-packages (from keras==2.2.4) (1.1.0)
Requirement already satisfied: keras-applications>=1.0.6 in /usr/local/lib/python3.7/site-packages (from keras==2.2.4) (1.0.8)
Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python3.7/site-packages (from keras==2.2.4) (1.15.0)
Requirement already satisfied: scipy>=0.14 in /usr/local/lib/python3.7/site-packages (from keras==2.2.4) (1.5.2)
Collecting pyyaml
  Downloading PyYAML-5.4.1-cp37-cp37m-manylinux1_x86_64.whl (636 kB)
[K     |████████████████████████████████| 636 kB 8.7 MB/s 
[?25hRequirement already satisfied: h5py in /usr/local/lib/python3.7/site-packages (from keras==2.2.4) (2.10.0[...]<jupyter_text>데이터셋 준비 구글 드라이브에 데이터 셋 업로드하기/drive/My Drive/object_detection/dataset 폴더에 train, val, test 폴더를 구성해 놓습니다.왼쪽 파일 탭의 **새로고침** 후 계속 진행합니다.  학습<jupyter_code># 경로 변경 
%cd code
# 학습 시작
!python train.py train --dataset=../dataset/ --weights=coco<jupyter_output>Using TensorFlow backend.
Weights:  coco
Dataset:  ../dataset/
Logs:  /content/drive/My Drive/object-detection/logs

Configurations:
BACKBONE                       resnet101
BACKBONE_STRIDES               [4, 8, 16, 32, 64]
BATCH_SIZE                     1
BBOX_STD_DEV                   [0.1 0.1 0.2 0.2]
COMPUTE_BACKBONE_SHAPE         None
DETECTION_MAX_INSTANCES        100
DETECTION_MIN_CONFIDENCE       0.9
DETECTION_NMS_THRESHOLD        0.3
FPN_CLASSIF_FC_LAYERS_SIZE     1024
GPU_COUNT                      1
GRADIENT_CLIP_NORM             5.0
IMAGES_PER_GPU                 1
IMAGE_CHANNEL_COUNT            3
IMAGE_MAX_DIM                  1024
IMAGE_META_SIZE                14
IMAGE_MIN_DIM                  800
IMAGE_MIN_SCALE                0
IMAGE_RESIZE_MODE              square
IMAGE_SHAPE                    [1024 1024    3]
LEARNING_MOMENTUM              0.9
LEARNING_RATE                  0.001
LOSS_WEIGHTS                   {'rpn_class_loss': 1.0, 'rpn_bbox_loss': 1.0, 'mrcnn_cla[...]<jupyter_text>예측<jupyter_code># object_time 폴더 명 설정 하고 실행하세요!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# 파일들중 가장 마지막에 생성된 h5 파일의 이름을 입력.

!python predict.py --dataset=../dataset/ --weights=logs/object20210315T1341/mask_rcnn_object_0030.h5

# 예시 !python predict.py --dataset=../dataset/ --weights=logs/object20210315T1306/mask_rcnn_object_0002.h5<jupyter_output>Using TensorFlow backend.

Configurations:
BACKBONE                       resnet101
BACKBONE_STRIDES               [4, 8, 16, 32, 64]
BATCH_SIZE                     1
BBOX_STD_DEV                   [0.1 0.1 0.2 0.2]
COMPUTE_BACKBONE_SHAPE         None
DETECTION_MAX_INSTANCES        100
DETECTION_MIN_CONFIDENCE       0.9
DETECTION_NMS_THRESHOLD        0.3
FPN_CLASSIF_FC_LAYERS_SIZE     1024
GPU_COUNT                      1
GRADIENT_CLIP_NORM             5.0
IMAGES_PER_GPU                 1
IMAGE_CHANNEL_COUNT            3
IMAGE_MAX_DIM                  1024
IMAGE_META_SIZE                14
IMAGE_MIN_DIM                  800
IMAGE_MIN_SCALE                0
IMAGE_RESIZE_MODE              square
IMAGE_SHAPE                    [1024 1024    3]
LEARNING_MOMENTUM              0.9
LEARNING_RATE                  0.001
LOSS_WEIGHTS                   {'rpn_class_loss': 1.0, 'rpn_bbox_loss': 1.0, 'mrcnn_class_loss': 1.0, 'mrcnn_bbox_loss': 1.0, 'mrcnn_mask_loss': 1.0}
MASK_POOL_SIZE             [...]<jupyter_text>예측 완료되면 dataset/test 폴더에 '**이미지명_detect.png**' 파일들이 생성됩니다.  성능 평가<jupyter_code># object_time 폴더 명 설정 하고 실행하세요!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!python evaluate.py --dataset=../dataset/ --weights=logs/object20210315T1341/mask_rcnn_object_0030.h5

# !python evaluate.py --dataset=../dataset/ --weights=logs/object20210315T1306/mask_rcnn_object_0002.h5<jupyter_output>Using TensorFlow backend.

Configurations:
BACKBONE                       resnet101
BACKBONE_STRIDES               [4, 8, 16, 32, 64]
BATCH_SIZE                     1
BBOX_STD_DEV                   [0.1 0.1 0.2 0.2]
COMPUTE_BACKBONE_SHAPE         None
DETECTION_MAX_INSTANCES        100
DETECTION_MIN_CONFIDENCE       0.9
DETECTION_NMS_THRESHOLD        0.3
FPN_CLASSIF_FC_LAYERS_SIZE     1024
GPU_COUNT                      1
GRADIENT_CLIP_NORM             5.0
IMAGES_PER_GPU                 1
IMAGE_CHANNEL_COUNT            3
IMAGE_MAX_DIM                  1024
IMAGE_META_SIZE                14
IMAGE_MIN_DIM                  800
IMAGE_MIN_SCALE                0
IMAGE_RESIZE_MODE              square
IMAGE_SHAPE                    [1024 1024    3]
LEARNING_MOMENTUM              0.9
LEARNING_RATE                  0.001
LOSS_WEIGHTS                   {'rpn_class_loss': 1.0, 'rpn_bbox_loss': 1.0, 'mrcnn_class_loss': 1.0, 'mrcnn_bbox_loss': 1.0, 'mrcnn_mask_loss': 1.0}
MASK_POOL_SIZE             [...]
{'fraction_non_alphanumeric': 0.12413009515693793, 'fraction_numerical': 0.09146428064195426, 'mean_word_length': 2.704366123093109, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 22, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '198084', 'license': 'MIT', 'n_tokens_mistral': 3388, 'n_tokens_neox': 3235, 'n_words': 474, 'path': 'object_detection.ipynb', 'repo_name': 'DuaNoDo/object-detection', 'size': '7050'}