{"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":"markdown","source":"lunana  \nlast update 2022 04 08  \nゆっくりしていってね！  ","metadata":{"id":"3aM8dNjwKVmY"}},{"cell_type":"markdown","source":"version 5 +Trends  \nversion 6 Trends update","metadata":{}},{"cell_type":"markdown","source":"# Trends  \n## datasets\n* happywhale-tfrecords-v1 ( KS )  \nhttps://www.kaggle.com/datasets/ks2019/happywhale-tfrecords-v1  \n* backfintfrecords ( Jan Bre )  \nhttps://www.kaggle.com/datasets/jpbremer/backfintfrecords  \n* happywhale-tfrecords-bb ( Lex Toumbourou )  \nhttps://www.kaggle.com/datasets/lextoumbourou/happywhale-tfrecords-bb","metadata":{}},{"cell_type":"markdown","source":"## notebook  \n* happywhale_arcface_baseline_eff7_tpu_768_inference ( Andrij ) LB=0.729  \nEff-v1-B7 image_size=768 happywhale-tfrecords-v1 TPU 5folds  \nhttps://www.kaggle.com/code/aikhmelnytskyy/happywhale-arcface-baseline-eff7-tpu-768-inference  \n* 0.720_🐳&🐬EFF_B5_640_Rotate ( Rabbit ) LB=0.720  \nEff-v1-B5 image_size=640 backfintfrecords 5folds  \nhttps://www.kaggle.com/code/nghiahoangtrung/0-720-eff-b5-640-rotate  \n* Happywhale - Effnet B7 fork with Detic Training ( Andrij ) LB=0.699  \nEff-v1-B7 image_size=768 happywhale-tfrecords-bb TPU 5folds  \nhttps://www.kaggle.com/code/aikhmelnytskyy/happywhale-effnet-b7-fork-with-detic-training  \n* [日本語&ENG] HappyWhale effnetv2-m ゆっくり実況 [infer] ( pixyz0130 ) LB=0.630  \nEff-v2-m image_size=768 happywhale-tfrecords-v1 TPU 5folds  \nhttps://www.kaggle.com/code/pixyz0130/eng-happywhale-effnetv2-m-infer  \n* [日本語&ENG] HappyWhale effnetv2-s add test ゆっくり実況 ( pixyz0130 ) LB=0.556  \nEff-v2-s image_size=512 happywhale-tfrecords-v1 TPU 5folds  \nhttps://www.kaggle.com/code/pixyz0130/eng-happywhale-effnetv2-s-add-test","metadata":{}},{"cell_type":"markdown","source":"## post-train models  \n* happywhale-effv2m-ver2 ( pixyz0130 ) LB=0.630  \nEff-v2-m image_size=768 happywhale-tfrecords-v1 TPU 5folds  \nhttps://www.kaggle.com/datasets/pixyz0130/happywhale-effv2m-ver2  \n* HappyWhale-effv2s ( pixyz0130 ) LB=0.556  \nEff-v2-s image_size=512 happywhale-tfrecords-v1 TPU 5folds  \nhttps://www.kaggle.com/datasets/pixyz0130/happywhale-effv2s","metadata":{}},{"cell_type":"markdown","source":"# Data list\n* [**train_images**](#train_images)  \n* [**train.csv**](#train.csv)  \n* [**test_images**](#test_images)  \n* [**sample_submission**](#sample_submission)","metadata":{}},{"cell_type":"markdown","source":"**霊夢：今日も画像のコンペだね。  \n魔理沙：まずは概要を読んでみよう。**  \n\n**Reimu: It's an image competition today as well.  \nMarisa: First, let's read the overview.**","metadata":{"id":"PgIt2tfOKYvb"}},{"cell_type":"markdown","source":"# Overview","metadata":{}},{"cell_type":"markdown","source":"指紋と顔認識を使用して人を識別しますが、動物でも同様のアプローチを使用できますか？実際、研究者は、尾、背びれ、頭、その他の体の部分の形やマーキングによって、海洋生物を手動で追跡しています。写真による自然なマーキングによる識別（photo-IDとして知られています）は、海洋哺乳類科学のための強力なツールです。これにより、個々の動物を経時的に追跡し、個体群の状態と傾向を評価することができます。クジラとイルカの写真IDを自動化するための支援により、研究者は画像の識別時間を99％以上短縮できます。より効率的な識別により、以前は手が届かなかった、または不可能だった規模の研究が可能になる可能性があります。  \n\n\n現在、ほとんどの研究機関は、時間のかかる、場合によっては不正確な、人間の目による手動マッチングに依存しています。何千時間も手動マッチングに費やされます。これには、写真を凝視して1人の個人を別の個人と比較し、一致を見つけ、新しい個人を特定することが含まれます。研究者はクジラの写真を1、2枚見るのを楽しんでいますが、手動で照合すると範囲と範囲が制限されます。  \n\n\n<img src=\"https://storage.googleapis.com/kaggle-media/competitions/Happywhale/AU%20Kaggle%20Competition%20Description%20Image-03.jpg\" width=500>\n\nこのコンテストで開発されたアルゴリズムは、共同研究および市民科学のWebプラットフォームであるHappywhaleに実装されます。その使命は、質の高い保存科学と教育を通じて、海洋環境に対する世界的な理解と配慮を高めることです。Happywhaleは、海洋哺乳類に関心のある人を引き付ける革新的なツールを構築することにより、一般の人々が科学に参加するのを簡単でやりがいのあるものにすることを目指しています。このプラットフォームは、強力なコラボレーションツールを使用して研究コミュニティにもサービスを提供します。  \n\n\nこのコンテストでは、個々のクジラとイルカを、それらの自然なマーキングのユニークな、しかししばしば微妙な特徴によって一致させるモデルを開発します。28の研究機関によって構築された複数種のデータセットからの画像セットの背びれと体の側面のビューに特に注意を払います。最高の提出物は、高速で正確な写真IDソリューションを提案します。  \n\n\n成功すれば、世界の変化する海への影響をよりよく理解して管理するための高度なテクノロジーを構築することができます。以前の自動化の試みにより、50,000頭を超えるクジラのグローバルデータベースが作成され、最もクジラが豊富な地域で最高速度11mphで運航するクルーズ船との合意が得られました。海洋生物の識別を自動化するというあなたのアイデアは、海洋への人間の影響の増大を克服するのに役立ち、保存科学のための重要なツールを提供します。クジラがいるなら、方法があります！  \n\nWe use fingerprints and facial recognition to identify people, but can we use similar approaches with animals? In fact, researchers manually track marine life by the shape and markings on their tails, dorsal fins, heads and other body parts. Identification by natural markings via photographs—known as photo-ID—is a powerful tool for marine mammal science. It allows individual animals to be tracked over time and enables assessments of population status and trends. With your help to automate whale and dolphin photo-ID, researchers can reduce image identification times by over 99%. More efficient identification could enable a scale of study previously unaffordable or impossible.\n\n\n\nCurrently, most research institutions rely on time-intensive—and sometimes inaccurate—manual matching by the human eye. Thousands of hours go into manual matching, which involves staring at photos to compare one individual to another, finding matches, and identifying new individuals. While researchers enjoy looking at a whale photo or two, manual matching limits the scope and reach.\n\nAlgorithms developed in this competition will be implemented in Happywhale, a research collaboration and citizen science web platform. Its mission is to increase global understanding and caring for marine environments through high quality conservation science and education. Happywhale aims to make it easy and rewarding for the public to participate in science by building innovative tools to engage anyone interested in marine mammals. The platform also serves the research community with powerful collaborative tools.\n\nIn this competition, you’ll develop a model to match individual whales and dolphins by unique—but often subtle—characteristics of their natural markings. You'll pay particular attention to dorsal fins and lateral body views in image sets from a multi-species dataset built by 28 research institutions. The best submissions will suggest photo-ID solutions that are fast and accurate.\n\nIf successful, you'll have a hand in building advanced technology to better understand and manage the impact on the world’s changing oceans. Previous automation attempts resulted in a global database of over 50,000 whales and an agreement with cruise ships to operate at a maximum speed of 11 mph in the most whale-rich region. Your ideas to automate the identification of marine life will help overcome increasing human impacts on oceans, providing a critical tool for conservation science. If there's a whale, there's a way!","metadata":{"id":"qqlnWh3yKZ-R"}},{"cell_type":"markdown","source":"![https://1.bp.blogspot.com/-11NArzo1PTw/VYjRVq3PMoI/AAAAAAAAuno/KZY4E7bqQes/s550/whale_10_tsuchikujira.png](https://1.bp.blogspot.com/-11NArzo1PTw/VYjRVq3PMoI/AAAAAAAAuno/KZY4E7bqQes/s550/whale_10_tsuchikujira.png)","metadata":{}},{"cell_type":"markdown","source":"**魔理沙：次はデータを見てみよう**\n\n**Marisa: Next, let's look at the data.**","metadata":{"id":"8eZi9TNGKdl3"}},{"cell_type":"markdown","source":"# train.csv","metadata":{}},{"cell_type":"markdown","source":"train.csv-各トレーニング画像のspeciesとindividual_idを提供します  \n\ntrain.csv - provides the species and the individual_id for each of the training images","metadata":{"id":"Q2U_WmKrKxA0"}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pylab as plt","metadata":{"id":"gjVvKrXcKs1o","execution":{"iopub.status.busy":"2022-03-09T11:48:21.019146Z","iopub.execute_input":"2022-03-09T11:48:21.020391Z","iopub.status.idle":"2022-03-09T11:48:21.051381Z","shell.execute_reply.started":"2022-03-09T11:48:21.020255Z","shell.execute_reply":"2022-03-09T11:48:21.050638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv(\"../input/happy-whale-and-dolphin/train.csv\")\ndf_train.head()","metadata":{"id":"74V8FJWGK3cF","execution":{"iopub.status.busy":"2022-03-09T11:48:21.052782Z","iopub.execute_input":"2022-03-09T11:48:21.0534Z","iopub.status.idle":"2022-03-09T11:48:21.180642Z","shell.execute_reply.started":"2022-03-09T11:48:21.053363Z","shell.execute_reply":"2022-03-09T11:48:21.179664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.describe()","metadata":{"id":"lK8RntkELDWW","execution":{"iopub.status.busy":"2022-03-09T11:48:21.182317Z","iopub.execute_input":"2022-03-09T11:48:21.182803Z","iopub.status.idle":"2022-03-09T11:48:21.28481Z","shell.execute_reply.started":"2022-03-09T11:48:21.182758Z","shell.execute_reply":"2022-03-09T11:48:21.283742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(df_train)","metadata":{"id":"OG4ej4ohLJQT","execution":{"iopub.status.busy":"2022-03-09T11:48:21.286876Z","iopub.execute_input":"2022-03-09T11:48:21.287124Z","iopub.status.idle":"2022-03-09T11:48:21.293872Z","shell.execute_reply.started":"2022-03-09T11:48:21.287097Z","shell.execute_reply":"2022-03-09T11:48:21.292765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**魔理沙:speciesのグラフを書いてみよう。**\n\n**Marisa: Let's draw a graph of species.**","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(15, 12))\nplt.rcParams[\"font.size\"] = 18\nplt.barh(df_train[\"species\"].value_counts().sort_values(ascending=True).index,df_train[\"species\"].value_counts().sort_values(ascending=True),tick_label = df_train[\"species\"].value_counts().sort_values(ascending=True).index)","metadata":{"execution":{"iopub.status.busy":"2022-03-09T11:48:21.2956Z","iopub.execute_input":"2022-03-09T11:48:21.295833Z","iopub.status.idle":"2022-03-09T11:48:21.809261Z","shell.execute_reply.started":"2022-03-09T11:48:21.295804Z","shell.execute_reply":"2022-03-09T11:48:21.808334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**霊夢:クジラよりイルカの方が多い？  \n魔理沙:そんな気がする。  \n霊夢:”beluga\"って何？  \n魔理沙:belugaはシロイルカだよ。**\n\n**Reimu: Are there more dolphins than whales?  \nMarisa: I feel like that.  \nReimu: What is \"beluga\"?  \nMarisa: beluga is a beluga whale.**\n\n![https://3.bp.blogspot.com/-UVd6L9Akev0/Ut0BNimmsRI/AAAAAAAAdUk/50BVIxHzGw0/s400/animal_shiroiruka.png](https://3.bp.blogspot.com/-UVd6L9Akev0/Ut0BNimmsRI/AAAAAAAAdUk/50BVIxHzGw0/s400/animal_shiroiruka.png)","metadata":{}},{"cell_type":"markdown","source":"**魔理沙：画像データを見てみよう。**\n\n**Marisa: Let's take a look at the image data.**\n\n![https://4.bp.blogspot.com/-6sCiU0t3xEw/XDXctFskcpI/AAAAAAABRMQ/J_7v9n7-nmcL2PFWYx3suE3pzqlvApxMwCLcBGAs/s400/sougankyou_nozoku_girl.png](https://4.bp.blogspot.com/-6sCiU0t3xEw/XDXctFskcpI/AAAAAAABRMQ/J_7v9n7-nmcL2PFWYx3suE3pzqlvApxMwCLcBGAs/s400/sougankyou_nozoku_girl.png)","metadata":{"id":"WoCsXTPcNH1l"}},{"cell_type":"markdown","source":"# train_images","metadata":{}},{"cell_type":"markdown","source":"train_images / -トレーニング画像を含むフォルダ  \n\ntrain_images/ - a folder containing the training images","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nfrom glob import glob","metadata":{"id":"4PyoOrFSMY76","execution":{"iopub.status.busy":"2022-03-09T11:48:21.810567Z","iopub.execute_input":"2022-03-09T11:48:21.810823Z","iopub.status.idle":"2022-03-09T11:48:21.815058Z","shell.execute_reply.started":"2022-03-09T11:48:21.810792Z","shell.execute_reply":"2022-03-09T11:48:21.814235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BASE_PATH = \"../input/happy-whale-and-dolphin/train_images/\"\nTRAIN_IMAGES = glob(BASE_PATH + \"train/*.jpg\")","metadata":{"execution":{"iopub.status.busy":"2022-03-09T11:57:42.321135Z","iopub.execute_input":"2022-03-09T11:57:42.321455Z","iopub.status.idle":"2022-03-09T11:57:42.326981Z","shell.execute_reply.started":"2022-03-09T11:57:42.321401Z","shell.execute_reply":"2022-03-09T11:57:42.326219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for x in range(5):\n    path = BASE_PATH + np.random.choice(df_train['image'])\n    im = plt.imread(path)\n    plt.figure(figsize=(15, 6))\n    plt.imshow(im)\n    plt.title(path.split(\"/\")[-1])\n    plt.xticks([]), plt.yticks([])\n    df_train[df_train['image']==path.split('/')[-1]]","metadata":{"id":"5XHg_etYMPGn","execution":{"iopub.status.busy":"2022-03-09T11:58:30.470791Z","iopub.execute_input":"2022-03-09T11:58:30.471105Z","iopub.status.idle":"2022-03-09T11:58:36.606076Z","shell.execute_reply.started":"2022-03-09T11:58:30.471074Z","shell.execute_reply":"2022-03-09T11:58:36.605388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**霊夢:体の1部しか映ってないから判別難しいな。**\n\n**Reimu:It's difficult to tell because you can only see one part of your body.**\n![https://3.bp.blogspot.com/-VkaXRdIAzRU/WUdYwLM2msI/AAAAAAABE_E/Ob4pV2KxYAUvnkvQDhtTdY-lWeZWWbTkACLcBGAs/s400/kaisya_komaru_man.png](https://3.bp.blogspot.com/-VkaXRdIAzRU/WUdYwLM2msI/AAAAAAABE_E/Ob4pV2KxYAUvnkvQDhtTdY-lWeZWWbTkACLcBGAs/s400/kaisya_komaru_man.png)","metadata":{}},{"cell_type":"markdown","source":"**魔理沙：次はテストデータを見てみよう。**\n\n**Marisa: Next, let's look at the test data.**","metadata":{"id":"GbcARKHhNeuh"}},{"cell_type":"markdown","source":"# test_images","metadata":{}},{"cell_type":"markdown","source":"test_images / -テスト画像を含むフォルダ。各画像について、あなたの仕事はindividual_id;を予測することです。試験データの種情報は提供されていません。テストデータには、トレーニングデータでは観察されない個人がいます。これは、new_individualとして予測する必要があります。  \n\ntest_images/ - a folder containing the test images; for each image, your task is to predict the individual_id; no species information is given for the test data; there are individuals in the test data that are not observed in the training data, which should be predicted as new_individual.","metadata":{"id":"lQZFjTdpN6W9"}},{"cell_type":"markdown","source":"**霊夢:え？？individual_idを予測するの？？**\n\n**Reimu: What?? Do you predict individual_id??** \n\n![https://4.bp.blogspot.com/-IMLly7zzfIk/Wn1ViNMu99I/AAAAAAABKDE/oTpDtyrZcTwGZLZAAtbeQ5PIn7ixnaaQgCLcBGAs/s400/bikkuri_me_tobideru_woman.png](https://4.bp.blogspot.com/-IMLly7zzfIk/Wn1ViNMu99I/AAAAAAABKDE/oTpDtyrZcTwGZLZAAtbeQ5PIn7ixnaaQgCLcBGAs/s400/bikkuri_me_tobideru_woman.png)\n\n**魔理沙:とりあえず、画像を表示しよう。**  \n\n**Marisa: Let's display the image for the time being.**　\n![https://4.bp.blogspot.com/-u0AiyPNqSsQ/VXOUoNjbfhI/AAAAAAAAuM8/R5H8c7jwcaE/s550/whale_09_minkukujira.png](https://4.bp.blogspot.com/-u0AiyPNqSsQ/VXOUoNjbfhI/AAAAAAAAuM8/R5H8c7jwcaE/s550/whale_09_minkukujira.png)","metadata":{}},{"cell_type":"code","source":"BASE_PATH = \"../input/happy-whale-and-dolphin/test_images/\"\nTEST_IMAGES = glob(BASE_PATH + \"*.jpg\")","metadata":{"execution":{"iopub.status.busy":"2022-03-09T11:48:22.224392Z","iopub.execute_input":"2022-03-09T11:48:22.22483Z","iopub.status.idle":"2022-03-09T11:48:23.239442Z","shell.execute_reply.started":"2022-03-09T11:48:22.224793Z","shell.execute_reply":"2022-03-09T11:48:23.238606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for x in range(5):\n    path = np.random.choice(TEST_IMAGES)\n    im = plt.imread(path)\n    plt.figure(figsize=(15, 6))\n    plt.imshow(im)\n    plt.title(path.split(\"/\")[-1])","metadata":{"execution":{"iopub.status.busy":"2022-03-09T11:59:19.210683Z","iopub.execute_input":"2022-03-09T11:59:19.211178Z","iopub.status.idle":"2022-03-09T11:59:26.643661Z","shell.execute_reply.started":"2022-03-09T11:59:19.211147Z","shell.execute_reply":"2022-03-09T11:59:26.642657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**魔理沙：最後にsample_submissionを見てみよう。**  \n\n**Marisa: Finally, let's take a look at sample_submission.**","metadata":{"id":"ImOk5OYoN9UL"}},{"cell_type":"markdown","source":"# sample_submission","metadata":{}},{"cell_type":"markdown","source":"sample_submission.csv-正しい形式のサンプル送信ファイル  \nテストセットのそれぞれについて、最大5つのラベルimageを予測できます。individual_idテストセットには、トレーニングデータに表示されていない個人がいます。これらはnew_individualとして予測する必要があります。  \n\nsample_submission.csv - a sample submission file in the correct format  \nFor each image in the test set, you may predict up to 5 individual_id labels. There are individuals in the test set that are not seen in the training data; these should be predicted as new_individual.","metadata":{}},{"cell_type":"markdown","source":"**魔理沙:評価方法は以下のURLに書いてあります。**\n\n**Marisa: The evaluation method is written at the following URL.**  \nhttps://www.kaggle.com/c/happy-whale-and-dolphin/overview/evaluation","metadata":{}},{"cell_type":"code","source":"sample_submission = pd.read_csv(\"../input/happy-whale-and-dolphin/sample_submission.csv\")\nsample_submission","metadata":{"id":"p0maxlzeOFem","execution":{"iopub.status.busy":"2022-03-09T11:48:25.143363Z","iopub.execute_input":"2022-03-09T11:48:25.14367Z","iopub.status.idle":"2022-03-09T11:48:25.211887Z","shell.execute_reply.started":"2022-03-09T11:48:25.143633Z","shell.execute_reply":"2022-03-09T11:48:25.211098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**霊夢:今回はここまでです。  \n魔理沙:最後までご覧いただきありがとうございました。**  \n\n**Reimu: That's all for this time.  \nMarisa: Thank you for watching until the end.**\n\n![https://3.bp.blogspot.com/-zz_dAx1CpKU/UZM42iiIytI/AAAAAAAASN0/bnGS3trtqGg/s400/byebye_girl.png](https://3.bp.blogspot.com/-zz_dAx1CpKU/UZM42iiIytI/AAAAAAAASN0/bnGS3trtqGg/s400/byebye_girl.png)","metadata":{}}]}