Skip to content

Instantly share code, notes, and snippets.

@merrybingo
Created October 4, 2019 05:35
Show Gist options
  • Save merrybingo/69fd5bb2e013da5f67a7873948246c25 to your computer and use it in GitHub Desktop.
Save merrybingo/69fd5bb2e013da5f67a7873948246c25 to your computer and use it in GitHub Desktop.
대학원 수업용 객체탐지 실험
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "object_detection.ipynb",
"provenance": [],
"private_outputs": true,
"collapsed_sections": [],
"toc_visible": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "5VJzdkvIaiIn",
"colab_type": "text"
},
"source": [
"# 항공영상에서 객체탐지를 위한 학습시키기"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "nTbSzB0Wh6dG",
"colab_type": "text"
},
"source": [
"작성자: 건국대학교 신기술융합학과 석사과정 김혜진\n",
"\n",
"작성일자: 2019-10-04\n",
"\n",
"목표: 누구나 객체탐지를 쉽게 할 수 있다.\n",
"\n",
"자세한 내용은 [여기서](https://github.com/merrybingo/object_detection) 보기 \n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "v2INnb4CaFtH",
"colab_type": "text"
},
"source": [
"## 소스코드 다운로드"
]
},
{
"cell_type": "code",
"metadata": {
"id": "SpUeauaHXeI_",
"colab_type": "code",
"colab": {}
},
"source": [
"# google drive 마운트 \n",
"\n",
"from google.colab import drive\n",
"drive.mount('/content/drive')"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "lda9sakpXewg",
"colab_type": "code",
"colab": {}
},
"source": [
"# 현재 경로 확인\n",
"\n",
"!pwd"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "HDtVcP8oXmTP",
"colab_type": "code",
"colab": {}
},
"source": [
"# 경로 변경\n",
"\n",
"%cd drive/My Drive/"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "8QjPIzZoXw1G",
"colab_type": "code",
"colab": {}
},
"source": [
"# 소스코드 다운로드\n",
"\n",
"!git clone https://github.com/merrybingo/object_detection.git"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "xjkMd5-SZppm",
"colab_type": "code",
"colab": {}
},
"source": [
"# 경로 변경\n",
"\n",
"%cd object_detection"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "X1BApZvPX08n",
"colab_type": "code",
"colab": {}
},
"source": [
"# coco weight 파일 다운로드 \n",
"\n",
"!wget https://github.com/matterport/Mask_RCNN/releases/download/v1.0/mask_rcnn_coco.h5"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "H-VUXR0hab5w",
"colab_type": "text"
},
"source": [
"## 실험 환경 구성"
]
},
{
"cell_type": "code",
"metadata": {
"id": "zy75iPiaZVAG",
"colab_type": "code",
"colab": {}
},
"source": [
"# 필수 라이브러리 설치\n",
"\n",
"!pip install -r requirements.txt"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "PSGxuCNYa51I",
"colab_type": "text"
},
"source": [
"## 데이터셋 준비"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "DTSdMOZ5gB5e",
"colab_type": "text"
},
"source": [
"구글 드라이브에 데이터 셋 업로드하기\n",
"\n",
"/drive/My Drive/object_detection/dataset 폴더에 train, val, test 폴더를 구성해 놓습니다.\n",
"\n",
"또는 \n",
"\n",
"/drive/My Drive/object_detection/dataset/load_dataset 폴더에 train, val, test 폴더를 구성해 놓습니다.\n",
"\n",
"\n",
"왼쪽 파일 탭의 **새로고침** 후 계속 진행합니다."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "VmDE_lUcbMv-",
"colab_type": "text"
},
"source": [
"## 학습"
]
},
{
"cell_type": "code",
"metadata": {
"id": "re6DmLaqbOgm",
"colab_type": "code",
"colab": {}
},
"source": [
"# 경로 변경 \n",
"\n",
"%cd code"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "cBBSkcD7bZgm",
"colab_type": "code",
"colab": {}
},
"source": [
"# 학습 시작\n",
"\n",
"!python train.py train --dataset=../dataset/ --weights=coco\n",
"\n",
"# !python train.py train --dataset=../dataset/load_dataset/ --weights=coco"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "sAHXNF3RgO3P",
"colab_type": "text"
},
"source": [
"## 예측"
]
},
{
"cell_type": "code",
"metadata": {
"id": "S2Ny7bwSgQMA",
"colab_type": "code",
"colab": {}
},
"source": [
"# object_time 폴더 명 설정 하고 실행하세요!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",
"\n",
"!python predict.py --dataset=../dataset/ --weights=logs/object_time/mask_rcnn_object_0030.h5\n",
"\n",
"# !python predict.py --dataset=../dataset/load_dataset/ --weights=logs/object_time/mask_rcnn_object_0030.h5"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "3BJ9PrLlg2Mf",
"colab_type": "text"
},
"source": [
"예측 완료되면 dataset/test 폴더에 '**이미지명_detect.png**' 파일들이 생성됩니다."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "AlcBS_C-hEPG",
"colab_type": "text"
},
"source": [
"## 성능 평가"
]
},
{
"cell_type": "code",
"metadata": {
"id": "kk_YijmLhGCV",
"colab_type": "code",
"colab": {}
},
"source": [
"# object_time 폴더 명 설정 하고 실행하세요!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",
"\n",
"!python evaluate.py --dataset=../dataset/ --weights=logs/object_time/mask_rcnn_object_0030.h5\n",
"\n",
"# !python evaluate.py --dataset=../dataset/load_dataset/ --weights=logs/object_time/mask_rcnn_object_0030.h5"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "cchcgG8fhXAW",
"colab_type": "text"
},
"source": [
"평가가 완료되면 mAP % 수치가 프린트 됩니다."
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment