{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-21T04:58:53.309119Z","iopub.execute_input":"2022-02-21T04:58:53.309688Z","iopub.status.idle":"2022-02-21T04:58:53.313381Z","shell.execute_reply.started":"2022-02-21T04:58:53.309646Z","shell.execute_reply":"2022-02-21T04:58:53.312548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"yolov5でクジラ/イルカの画像を切り取りしてからkerasで学習させたい。\n\n\n事前準備としてyolov5の使い方を整理する。","metadata":{}},{"cell_type":"markdown","source":"PATHの整理です。","metadata":{}},{"cell_type":"code","source":"def addpath(x):\n    BASE_PATH = \"/kaggle/input/happy-whale-and-dolphin/train\"\n    y = BASE_PATH + '/' + x\n    return y\ndf = pd.read_csv('/kaggle/input/happy-whale-and-dolphin/train.csv')\ndf['image'] = df['image'].apply(addpath)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T04:58:56.076457Z","iopub.execute_input":"2022-02-21T04:58:56.077137Z","iopub.status.idle":"2022-02-21T04:58:56.215336Z","shell.execute_reply.started":"2022-02-21T04:58:56.077089Z","shell.execute_reply":"2022-02-21T04:58:56.214408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"yolov5のセットアップ","metadata":{}},{"cell_type":"code","source":"!git clone https://github.com/ultralytics/yolov5  # clone\n%cd yolov5\n%pip install -qr requirements.txt  # install\n\nimport torch\nfrom yolov5 import utils\ndisplay = utils.notebook_init()  # checks","metadata":{"execution":{"iopub.status.busy":"2022-02-21T05:00:03.95846Z","iopub.execute_input":"2022-02-21T05:00:03.958796Z","iopub.status.idle":"2022-02-21T05:00:21.0661Z","shell.execute_reply.started":"2022-02-21T05:00:03.958755Z","shell.execute_reply":"2022-02-21T05:00:21.065033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BASE_PATH = \"/kaggle/input/happy-whale-and-dolphin/train\"\nSAVE_PATH = \"/kaggle/working/exp\"","metadata":{"execution":{"iopub.status.busy":"2022-02-21T05:00:42.84257Z","iopub.execute_input":"2022-02-21T05:00:42.842916Z","iopub.status.idle":"2022-02-21T05:00:42.847983Z","shell.execute_reply.started":"2022-02-21T05:00:42.842878Z","shell.execute_reply":"2022-02-21T05:00:42.847242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"プロジェクトフォルダに対してdetect.pyを実施\n/kaggle/workingフォルダへ結果保存\nsave-crop検出したものを切り取って保存exp/cropに保存されている。","metadata":{}},{"cell_type":"code","source":"!python detect.py --weights yolov5s.pt --img 640 --conf 0.01 --source /kaggle/input/happy-whale-and-dolphin/test_images/000110707af0ba.jpg --project /kaggle/working --save-crop\n#フォルダに適用する場合はこれを以下を使う\n#!python detect.py --weights yolov5s.pt --img 640 --conf 0.2 --source /kaggle/input/happy-whale-and-dolphin/test_images --project /kaggle/working --save-crop\n#display.Image(filename='/kaggle/input/happy-whale-and-dolphin/test_images/186a069306d4de.jpg', width=600)\n#display.Image(filename='/kaggle/working/yolov5/runs/detect/exp2/ffdcc55cbc1559.jpg', width=600)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T05:00:48.054662Z","iopub.execute_input":"2022-02-21T05:00:48.055104Z","iopub.status.idle":"2022-02-21T05:00:57.624749Z","shell.execute_reply.started":"2022-02-21T05:00:48.055073Z","shell.execute_reply":"2022-02-21T05:00:57.623586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"イルカやクジラと認識されない(/ω＼)\n\nクジラ/イルカのデータセットを用意し学習する。train.py\n\n学習後にdetecする。","metadata":{}},{"cell_type":"code","source":"display.Image(filename='/kaggle/working/exp/000110707af0ba.jpg', width=600)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T05:01:02.120939Z","iopub.execute_input":"2022-02-21T05:01:02.121245Z","iopub.status.idle":"2022-02-21T05:01:02.194028Z","shell.execute_reply.started":"2022-02-21T05:01:02.121215Z","shell.execute_reply":"2022-02-21T05:01:02.193302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-02-17T08:35:03.339354Z","iopub.execute_input":"2022-02-17T08:35:03.339723Z","iopub.status.idle":"2022-02-17T08:35:03.345508Z","shell.execute_reply.started":"2022-02-17T08:35:03.339695Z","shell.execute_reply":"2022-02-17T08:35:03.344787Z"},"trusted":true},"execution_count":null,"outputs":[]}]}