Datasets:
remove checksum duplicates (incl. mislabel)
Browse filesOne image was duplicated with two different labels and both copies were removed
1 unmodified line23456781730 unmodified lines1739174017411742174317441 unmodified line"cells": [{"cell_type": "code","execution_count": 2,"metadata": {},"outputs": [],"source": [1730 unmodified lines"Rerun the balanced set part as well."]},{"cell_type": "code","execution_count": null,1 unmodified line23456781730 unmodified lines1739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123321 unmodified line"cells": [{"cell_type": "code","execution_count": 12,"metadata": {},"outputs": [],"source": [1730 unmodified lines"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": ["<div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>dataset_name</th>\n"," <th>url_gcp</th>\n"," <th>url_aws</th>\n"," <th>url_azure</th>\n"," <th>image_id</th>\n"," <th>sequence_id</th>\n"," <th>location_id</th>\n"," <th>frame_num</th>\n"," <th>original_label</th>\n"," <th>scientific_name</th>\n"," <th>...</th>\n"," <th>phylum</th>\n"," <th>class</th>\n"," <th>order</th>\n"," <th>family</th>\n"," <th>genus</th>\n"," <th>species</th>\n"," <th>num_sp_images</th>\n"," <th>filename</th>\n"," <th>filepath</th>\n"," <th>md5</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>Ohio Small Animals</td>\n"," <td>https://storage.googleapis.com/public-datasets...</td>\n"," <td>http://us-west-2.opendata.source.coop.s3.amazo...</td>\n"," <td>https://lilawildlife.blob.core.windows.net/lil...</td>\n"," <td>Ohio Small Animals : Images/Sorted_by_species/...</td>\n"," <td>Ohio Small Animals : location_BIWA3N_sequence_...</td>\n"," <td>Ohio Small Animals : BIWA3N</td>\n"," <td>0</td>\n"," <td>american_bullfrog</td>\n"," <td>lithobates catesbeianus</td>\n"," <td>...</td>\n"," <td>chordata</td>\n"," <td>amphibia</td>\n"," <td>anura</td>\n"," <td>ranidae</td>\n"," <td>lithobates</td>\n"," <td>lithobates catesbeianus</td>\n"," <td>12.0</td>\n"," <td>OH_sm_animals_BIWA3N_2020-07-12_06-50-28.JPG</td>\n"," <td>ohio-small-animals/lithobates catesbeianus/OH_...</td>\n"," <td>8dfcd2f7cf855b94c191baead05b904e</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>Ohio Small Animals</td>\n"," <td>https://storage.googleapis.com/public-datasets...</td>\n"," <td>http://us-west-2.opendata.source.coop.s3.amazo...</td>\n"," <td>https://lilawildlife.blob.core.windows.net/lil...</td>\n"," <td>Ohio Small Animals : Images/Sorted_by_species/...</td>\n"," <td>Ohio Small Animals : location_BIWA3N_sequence_...</td>\n"," <td>Ohio Small Animals : BIWA3N</td>\n"," <td>1</td>\n"," <td>american_bullfrog</td>\n"," <td>lithobates catesbeianus</td>\n"," <td>...</td>\n"," <td>chordata</td>\n"," <td>amphibia</td>\n"," <td>anura</td>\n"," <td>ranidae</td>\n"," <td>lithobates</td>\n"," <td>lithobates catesbeianus</td>\n"," <td>12.0</td>\n"," <td>OH_sm_animals_BIWA3N_2020-07-12_06-50-29.JPG</td>\n"," <td>ohio-small-animals/lithobates catesbeianus/OH_...</td>\n"," <td>7fb71f74e311bcc59d12a6c1d3a5f564</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>Ohio Small Animals</td>\n"," <td>https://storage.googleapis.com/public-datasets...</td>\n"," <td>http://us-west-2.opendata.source.coop.s3.amazo...</td>\n"," <td>https://lilawildlife.blob.core.windows.net/lil...</td>\n"," <td>Ohio Small Animals : Images/Sorted_by_species/...</td>\n"," <td>Ohio Small Animals : location_BIWA3N_sequence_...</td>\n"," <td>Ohio Small Animals : BIWA3N</td>\n"," <td>2</td>\n"," <td>american_bullfrog</td>\n"," <td>lithobates catesbeianus</td>\n"," <td>...</td>\n"," <td>chordata</td>\n"," <td>amphibia</td>\n"," <td>anura</td>\n"," <td>ranidae</td>\n"," <td>lithobates</td>\n"," <td>lithobates catesbeianus</td>\n"," <td>12.0</td>\n"," <td>OH_sm_animals_BIWA3N_2020-07-12_06-50-30.JPG</td>\n"," <td>ohio-small-animals/lithobates catesbeianus/OH_...</td>\n"," <td>599fd8843e098432bb1664c4366b4844</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>Ohio Small Animals</td>\n"," <td>https://storage.googleapis.com/public-datasets...</td>\n"," <td>http://us-west-2.opendata.source.coop.s3.amazo...</td>\n"," <td>https://lilawildlife.blob.core.windows.net/lil...</td>\n"," <td>Ohio Small Animals : Images/Sorted_by_species/...</td>\n"," <td>Ohio Small Animals : location_BIWA4N_sequence_...</td>\n"," <td>Ohio Small Animals : BIWA4N</td>\n"," <td>0</td>\n"," <td>american_bullfrog</td>\n"," <td>lithobates catesbeianus</td>\n"," <td>...</td>\n"," <td>chordata</td>\n"," <td>amphibia</td>\n"," <td>anura</td>\n"," <td>ranidae</td>\n"," <td>lithobates</td>\n"," <td>lithobates catesbeianus</td>\n"," <td>12.0</td>\n"," <td>OH_sm_animals_BIWA4N_2020-07-20_02-03-45.JPG</td>\n"," <td>ohio-small-animals/lithobates catesbeianus/OH_...</td>\n"," <td>6f7e9e8c72d2bbd1af3118e6058f321f</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>Ohio Small Animals</td>\n"," <td>https://storage.googleapis.com/public-datasets...</td>\n"," <td>http://us-west-2.opendata.source.coop.s3.amazo...</td>\n"," <td>https://lilawildlife.blob.core.windows.net/lil...</td>\n"," <td>Ohio Small Animals : Images/Sorted_by_species/...</td>\n"," <td>Ohio Small Animals : location_BIWA4N_sequence_...</td>\n"," <td>Ohio Small Animals : BIWA4N</td>\n"," <td>1</td>\n"," <td>american_bullfrog</td>\n"," <td>lithobates catesbeianus</td>\n"," <td>...</td>\n"," <td>chordata</td>\n"," <td>amphibia</td>\n"," <td>anura</td>\n"," <td>ranidae</td>\n"," <td>lithobates</td>\n"," <td>lithobates catesbeianus</td>\n"," <td>12.0</td>\n"," <td>OH_sm_animals_BIWA4N_2020-07-20_02-03-46.JPG</td>\n"," <td>ohio-small-animals/lithobates catesbeianus/OH_...</td>\n"," <td>8e77e782f40299f3d202c48aa42d6be6</td>\n"," </tr>\n"," </tbody>\n","</table>\n","<p>5 rows × 22 columns</p>\n","</div>"],"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,
notebooks/lilabc_test-ohio-small-animal.ipynb+589-1