Skip to content

Commit

Permalink
Write code for generating submission file
Browse files Browse the repository at this point in the history
  • Loading branch information
ShabbirK committed Apr 30, 2019
1 parent e30af48 commit 199d06f
Show file tree
Hide file tree
Showing 25 changed files with 8,883 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ TN_TEST
credentials.json
token.pickle
*-temp*
TrackingNet/
TrackingNet/
submission_files/
118 changes: 118 additions & 0 deletions .ipynb_checkpoints/Prepare-Submission-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import json\n",
"import pathlib\n",
"from explore_dir import explore_dir"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cg_5uaJjLHk_0\n",
"cGwjfCPO-7k_0\n"
]
}
],
"source": [
"!ls TrackingNet/results/"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"files, dirs, _ = explore_dir('TrackingNet/results/')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['TrackingNet/results/cGwjfCPO-7k_0', 'TrackingNet/results/cg_5uaJjLHk_0']"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dirs"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"save_path = 'submission_files/'\n",
"pathlib.Path(save_path).mkdir(exist_ok=True, parents=True)\n",
"\n",
"for dir_path in dirs[:1]:\n",
" dname = dir_path.split('/')[-1]\n",
" files, _, _ = explore_dir(dir_path)\n",
" results_json = None\n",
" with open(files[0]) as f:\n",
" results_json = json.load(f)\n",
" \n",
" df = pd.DataFrame(data=results_json['res'])\n",
" df.to_csv(save_path + dname + \".txt\", index=False, header=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
6 changes: 6 additions & 0 deletions .ipynb_checkpoints/Small-Data-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
118 changes: 118 additions & 0 deletions Prepare-Submission.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import json\n",
"import pathlib\n",
"from explore_dir import explore_dir"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cg_5uaJjLHk_0\n",
"cGwjfCPO-7k_0\n"
]
}
],
"source": [
"!ls TrackingNet/results/"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"files, dirs, _ = explore_dir('TrackingNet/results/')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['TrackingNet/results/cGwjfCPO-7k_0', 'TrackingNet/results/cg_5uaJjLHk_0']"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dirs"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"save_path = 'submission_files/'\n",
"pathlib.Path(save_path).mkdir(exist_ok=True, parents=True)\n",
"\n",
"for dir_path in dirs[:1]:\n",
" dname = dir_path.split('/')[-1]\n",
" files, _, _ = explore_dir(dir_path)\n",
" results_json = None\n",
" with open(files[0]) as f:\n",
" results_json = json.load(f)\n",
" \n",
" df = pd.DataFrame(data=results_json['res'])\n",
" df.to_csv(save_path + dname + \".txt\", index=False, header=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
94 changes: 94 additions & 0 deletions Small-Data.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"anno_path = './csv_link/TRAIN_0_ANNO.csv'\n",
"zips_path = './csv_link/TRAIN_0_ZIPS.csv'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"anno_df = pd.read_csv(anno_path)\n",
"zips_df = pd.read_csv(zips_path)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"anno_df['id'] = anno_df['name'].str.replace('.txt', '')\n",
"zips_df['id'] = zips_df['name'].str.replace('.zip', '')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"combined_df = anno_df.merge(zips_df, on='id')"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"count = 10\n",
"anno_short_df = anno_df[anno_df['name'].isin(combined_df['name_x'][:count])][['name', 'link']]\n",
"zips_short_df = zips_df[zips_df['name'].isin(combined_df['name_y'][:count])][['name', 'link']]"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"anno_short_df.to_csv('./csv_link_short/TRAIN_0_ANNO.csv', index=False)\n",
"zips_short_df.to_csv('./csv_link_short/TRAIN_0_ZIPS.csv', index=False)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 199d06f

Please sign in to comment.