diff --git "a/notebooks/lilabc_test-ohio-small-animal.ipynb" "b/notebooks/lilabc_test-ohio-small-animal.ipynb" new file mode 100644--- /dev/null +++ "b/notebooks/lilabc_test-ohio-small-animal.ipynb" @@ -0,0 +1,2362 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import seaborn as sns\n", + "\n", + "sns.set_style(\"whitegrid\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Reading in our potential test sets from [here](https://huggingface.co/datasets/imageomics/lila-bc-camera/tree/d18307b285217d18b31d1a7b2c9091bb0873ade0/data/potential-test-sets):\n", + " - [Ohio Small Animals](https://lila.science/datasets/ohio-small-animals/)\n", + " - [Desert Lion Conservation Camera Traps](https://lila.science/datasets/desert-lion-conservation-camera-traps/)\n", + " - [Orinoquia Camera Traps](https://lila.science/datasets/orinoquia-camera-traps/)\n", + " - [Island Conservation Camera Traps](https://lila.science/datasets/island-conservation-camera-traps/)\n", + " - [ENA24](https://lila.science/datasets/ena24detection)\n", + "\n", + "We'll clean them down to just the taxa and identifier columns, then further reduce to make balanced test sets for each.\n", + "\n", + "# Ohio Small Animals Datasets\n", + "upper/lower bounded and balanced" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
dataset_nameurl_gcpurl_awsurl_azureimage_idsequence_idlocation_idframe_numoriginal_labelscientific_name...superfamilyfamilysubfamilytribegenusspeciessubspeciesvarietymulti_speciesnum_species
0Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA3N_sequence_...Ohio Small Animals : BIWA3N0american_bullfroglithobates catesbeianus...NaNranidaeNaNNaNlithobateslithobates catesbeianusNaNNaNFalse1.0
1Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA3N_sequence_...Ohio Small Animals : BIWA3N1american_bullfroglithobates catesbeianus...NaNranidaeNaNNaNlithobateslithobates catesbeianusNaNNaNFalse1.0
2Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA3N_sequence_...Ohio Small Animals : BIWA3N2american_bullfroglithobates catesbeianus...NaNranidaeNaNNaNlithobateslithobates catesbeianusNaNNaNFalse1.0
3Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA4N_sequence_...Ohio Small Animals : BIWA4N0american_bullfroglithobates catesbeianus...NaNranidaeNaNNaNlithobateslithobates catesbeianusNaNNaNFalse1.0
4Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA4N_sequence_...Ohio Small Animals : BIWA4N1american_bullfroglithobates catesbeianus...NaNranidaeNaNNaNlithobateslithobates catesbeianusNaNNaNFalse1.0
\n", + "

5 rows × 34 columns

\n", + "
" + ], + "text/plain": [ + " dataset_name url_gcp \\\n", + "0 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "1 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "2 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "3 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "4 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "\n", + " url_aws \\\n", + "0 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "1 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "2 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "3 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "4 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "\n", + " url_azure \\\n", + "0 https://lilawildlife.blob.core.windows.net/lil... \n", + "1 https://lilawildlife.blob.core.windows.net/lil... \n", + "2 https://lilawildlife.blob.core.windows.net/lil... \n", + "3 https://lilawildlife.blob.core.windows.net/lil... \n", + "4 https://lilawildlife.blob.core.windows.net/lil... \n", + "\n", + " image_id \\\n", + "0 Ohio Small Animals : Images/Sorted_by_species/... \n", + "1 Ohio Small Animals : Images/Sorted_by_species/... \n", + "2 Ohio Small Animals : Images/Sorted_by_species/... \n", + "3 Ohio Small Animals : Images/Sorted_by_species/... \n", + "4 Ohio Small Animals : Images/Sorted_by_species/... \n", + "\n", + " sequence_id \\\n", + "0 Ohio Small Animals : location_BIWA3N_sequence_... \n", + "1 Ohio Small Animals : location_BIWA3N_sequence_... \n", + "2 Ohio Small Animals : location_BIWA3N_sequence_... \n", + "3 Ohio Small Animals : location_BIWA4N_sequence_... \n", + "4 Ohio Small Animals : location_BIWA4N_sequence_... \n", + "\n", + " location_id frame_num original_label \\\n", + "0 Ohio Small Animals : BIWA3N 0 american_bullfrog \n", + "1 Ohio Small Animals : BIWA3N 1 american_bullfrog \n", + "2 Ohio Small Animals : BIWA3N 2 american_bullfrog \n", + "3 Ohio Small Animals : BIWA4N 0 american_bullfrog \n", + "4 Ohio Small Animals : BIWA4N 1 american_bullfrog \n", + "\n", + " scientific_name ... superfamily family subfamily tribe \\\n", + "0 lithobates catesbeianus ... NaN ranidae NaN NaN \n", + "1 lithobates catesbeianus ... NaN ranidae NaN NaN \n", + "2 lithobates catesbeianus ... NaN ranidae NaN NaN \n", + "3 lithobates catesbeianus ... NaN ranidae NaN NaN \n", + "4 lithobates catesbeianus ... NaN ranidae NaN NaN \n", + "\n", + " genus species subspecies variety multi_species \\\n", + "0 lithobates lithobates catesbeianus NaN NaN False \n", + "1 lithobates lithobates catesbeianus NaN NaN False \n", + "2 lithobates lithobates catesbeianus NaN NaN False \n", + "3 lithobates lithobates catesbeianus NaN NaN False \n", + "4 lithobates lithobates catesbeianus NaN NaN False \n", + "\n", + " num_species \n", + "0 1.0 \n", + "1 1.0 \n", + "2 1.0 \n", + "3 1.0 \n", + "4 1.0 \n", + "\n", + "[5 rows x 34 columns]" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df = pd.read_csv(\"../data/potential-test-sets/Ohio_Small_Animals_image_urls_and_labels.csv\", low_memory = False)\n", + "df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['dataset_name', 'url_gcp', 'url_aws', 'url_azure', 'image_id',\n", + " 'sequence_id', 'location_id', 'frame_num', 'original_label',\n", + " 'scientific_name', 'common_name', 'datetime', 'annotation_level',\n", + " 'kingdom', 'phylum', 'subphylum', 'superclass', 'class', 'subclass',\n", + " 'infraclass', 'superorder', 'order', 'suborder', 'infraorder',\n", + " 'superfamily', 'family', 'subfamily', 'tribe', 'genus', 'species',\n", + " 'subspecies', 'variety', 'multi_species', 'num_species'],\n", + " dtype='object')" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.columns" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Observe that we also now get multiple URL options; `url_aws` will likely be best/fastest for use with [`distributed-downloader`](https://github.com/Imageomics/distributed-downloader) to get the images." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 107106 entries, 0 to 107105\n", + "Data columns (total 34 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 dataset_name 107106 non-null object \n", + " 1 url_gcp 107106 non-null object \n", + " 2 url_aws 107106 non-null object \n", + " 3 url_azure 107106 non-null object \n", + " 4 image_id 107106 non-null object \n", + " 5 sequence_id 107106 non-null object \n", + " 6 location_id 107106 non-null object \n", + " 7 frame_num 107106 non-null int64 \n", + " 8 original_label 107106 non-null object \n", + " 9 scientific_name 107106 non-null object \n", + " 10 common_name 107106 non-null object \n", + " 11 datetime 107106 non-null object \n", + " 12 annotation_level 107106 non-null object \n", + " 13 kingdom 107106 non-null object \n", + " 14 phylum 102031 non-null object \n", + " 15 subphylum 102031 non-null object \n", + " 16 superclass 0 non-null float64\n", + " 17 class 102031 non-null object \n", + " 18 subclass 38900 non-null object \n", + " 19 infraclass 38900 non-null object \n", + " 20 superorder 37915 non-null object \n", + " 21 order 102031 non-null object \n", + " 22 suborder 67797 non-null object \n", + " 23 infraorder 0 non-null float64\n", + " 24 superfamily 26395 non-null object \n", + " 25 family 102031 non-null object \n", + " 26 subfamily 75088 non-null object \n", + " 27 tribe 31051 non-null object \n", + " 28 genus 102031 non-null object \n", + " 29 species 102031 non-null object \n", + " 30 subspecies 38087 non-null object \n", + " 31 variety 0 non-null float64\n", + " 32 multi_species 107106 non-null bool \n", + " 33 num_species 107106 non-null float64\n", + "dtypes: bool(1), float64(4), int64(1), object(28)\n", + "memory usage: 27.1+ MB\n" + ] + } + ], + "source": [ + "df.info(show_counts = True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is mostly filled in. Let's get some counts on the taxa, then start looking at balancing it." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "lin_taxa = ['kingdom', 'phylum', 'class', 'order', 'family', 'genus', 'species']\n", + "taxa_cols = ['original_label', 'scientific_name', 'common_name', 'kingdom', 'phylum', 'class', 'order', 'family', 'genus', 'species']" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "original_label 45\n", + "scientific_name 45\n", + "common_name 45\n", + "kingdom 1\n", + "phylum 1\n", + "class 4\n", + "order 10\n", + "family 25\n", + "genus 37\n", + "species 44\n", + "dtype: int64" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df[taxa_cols].nunique()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We only have 45--there's also null species values, so that'd be the distinction there.\n", + "\n", + "Also, should check for duplicated images." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "number of unique images: 107106\n" + ] + }, + { + "data": { + "text/plain": [ + "multi_species\n", + "False 107106\n", + "Name: count, dtype: int64" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "print(f\"number of unique images: {df[\"image_id\"].nunique()}\")\n", + "\n", + "df[\"multi_species\"].value_counts()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Okay, none of these have multiple species per image, so now let's look at how many images we have per species." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
dataset_nameurl_gcpurl_awsurl_azureimage_idsequence_idlocation_idframe_numoriginal_labelscientific_name...superfamilyfamilysubfamilytribegenusspeciessubspeciesvarietymulti_speciesnum_species
23682Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_GRN1_sequence_in...Ohio Small Animals : GRN11invertebrateanimalia...NaNNaNNaNNaNNaNNaNNaNNaNFalse1.0
24727Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_MLN3_sequence_in...Ohio Small Animals : MLN31invertebrateanimalia...NaNNaNNaNNaNNaNNaNNaNNaNFalse1.0
26630Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_WIL3_sequence_in...Ohio Small Animals : WIL30invertebrateanimalia...NaNNaNNaNNaNNaNNaNNaNNaNFalse1.0
26769Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_YWN1_sequence_in...Ohio Small Animals : YWN12invertebrateanimalia...NaNNaNNaNNaNNaNNaNNaNNaNFalse1.0
\n", + "

4 rows × 34 columns

\n", + "
" + ], + "text/plain": [ + " dataset_name url_gcp \\\n", + "23682 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "24727 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "26630 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "26769 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "\n", + " url_aws \\\n", + "23682 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "24727 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "26630 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "26769 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "\n", + " url_azure \\\n", + "23682 https://lilawildlife.blob.core.windows.net/lil... \n", + "24727 https://lilawildlife.blob.core.windows.net/lil... \n", + "26630 https://lilawildlife.blob.core.windows.net/lil... \n", + "26769 https://lilawildlife.blob.core.windows.net/lil... \n", + "\n", + " image_id \\\n", + "23682 Ohio Small Animals : Images/Sorted_by_species/... \n", + "24727 Ohio Small Animals : Images/Sorted_by_species/... \n", + "26630 Ohio Small Animals : Images/Sorted_by_species/... \n", + "26769 Ohio Small Animals : Images/Sorted_by_species/... \n", + "\n", + " sequence_id \\\n", + "23682 Ohio Small Animals : location_GRN1_sequence_in... \n", + "24727 Ohio Small Animals : location_MLN3_sequence_in... \n", + "26630 Ohio Small Animals : location_WIL3_sequence_in... \n", + "26769 Ohio Small Animals : location_YWN1_sequence_in... \n", + "\n", + " location_id frame_num original_label scientific_name \\\n", + "23682 Ohio Small Animals : GRN1 1 invertebrate animalia \n", + "24727 Ohio Small Animals : MLN3 1 invertebrate animalia \n", + "26630 Ohio Small Animals : WIL3 0 invertebrate animalia \n", + "26769 Ohio Small Animals : YWN1 2 invertebrate animalia \n", + "\n", + " ... superfamily family subfamily tribe genus species subspecies \\\n", + "23682 ... NaN NaN NaN NaN NaN NaN NaN \n", + "24727 ... NaN NaN NaN NaN NaN NaN NaN \n", + "26630 ... NaN NaN NaN NaN NaN NaN NaN \n", + "26769 ... NaN NaN NaN NaN NaN NaN NaN \n", + "\n", + " variety multi_species num_species \n", + "23682 NaN False 1.0 \n", + "24727 NaN False 1.0 \n", + "26630 NaN False 1.0 \n", + "26769 NaN False 1.0 \n", + "\n", + "[4 rows x 34 columns]" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.loc[df[\"species\"].isna()].sample(4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Ah, these are probably not images we want." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "scientific_name\n", + "thamnophis sirtalis sirtalis 31899\n", + "melospiza melodia 14567\n", + "microtus pennsylvanicus 14169\n", + "peromyscus leucopus 10548\n", + "troglodytes aedon aedon 5934\n", + "animalia 5075\n", + "plestiodon fasciatus 5045\n", + "sorex cinereus 4242\n", + "sylvilagus floridanus 3263\n", + "neogale frenata 2325\n", + "napaeozapus insignis 1510\n", + "thamnophis radix 1272\n", + "sistrurus catenatus 1189\n", + "didelphis virginiana 985\n", + "geothlypis trichas 802\n", + "Name: count, dtype: int64" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.scientific_name.value_counts()[:15]" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "scientific_name\n", + "pantherophis spiloides 68\n", + "heterodon platirhinos 67\n", + "procyon lotor 62\n", + "lithobates clamitans 47\n", + "marmota monax 44\n", + "clonophis kirtlandii 44\n", + "passerina cyanea 23\n", + "chrysemys picta 23\n", + "porzana carolina 13\n", + "lithobates catesbeianus 12\n", + "dumetella carolinensis 10\n", + "storeria occipitomaculata 9\n", + "rattus norvegicus 8\n", + "chelydra serpentina 6\n", + "sialia sialis 1\n", + "Name: count, dtype: int64" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.scientific_name.value_counts()[30:]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Looking at least-represented species:\n", + " - _lithobates catesbeianus_ isn't endangered itself, but is problematic for native species [USFWS Assessment](https://www.fws.gov/sites/default/files/documents/Ecological-Risk-Screening-Summary-American-Bullfrog.pdf), so worth testing on.\n", + " - _dumetella carolinensis_ listed as stable, least concern by [IUCN Redlist](https://www.iucnredlist.org/species/22711013/94272855), okay to exclude for balance.\n", + " - Similarly for _rattus norvegicus_ [IUCN](https://www.iucnredlist.org/species/19353/165118026), _chelydra serpentina_ is considered decreasing (still LC though) [IUCN](https://www.iucnredlist.org/species/163424/251347989), _sialia sialis_ increasing [IUCN](https://www.iucnredlist.org/species/22708550/139388955).\n", + " - _storeria occipitomaculata_ stable of least concern, though it \"needs updating\" [IUCN](https://www.iucnredlist.org/species/63930/12729296).\n", + "\n", + "So, for the balanced set we'll remove those that aren't classified beyond kingdom (all of which do have down to species), then randomly select 12 per species (to catch _lithobates catesbeianus_). That'd give us a 468 image test set (39 species at 12 images per species)." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmEAAAGwCAYAAADhf7JcAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8fJSN1AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAygElEQVR4nO3deViVdd7H8c8BUkBUzK1cSpsSRRFwzzXJFnHXyS53x1J73CbHSnOZLBpz1KxnzBSz0son28zGFpcWG3XMTBMxEQV3bdyyFAHRw+/5o4fzRCoCcvzBfd6v6/K64tznPuf74XfwfLrvm6PLGGMEAACA68rP9gAAAAC+iBIGAABgASUMAADAAkoYAACABZQwAAAACyhhAAAAFlDCAAAALAiwPQAuLzs7WxcvXpSfn59cLpftcQAAQD4YY5Sdna2AgAD5+eV9rIsSVkxdvHhRiYmJtscAAACFEBERoVKlSuV5H0pYMZXTnsPDw6+6iCWZ2+1WYmKiIiIi5O/vb3scryCjc/hCTjI6hy/kLI4Zc2a62lEwiRJWbOWcgvT39y82Lyxv8oWcZHQOX8hJRufwhZzFMWN+LiXiwnwAAAALKGEAAAAWUMIAAAAsoIQBAABYQAkDAACwgBIGAABgASUMAADAAkoYAACABZQwAAAACyhhAAAAFl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Ur1+//A9njIzxUvDiICecMTJy2Z3FW8joHEWQ0+12F+FARS9nvuI+57XwhYySb+QsjhkLMgslTFJmZqZGjBihP/3pT3K5XKpZs6buvfdebd++XWPHjtWAAQOUlpamkJAQrVq1Su3atVNISIgWLlyoli1bqn///pKkW2+9VUlJSVq8eLGaNGmiI0eOqH79+qpWrZpuvfVWLViwQOXKlSvQbBmZmUpLS/NG7GIl7dw52yN4HRmdozA504N/LW3JycnKyMgo6pGKXGJiou0RvM4XMkq+kbOkZqSESapcubK6d++uRYsWKSkpSSkpKUpOTlajRo0UFRWlypUr6+uvv1anTp20evVqPf7445KkvXv36quvvlJ0dLTnsS5cuKDatWtLkh5++GFNnDhRa9asUdu2bRUbG6vw8PACzRYUGKiQEAcfCjNGaefOKaRMGcnl0CMoZHSOa8gZHBwsSQoLC/PGZEXG7XYrMTFRERER8vf3tz2OV/hCRsk3chbHjDkz5QclTNKxY8fUq1cv1a9fXy1btlTv3r21du1aJSQkSJJiY2O1atUq3XrrrTp9+rTuuusuSdLFixfVpUsXPfLII7keLyDg129r165ddeedd+rzzz/X2rVrNWbMGA0dOlRjx47N/3Aul7Pf03JO6Tg4JxmdoyhyFpc3iqvx9/cvMbMWli9klHwjZ0nNyIX5ktasWaPy5csrPj5egwYNUpMmTXTo0CGZ/7v+o1OnTtqwYYNWrVqlmJgYBQUFSZJq166tAwcO6NZbb/X8+eKLL7RixQpJ0gsvvKBTp06pT58+io+P16OPPqrVq1dbywkAAIoPSpik0NBQHT16VBs3btShQ4e0YMECrV69WllZWZKkevXqqUqVKnrrrbfUsWNHz359+/bVjh079MILL2j//v1asWKFZs+erWrVqkn69XTlM888o127dmnPnj36+uuvC3w6EgAAOBMlTFLHjh3VtWtXjRkzRr169dKmTZs0fvx4paameopYbGys/P391bZtW89+1atX1/z587Vu3Tp17txZL774oiZMmKCuXbtKkqZOnapKlSppwIAB6t27t6pUqaJJkyZZyQgAAIoXlzGO/gCEEsvtdmvbtm368ECAUk6m2x7Ha4yR5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fdMTEyM5y+67Oxsc88995gPPvjAGGPM448/7vnhM8aYo0ePmrCwMHPw4EFjjDHt2rXz3NcYY5YvX27at2/vzSgee/bsMV27djVdunTJVU7+/e9/m6ioKM9fCsYYM2jQIPOPf/zDGGPMiy++mGvN0tPTTXR0tGf/vn37eu5rjDGbN282DRs2NOnp6VZeA1fKaYwxbdq0MevWrbvsfteydgcOHDB16tQxhw4d8myfOHFirscrKikpKaZOnTrmxIkTnttWrFhhWrdu7Zi1zCujMc5YR2OMOXbsmPnzn/9szp4967lt5MiR5qmnnnLMWuaV0RjnrKUxxpw+fdq0bdvW9OrVy/M83nzPsJExL5yOLGZ27dqlixcvKjo62nNb48aNlZCQcN1PwRVUamqqatWqdcntCQkJaty4seffwHS5XGrUqJG2bdvm2d6kSRPP/W+++WZVq1ZNCQkJOnbsmH788Uc1bdrUs71x48Y6cuSIjh8/7tU8kvTtt9+qefPmeueddy7JFB4eruDg4FxzXSlTUFCQ6tevr23btsntdisxMTHX9qioKF24cEG7du2y8hq4Us60tDQdO3bssusqXdvaJSQk6Oabb1aNGjVybf/++++LNpykypUra+HChapUqVKu29PS0hyzlnlldMo6SlKVKlX04osvKiQkRMYYbdmyRZs3b1azZs0cs5Z5ZXTSWkrS3//+d3Xr1k233357rgzees+wkTEvlLBi5sSJE6pQoUKuf3m9UqVKOn/+vH7++Wd7g12FMUb79u3T+vXrdd9996lDhw6aNWuWsrKydOLECVWpUiXX/StWrKj//Oc/kqTjx49fcfuJEyckKdf2nDeZnP29qW/fvpo4caKCgoJy3X61THltP3PmjM6fP59re0BAgEJDQz2Zr/dr4Eo5U1NT5XK5NH/+fLVt21Zdu3bVhx9+6Nl+LWt3pe/RsWPHijSbJJUrV05t2rTxfJ2dna233npLLVq0cMxa5pXRKev4ezExMerbt6+io6N13333OWYt88ropLXcuHGjvvvuO40YMSLX7d58z7D5er2cACvPiivKyMjI9UMuyfN1VlaWjZHy5ejRo57ZX3zxRR0+fFjPPvusMjMzr5gpJ09mZuYVt2dmZnq+/u02ye7342qZ8tp+uUy/3W6MKTavgb1798rlcum2225T//79tXnzZk2ZMkUhISG65557rmntrvY99KaZM2dq586dev/997Vo0SJHruVvM/7www+OXMd//OMfOnnypKZOnarnnnvOkT+Xv89Yv359R6zl+fPn9dRTT+mvf/2rAgMDc23z5nuGzdfr5VDCipnSpUtf8mLI+fr3L9TipHr16tq0aZPKly8vl8ulevXqKTs7W48//riaNWt22Uw5ea6UOSgoKNcPT+nSpT3/LemSozbXU+nSpS/5v9/8ZCpXrtwlOX67PSgoSG63u9i8Brp376727dsrNDRUklS3bl3t379fb7/9tu65555rWrsr7evtjDNnztTixYv1wgsvqE6dOo5cy99nvOOOOxy3jpIUEREh6dc39Mcee0y9evXK9duMv5+lJK7l7zNu3brVEWv50ksvqUGDBrmO3ua42hwlJWN+cDqymKlatapOnz6tixcvem47ceKEAgMDVa5cOYuTXV1oaKjnHL4k/eEPf9D58+dVuXJlnTx5Mtd9T5486TkkXLVq1ctur1y5sqpWrSpJnkPMv/3vypUreyVHflxp5vxkCg0NVenSpXNtv3jxon7++WdP5uLyGnC5XJ6/7HPcdtttnkP317J2ee3rLXFxcXr99dc1c+ZM3XfffXlmKKlrebmMTlrHkydP6vPPP8912+23364LFy5c0981xWkt88qYlpbmiLX85JNP9Pnnnys6OlrR0dFasWKFVqxYoejo6Gv6mSxOGfODElbM1KtXTwEBAZ4LECVpy5YtioiIkJ9f8V2udevWqXnz5rn+LzQpKUmhoaGeix6NMZJ+vX5s69atioyMlCRFRkZqy5Ytnv1+/PFH/fjjj4qMjFTVqlVVrVq1XNu3bNmiatWqXXJe/3qKjIzUDz/84Dn0nTPXlTJlZGRo586dioyMlJ+fnyIiInJt37ZtmwICAlS3bt1i9Rr47//+bw0ePDjXbbt27dJtt90m6drWLioqSkeOHMl1bd+WLVsUFRXllSwvvfSSli5dqtmzZ6tTp06e2520llfK6KR1PHz4sEaNGpXrGp4dO3boxhtvVOPGjR2xlnllfPPNNx2xlm+++aZWrFih5cu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gAAIAF/wv7RgHK9HH38gAAAABJRU5ErkJggg==", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "sns.histplot(df, y = 'class')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Filter Kingdom-only classifications" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Index: 102031 entries, 0 to 107105\n", + "Data columns (total 10 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 original_label 102031 non-null object\n", + " 1 scientific_name 102031 non-null object\n", + " 2 common_name 102031 non-null object\n", + " 3 kingdom 102031 non-null object\n", + " 4 phylum 102031 non-null object\n", + " 5 class 102031 non-null object\n", + " 6 order 102031 non-null object\n", + " 7 family 102031 non-null object\n", + " 8 genus 102031 non-null object\n", + " 9 species 102031 non-null object\n", + "dtypes: object(10)\n", + "memory usage: 8.6+ MB\n" + ] + } + ], + "source": [ + "df_filter = df.loc[df[\"species\"].notna()].copy()\n", + "df_filter[taxa_cols].info(show_counts=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_filter[\"subspecies\"].nunique()" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "subspecies\n", + "thamnophis sirtalis sirtalis 31899\n", + "troglodytes aedon aedon 5934\n", + "thamnophis saurita saurita 133\n", + "nerodia sipedon sipedon 121\n", + "Name: count, dtype: int64" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_filter[\"subspecies\"].value_counts()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "These are the representative subspecies of these species, so I don't think we'll consider the subspecies, especially since it's only labeled for a few. We can check if these species are in here without subspecies designations." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_filter.loc[(df_filter[\"species\"].isin([\"thamnophis sirtalis\", \"troglodytes aedon\", \"thamnophis saurita\", \"nerodia sipedon\"])) & (df_filter[\"subspecies\"].isna())].shape[0]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Yes, they're the only way these species are represented, so we can remove the subspecies." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Remove extra columns\n", + "\n", + "Only need `taxa_cols` (Linnean taxonomy + `original_label`, `scientific_name`, and `common_name`) and `id_cols`." + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "id_cols = ['dataset_name',\n", + " 'url_gcp',\n", + " 'url_aws',\n", + " 'url_azure',\n", + " 'image_id',\n", + " 'sequence_id',\n", + " 'location_id',\n", + " 'frame_num']\n", + "\n", + "cols_to_keep = [col for col in list(df.columns) if (col in id_cols or col in taxa_cols)]" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['dataset_name',\n", + " 'url_gcp',\n", + " 'url_aws',\n", + " 'url_azure',\n", + " 'image_id',\n", + " 'sequence_id',\n", + " 'location_id',\n", + " 'frame_num',\n", + " 'original_label',\n", + " 'scientific_name',\n", + " 'common_name',\n", + " 'kingdom',\n", + " 'phylum',\n", + " 'class',\n", + " 'order',\n", + " 'family',\n", + " 'genus',\n", + " 'species']" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cols_to_keep" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's add a number of images column (by `scientific_name`)." + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
dataset_nameurl_gcpurl_awsurl_azureimage_idsequence_idlocation_idframe_numoriginal_labelscientific_name...familysubfamilytribegenusspeciessubspeciesvarietymulti_speciesnum_speciesnum_sp_images
0Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA3N_sequence_...Ohio Small Animals : BIWA3N0american_bullfroglithobates catesbeianus...ranidaeNaNNaNlithobateslithobates catesbeianusNaNNaNFalse1.012.0
1Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA3N_sequence_...Ohio Small Animals : BIWA3N1american_bullfroglithobates catesbeianus...ranidaeNaNNaNlithobateslithobates catesbeianusNaNNaNFalse1.012.0
2Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA3N_sequence_...Ohio Small Animals : BIWA3N2american_bullfroglithobates catesbeianus...ranidaeNaNNaNlithobateslithobates catesbeianusNaNNaNFalse1.012.0
3Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA4N_sequence_...Ohio Small Animals : BIWA4N0american_bullfroglithobates catesbeianus...ranidaeNaNNaNlithobateslithobates catesbeianusNaNNaNFalse1.012.0
4Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA4N_sequence_...Ohio Small Animals : BIWA4N1american_bullfroglithobates catesbeianus...ranidaeNaNNaNlithobateslithobates catesbeianusNaNNaNFalse1.012.0
\n", + "

5 rows × 35 columns

\n", + "
" + ], + "text/plain": [ + " dataset_name url_gcp \\\n", + "0 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "1 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "2 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "3 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "4 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "\n", + " url_aws \\\n", + "0 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "1 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "2 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "3 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "4 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "\n", + " url_azure \\\n", + "0 https://lilawildlife.blob.core.windows.net/lil... \n", + "1 https://lilawildlife.blob.core.windows.net/lil... \n", + "2 https://lilawildlife.blob.core.windows.net/lil... \n", + "3 https://lilawildlife.blob.core.windows.net/lil... \n", + "4 https://lilawildlife.blob.core.windows.net/lil... \n", + "\n", + " image_id \\\n", + "0 Ohio Small Animals : Images/Sorted_by_species/... \n", + "1 Ohio Small Animals : Images/Sorted_by_species/... \n", + "2 Ohio Small Animals : Images/Sorted_by_species/... \n", + "3 Ohio Small Animals : Images/Sorted_by_species/... \n", + "4 Ohio Small Animals : Images/Sorted_by_species/... \n", + "\n", + " sequence_id \\\n", + "0 Ohio Small Animals : location_BIWA3N_sequence_... \n", + "1 Ohio Small Animals : location_BIWA3N_sequence_... \n", + "2 Ohio Small Animals : location_BIWA3N_sequence_... \n", + "3 Ohio Small Animals : location_BIWA4N_sequence_... \n", + "4 Ohio Small Animals : location_BIWA4N_sequence_... \n", + "\n", + " location_id frame_num original_label \\\n", + "0 Ohio Small Animals : BIWA3N 0 american_bullfrog \n", + "1 Ohio Small Animals : BIWA3N 1 american_bullfrog \n", + "2 Ohio Small Animals : BIWA3N 2 american_bullfrog \n", + "3 Ohio Small Animals : BIWA4N 0 american_bullfrog \n", + "4 Ohio Small Animals : BIWA4N 1 american_bullfrog \n", + "\n", + " scientific_name ... family subfamily tribe genus \\\n", + "0 lithobates catesbeianus ... ranidae NaN NaN lithobates \n", + "1 lithobates catesbeianus ... ranidae NaN NaN lithobates \n", + "2 lithobates catesbeianus ... ranidae NaN NaN lithobates \n", + "3 lithobates catesbeianus ... ranidae NaN NaN lithobates \n", + "4 lithobates catesbeianus ... ranidae NaN NaN lithobates \n", + "\n", + " species subspecies variety multi_species num_species \\\n", + "0 lithobates catesbeianus NaN NaN False 1.0 \n", + "1 lithobates catesbeianus NaN NaN False 1.0 \n", + "2 lithobates catesbeianus NaN NaN False 1.0 \n", + "3 lithobates catesbeianus NaN NaN False 1.0 \n", + "4 lithobates catesbeianus NaN NaN False 1.0 \n", + "\n", + " num_sp_images \n", + "0 12.0 \n", + "1 12.0 \n", + "2 12.0 \n", + "3 12.0 \n", + "4 12.0 \n", + "\n", + "[5 rows x 35 columns]" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "for sci_name in list(df_filter[\"scientific_name\"].unique()):\n", + " df_filter.loc[df_filter[\"scientific_name\"] == sci_name, \"num_sp_images\"] = df_filter.loc[df_filter[\"scientific_name\"] == sci_name].shape[0]\n", + "\n", + "df_filter.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [], + "source": [ + "cols_to_keep.append(\"num_sp_images\")" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
dataset_nameurl_gcpurl_awsurl_azureimage_idsequence_idlocation_idframe_numoriginal_labelscientific_namecommon_namekingdomphylumclassorderfamilygenusspeciesnum_sp_images
0Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA3N_sequence_...Ohio Small Animals : BIWA3N0american_bullfroglithobates catesbeianusamerican bullfroganimaliachordataamphibiaanuraranidaelithobateslithobates catesbeianus12.0
1Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA3N_sequence_...Ohio Small Animals : BIWA3N1american_bullfroglithobates catesbeianusamerican bullfroganimaliachordataamphibiaanuraranidaelithobateslithobates catesbeianus12.0
2Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA3N_sequence_...Ohio Small Animals : BIWA3N2american_bullfroglithobates catesbeianusamerican bullfroganimaliachordataamphibiaanuraranidaelithobateslithobates catesbeianus12.0
3Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA4N_sequence_...Ohio Small Animals : BIWA4N0american_bullfroglithobates catesbeianusamerican bullfroganimaliachordataamphibiaanuraranidaelithobateslithobates catesbeianus12.0
4Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA4N_sequence_...Ohio Small Animals : BIWA4N1american_bullfroglithobates catesbeianusamerican bullfroganimaliachordataamphibiaanuraranidaelithobateslithobates catesbeianus12.0
\n", + "
" + ], + "text/plain": [ + " dataset_name url_gcp \\\n", + "0 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "1 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "2 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "3 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "4 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "\n", + " url_aws \\\n", + "0 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "1 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "2 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "3 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "4 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "\n", + " url_azure \\\n", + "0 https://lilawildlife.blob.core.windows.net/lil... \n", + "1 https://lilawildlife.blob.core.windows.net/lil... \n", + "2 https://lilawildlife.blob.core.windows.net/lil... \n", + "3 https://lilawildlife.blob.core.windows.net/lil... \n", + "4 https://lilawildlife.blob.core.windows.net/lil... \n", + "\n", + " image_id \\\n", + "0 Ohio Small Animals : Images/Sorted_by_species/... \n", + "1 Ohio Small Animals : Images/Sorted_by_species/... \n", + "2 Ohio Small Animals : Images/Sorted_by_species/... \n", + "3 Ohio Small Animals : Images/Sorted_by_species/... \n", + "4 Ohio Small Animals : Images/Sorted_by_species/... \n", + "\n", + " sequence_id \\\n", + "0 Ohio Small Animals : location_BIWA3N_sequence_... \n", + "1 Ohio Small Animals : location_BIWA3N_sequence_... \n", + "2 Ohio Small Animals : location_BIWA3N_sequence_... \n", + "3 Ohio Small Animals : location_BIWA4N_sequence_... \n", + "4 Ohio Small Animals : location_BIWA4N_sequence_... \n", + "\n", + " location_id frame_num original_label \\\n", + "0 Ohio Small Animals : BIWA3N 0 american_bullfrog \n", + "1 Ohio Small Animals : BIWA3N 1 american_bullfrog \n", + "2 Ohio Small Animals : BIWA3N 2 american_bullfrog \n", + "3 Ohio Small Animals : BIWA4N 0 american_bullfrog \n", + "4 Ohio Small Animals : BIWA4N 1 american_bullfrog \n", + "\n", + " scientific_name common_name kingdom phylum class \\\n", + "0 lithobates catesbeianus american bullfrog animalia chordata amphibia \n", + "1 lithobates catesbeianus american bullfrog animalia chordata amphibia \n", + "2 lithobates catesbeianus american bullfrog animalia chordata amphibia \n", + "3 lithobates catesbeianus american bullfrog animalia chordata amphibia \n", + "4 lithobates catesbeianus american bullfrog animalia chordata amphibia \n", + "\n", + " order family genus species num_sp_images \n", + "0 anura ranidae lithobates lithobates catesbeianus 12.0 \n", + "1 anura ranidae lithobates lithobates catesbeianus 12.0 \n", + "2 anura ranidae lithobates lithobates catesbeianus 12.0 \n", + "3 anura ranidae lithobates lithobates catesbeianus 12.0 \n", + "4 anura ranidae lithobates lithobates catesbeianus 12.0 " + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_reduced = df_filter[cols_to_keep].copy()\n", + "df_reduced.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Reduce to no more than 10K images per species" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "30848\n" + ] + } + ], + "source": [ + "imgs_to_keep = list(df_reduced.loc[df_reduced[\"num_sp_images\"] <= 10000, \"image_id\"])\n", + "print(len(imgs_to_keep))" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "high_num_classes = list(df_reduced.loc[~df_reduced[\"image_id\"].isin(imgs_to_keep), \"scientific_name\"].unique())\n", + "len(high_num_classes)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "70848" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "for sci_name in high_num_classes:\n", + " sample_set = list(df_reduced.loc[df_reduced[\"scientific_name\"] == sci_name].sample(10000, random_state = 614)[\"image_id\"])\n", + " imgs_to_keep = imgs_to_keep + sample_set\n", + "\n", + "len(imgs_to_keep)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [], + "source": [ + "df_reduced_upper_bound = df_reduced.loc[df_reduced[\"image_id\"].isin(imgs_to_keep)].copy()\n", + "df_reduced_upper_bound.to_csv(\"../data/potential-test-sets/filtered/ohio-small-animals-upper-bound.csv\", index = False)" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "df_reduced_upper_lower = df_reduced_upper_bound.loc[df_reduced_upper_bound[\"num_sp_images\"] >= 10].copy()\n", + "df_reduced_upper_lower.to_csv(\"../data/potential-test-sets/filtered/ohio-small-animals-upper-lower-bound.csv\", index = False)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Randomly sample to balanced set (12 images per species)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "468" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "balanced_set = []\n", + "for sci_name in list(df_reduced[\"scientific_name\"].unique()):\n", + " temp = df_reduced.loc[df_reduced[\"scientific_name\"] == sci_name].copy()\n", + " if temp.shape[0] < 12:\n", + " continue\n", + " sample_set = list(temp.sample(12, random_state = 614)[\"image_id\"])\n", + " balanced_set = balanced_set + sample_set\n", + "\n", + "len(balanced_set)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Filter to just balanced set and drop the number of species column since it's been balanced to 12 each." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "df_balanced = df_reduced.loc[df_reduced[\"image_id\"].isin(balanced_set)].copy()\n", + "df_balanced.drop(columns = [\"num_sp_images\"], inplace = True)\n", + "df_balanced.to_csv(\"../data/potential-test-sets/filtered/ohio-small-animals-balanced.csv\", index = False)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Need to add unique filenames" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "df_reduced = pd.read_csv(\"../data/potential-test-sets/filtered/ohio-small-animals-upper-bound.csv\", low_memory=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'http://us-west-2.opendata.source.coop.s3.amazonaws.com/agentmorris/lila-wildlife/osu-small-animals/Images/Sorted_by_species/Amphibia/American Bullfrog/BIWA3N_2020-07-12_06-50-28.JPG'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_reduced.url_aws.values[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'https://lilawildlife.blob.core.windows.net/lila-wildlife/osu-small-animals/Images/Sorted_by_species/Amphibia/American Bullfrog/BIWA3N_2020-07-12_06-50-28.JPG'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_reduced.url_azure.values[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'BIWA3N_2020-07-12_06-50-28.JPG'" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_reduced.url_aws.values[0].split(\"/\")[-1]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "for img_id in list(df_reduced[\"image_id\"]):\n", + " url = df_reduced.loc[df_reduced[\"image_id\"] == img_id, \"url_aws\"].values[0]\n", + " df_reduced.loc[df_reduced[\"image_id\"] == img_id, \"filename\"] = \"OH_sm_animals_\" + url.split(\"/\")[-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Resave upper bound and upper-lower" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "df_reduced.to_csv(\"../data/potential-test-sets/filtered/ohio-small-animals-upper-bound.csv\", index = False)\n", + "df_reduced_upper_lower = df_reduced.loc[df_reduced[\"num_sp_images\"] >= 10].copy()\n", + "df_reduced_upper_lower.to_csv(\"../data/potential-test-sets/filtered/ohio-small-animals-upper-lower-bound.csv\", index = False)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Rerun the balanced set part as well." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## After download, duplicate images were detected\n", + "\n", + "Need to analyze and remove." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "df = pd.read_csv(\"../data/potential-test-sets/filtered/ohio-small-animals-upper-bound.csv\", low_memory=False)\n", + "df_checksums = pd.read_csv(\"../data/potential-test-sets/filtered/ohio-small-animals-upper-bound_checksums.csv\", low_memory=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "70848 70848\n", + "70848 filename 70848\n", + "md5 70836\n", + "dtype: int64\n" + ] + } + ], + "source": [ + "print(df.shape[0], df[\"filename\"].nunique())\n", + "print(df_checksums.shape[0], df_checksums[[\"filename\", \"md5\"]].nunique())" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(70848, 22)" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_full = pd.merge(df,\n", + " df_checksums,\n", + " on = \"filename\",\n", + " how = \"inner\"\n", + " )\n", + "df_full.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "scientific_name\n", + "coluber constrictor 12\n", + "thamnophis sirtalis sirtalis 10\n", + "peromyscus leucopus 1\n", + "napaeozapus insignis 1\n", + "Name: count, dtype: int64" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_full[\"dupe_img\"] = df_full.duplicated([\"md5\"], keep = False)\n", + "df_full.loc[df_full[\"dupe_img\"], \"scientific_name\"].value_counts()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Do these have conflicting labels?\n", + "\n", + "It would seem so, since [napaeozapus insignis](https://eol.org/pages/328468) and [peromyscus leucopus](https://eol.org/pages/310653) are quite similar in appearance (little brown mice)." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['58e0d98fdc5bbe326a0dfb0656b5910b',\n", + " '58e0d98fdc5bbe326a0dfb0656b5910b'], dtype=object)" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_full.loc[(df_full[\"dupe_img\"]) & (df_full[\"scientific_name\"].isin([\"napaeozapus insignis\", \"peromyscus leucopus\"])), \"md5\"].values" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['http://us-west-2.opendata.source.coop.s3.amazonaws.com/agentmorris/lila-wildlife/osu-small-animals/Images/Sorted_by_species/Mammalia/White-footed Mouse/YWS3_peromyscus_leucopus (37).JPG',\n", + " 'http://us-west-2.opendata.source.coop.s3.amazonaws.com/agentmorris/lila-wildlife/osu-small-animals/Images/Sorted_by_species/Mammalia/Woodland Jumping Mouse/YWS3_napaeozapus_insignis (5).JPG'],\n", + " dtype=object)" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_full.loc[(df_full[\"dupe_img\"]) & (df_full[\"scientific_name\"].isin([\"napaeozapus insignis\", \"peromyscus leucopus\"])), \"url_aws\"].values" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "scientific_name\n", + "peromyscus leucopus 10000\n", + "thamnophis sirtalis sirtalis 10000\n", + "napaeozapus insignis 1510\n", + "coluber constrictor 293\n", + "Name: count, dtype: int64" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "duplicated_sci_names = [\"coluber constrictor\",\n", + " \"thamnophis sirtalis sirtalis\",\n", + " \"peromyscus leucopus\",\n", + " \"napaeozapus insignis\"]\n", + "df_full.loc[df_full[\"scientific_name\"].isin(duplicated_sci_names), \"scientific_name\"].value_counts()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "They are all well-enough represented to still be in all datasets if we remove the duplicates. We'll drop both mice since we don't know which is the correct species classification ([image](http://us-west-2.opendata.source.coop.s3.amazonaws.com/agentmorris/lila-wildlife/osu-small-animals/Images/Sorted_by_species/Mammalia/White-footed%20Mouse/YWS3_peromyscus_leucopus%20(37).JPG) is basically a tail)." + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(70846, 23)" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_filter = df_full.loc[df_full[\"md5\"] != '58e0d98fdc5bbe326a0dfb0656b5910b'].copy()\n", + "df_filter.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(70835, 23)" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_filter[\"dupe_img\"] = df_filter.duplicated([\"md5\"], keep = \"first\")\n", + "df_reduced = df_filter.loc[~df_filter[\"dupe_img\"]].copy()\n", + "df_reduced.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['dataset_name', 'url_gcp', 'url_aws', 'url_azure', 'image_id',\n", + " 'sequence_id', 'location_id', 'frame_num', 'original_label',\n", + " 'scientific_name', 'common_name', 'kingdom', 'phylum', 'class', 'order',\n", + " 'family', 'genus', 'species', 'num_sp_images', 'filename', 'filepath',\n", + " 'md5', 'dupe_img'],\n", + " dtype='object')" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_reduced.columns" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Update Number of Species images counts" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "for sci_name in duplicated_sci_names:\n", + " df_reduced.loc[df_reduced[\"scientific_name\"] == sci_name, \"num_sp_images\"] = df_reduced.loc[df_reduced[\"scientific_name\"] == sci_name].shape[0]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Now save and reduce other two files\n", + "Don't need the `dupe_img` column." + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
dataset_nameurl_gcpurl_awsurl_azureimage_idsequence_idlocation_idframe_numoriginal_labelscientific_name...phylumclassorderfamilygenusspeciesnum_sp_imagesfilenamefilepathmd5
0Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA3N_sequence_...Ohio Small Animals : BIWA3N0american_bullfroglithobates catesbeianus...chordataamphibiaanuraranidaelithobateslithobates catesbeianus12.0OH_sm_animals_BIWA3N_2020-07-12_06-50-28.JPGohio-small-animals/lithobates catesbeianus/OH_...8dfcd2f7cf855b94c191baead05b904e
1Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA3N_sequence_...Ohio Small Animals : BIWA3N1american_bullfroglithobates catesbeianus...chordataamphibiaanuraranidaelithobateslithobates catesbeianus12.0OH_sm_animals_BIWA3N_2020-07-12_06-50-29.JPGohio-small-animals/lithobates catesbeianus/OH_...7fb71f74e311bcc59d12a6c1d3a5f564
2Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA3N_sequence_...Ohio Small Animals : BIWA3N2american_bullfroglithobates catesbeianus...chordataamphibiaanuraranidaelithobateslithobates catesbeianus12.0OH_sm_animals_BIWA3N_2020-07-12_06-50-30.JPGohio-small-animals/lithobates catesbeianus/OH_...599fd8843e098432bb1664c4366b4844
3Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA4N_sequence_...Ohio Small Animals : BIWA4N0american_bullfroglithobates catesbeianus...chordataamphibiaanuraranidaelithobateslithobates catesbeianus12.0OH_sm_animals_BIWA4N_2020-07-20_02-03-45.JPGohio-small-animals/lithobates catesbeianus/OH_...6f7e9e8c72d2bbd1af3118e6058f321f
4Ohio Small Animalshttps://storage.googleapis.com/public-datasets...http://us-west-2.opendata.source.coop.s3.amazo...https://lilawildlife.blob.core.windows.net/lil...Ohio Small Animals : Images/Sorted_by_species/...Ohio Small Animals : location_BIWA4N_sequence_...Ohio Small Animals : BIWA4N1american_bullfroglithobates catesbeianus...chordataamphibiaanuraranidaelithobateslithobates catesbeianus12.0OH_sm_animals_BIWA4N_2020-07-20_02-03-46.JPGohio-small-animals/lithobates catesbeianus/OH_...8e77e782f40299f3d202c48aa42d6be6
\n", + "

5 rows × 22 columns

\n", + "
" + ], + "text/plain": [ + " dataset_name url_gcp \\\n", + "0 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "1 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "2 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "3 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "4 Ohio Small Animals https://storage.googleapis.com/public-datasets... \n", + "\n", + " url_aws \\\n", + "0 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "1 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "2 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "3 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "4 http://us-west-2.opendata.source.coop.s3.amazo... \n", + "\n", + " url_azure \\\n", + "0 https://lilawildlife.blob.core.windows.net/lil... \n", + "1 https://lilawildlife.blob.core.windows.net/lil... \n", + "2 https://lilawildlife.blob.core.windows.net/lil... \n", + "3 https://lilawildlife.blob.core.windows.net/lil... \n", + "4 https://lilawildlife.blob.core.windows.net/lil... \n", + "\n", + " image_id \\\n", + "0 Ohio Small Animals : Images/Sorted_by_species/... \n", + "1 Ohio Small Animals : Images/Sorted_by_species/... \n", + "2 Ohio Small Animals : Images/Sorted_by_species/... \n", + "3 Ohio Small Animals : Images/Sorted_by_species/... \n", + "4 Ohio Small Animals : Images/Sorted_by_species/... \n", + "\n", + " sequence_id \\\n", + "0 Ohio Small Animals : location_BIWA3N_sequence_... \n", + "1 Ohio Small Animals : location_BIWA3N_sequence_... \n", + "2 Ohio Small Animals : location_BIWA3N_sequence_... \n", + "3 Ohio Small Animals : location_BIWA4N_sequence_... \n", + "4 Ohio Small Animals : location_BIWA4N_sequence_... \n", + "\n", + " location_id frame_num original_label \\\n", + "0 Ohio Small Animals : BIWA3N 0 american_bullfrog \n", + "1 Ohio Small Animals : BIWA3N 1 american_bullfrog \n", + "2 Ohio Small Animals : BIWA3N 2 american_bullfrog \n", + "3 Ohio Small Animals : BIWA4N 0 american_bullfrog \n", + "4 Ohio Small Animals : BIWA4N 1 american_bullfrog \n", + "\n", + " scientific_name ... phylum class order family \\\n", + "0 lithobates catesbeianus ... chordata amphibia anura ranidae \n", + "1 lithobates catesbeianus ... chordata amphibia anura ranidae \n", + "2 lithobates catesbeianus ... chordata amphibia anura ranidae \n", + "3 lithobates catesbeianus ... chordata amphibia anura ranidae \n", + "4 lithobates catesbeianus ... chordata amphibia anura ranidae \n", + "\n", + " genus species num_sp_images \\\n", + "0 lithobates lithobates catesbeianus 12.0 \n", + "1 lithobates lithobates catesbeianus 12.0 \n", + "2 lithobates lithobates catesbeianus 12.0 \n", + "3 lithobates lithobates catesbeianus 12.0 \n", + "4 lithobates lithobates catesbeianus 12.0 \n", + "\n", + " filename \\\n", + "0 OH_sm_animals_BIWA3N_2020-07-12_06-50-28.JPG \n", + "1 OH_sm_animals_BIWA3N_2020-07-12_06-50-29.JPG \n", + "2 OH_sm_animals_BIWA3N_2020-07-12_06-50-30.JPG \n", + "3 OH_sm_animals_BIWA4N_2020-07-20_02-03-45.JPG \n", + "4 OH_sm_animals_BIWA4N_2020-07-20_02-03-46.JPG \n", + "\n", + " filepath \\\n", + "0 ohio-small-animals/lithobates catesbeianus/OH_... \n", + "1 ohio-small-animals/lithobates catesbeianus/OH_... \n", + "2 ohio-small-animals/lithobates catesbeianus/OH_... \n", + "3 ohio-small-animals/lithobates catesbeianus/OH_... \n", + "4 ohio-small-animals/lithobates catesbeianus/OH_... \n", + "\n", + " md5 \n", + "0 8dfcd2f7cf855b94c191baead05b904e \n", + "1 7fb71f74e311bcc59d12a6c1d3a5f564 \n", + "2 599fd8843e098432bb1664c4366b4844 \n", + "3 6f7e9e8c72d2bbd1af3118e6058f321f \n", + "4 8e77e782f40299f3d202c48aa42d6be6 \n", + "\n", + "[5 rows x 22 columns]" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_reduced.drop(columns = [\"dupe_img\"], inplace=True)\n", + "df_reduced.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "df_reduced.to_csv(\"../data/potential-test-sets/filtered/ohio-small-animals-upper-bound.csv\", index = False)\n", + "df_reduced_upper_lower = df_reduced.loc[df_reduced[\"num_sp_images\"] >= 10].copy()\n", + "df_reduced_upper_lower.to_csv(\"../data/potential-test-sets/filtered/ohio-small-animals-upper-lower-bound.csv\", index = False)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "468" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "balanced_set = []\n", + "for sci_name in list(df_reduced[\"scientific_name\"].unique()):\n", + " temp = df_reduced.loc[df_reduced[\"scientific_name\"] == sci_name].copy()\n", + " if temp.shape[0] < 12:\n", + " continue\n", + " sample_set = list(temp.sample(12, random_state = 614)[\"image_id\"])\n", + " balanced_set = balanced_set + sample_set\n", + "\n", + "len(balanced_set)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [], + "source": [ + "df_balanced = df_reduced.loc[df_reduced[\"image_id\"].isin(balanced_set)].copy()\n", + "df_balanced.drop(columns = [\"num_sp_images\"], inplace = True)\n", + "df_balanced.to_csv(\"../data/potential-test-sets/filtered/ohio-small-animals-balanced.csv\", index = False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "jupytext": { + "formats": "ipynb,py:percent" + }, + "kernelspec": { + "display_name": "data-dev", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}