Skip to content

Commit d6cdb07

Browse files
committed
Initial commit
0 parents  commit d6cdb07

File tree

588 files changed

+1371
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

588 files changed

+1371
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "recovered-maker",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import pandas as pd\n",
11+
"import numpy as np\n",
12+
"import json"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": 11,
18+
"id": "enhanced-cursor",
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"class_map = json.load(open('../output/part_of_object/class_maps.json'))\n",
23+
"df = pd.DataFrame.from_records(list(map(json.loads, open('/mnt/nfs/home/leclerc/3db_output/details.log').readlines())))\n",
24+
"df = df.drop('render_args', axis=1).join(pd.DataFrame(df.render_args.values.tolist()))"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 41,
30+
"id": "transsexual-pathology",
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"labs = np.array([wnid_to_ind[x[1]] for x in json.load(open('labels.json'))['image_filenames']])"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 33,
40+
"id": "thermal-opening",
41+
"metadata": {},
42+
"outputs": [],
43+
"source": [
44+
"wnid_to_ind = {v[0]: int(k) for k, v in \\\n",
45+
" json.load(open('/data/theory/robustopt/datasets/imagenet_info/imagenet_class_index.json')).items()}"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": 108,
51+
"id": "eligible-cattle",
52+
"metadata": {},
53+
"outputs": [
54+
{
55+
"name": "stderr",
56+
"output_type": "stream",
57+
"text": [
58+
"<ipython-input-108-5fcd6045da9f>:2: FutureWarning: The default value of regex will change from True to False in a future version.\n",
59+
" grouped_df['model'] = grouped_df['model'].str.replace('.blend', '')\n"
60+
]
61+
}
62+
],
63+
"source": [
64+
"grouped_df = df.groupby('model').agg(acc=('is_correct', 'mean')).reset_index()\n",
65+
"grouped_df['model'] = grouped_df['model'].str.replace('.blend', '')\n",
66+
"grouped_df['class'] = \\\n",
67+
" grouped_df['model'].apply(json.load(open('/mnt/nfs/home/aiilyas/3db/3db/resources/ycb_to_IN.json')).get)\n",
68+
"grouped_df['class'] = grouped_df['class'].apply(lambda x: x[0])\n",
69+
"grouped_df['orig_acc'] = grouped_df['class'].apply( \\\n",
70+
" lambda x: (np.load('preds.npy')[:,0] == labs)[labs==x].mean()\n",
71+
")\n",
72+
"del grouped_df['class']\n",
73+
"grouped_df['model'] = grouped_df['model'].str.replace('_', ' ')\n",
74+
"grouped_df['model'] = grouped_df['model'].str.replace('\\d+', '', regex=True).str.strip()\n",
75+
"grouped_df = grouped_df.sort_values('model')\n",
76+
"grouped_df = grouped_df[~grouped_df['model'].isin(['strawberry', 'toygun', 'helmet'])]\n",
77+
"\n",
78+
"final_df_1 = grouped_df[:8].set_index('model').T\n",
79+
"final_df_1 = final_df_1.round(3) * 100\n",
80+
"\n",
81+
"final_df_2 = grouped_df[8:].set_index('model').T\n",
82+
"final_df_2 = final_df_2.round(3) * 100"
83+
]
84+
}
85+
],
86+
"metadata": {
87+
"kernelspec": {
88+
"display_name": "Python 3",
89+
"language": "python",
90+
"name": "python3"
91+
},
92+
"language_info": {
93+
"codemirror_mode": {
94+
"name": "ipython",
95+
"version": 3
96+
},
97+
"file_extension": ".py",
98+
"mimetype": "text/x-python",
99+
"name": "python",
100+
"nbconvert_exporter": "python",
101+
"pygments_lexer": "ipython3",
102+
"version": "3.8.5"
103+
}
104+
},
105+
"nbformat": 4,
106+
"nbformat_minor": 5
107+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "biological-islam",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import pandas as pd\n",
11+
"import numpy as np\n",
12+
"import json"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": 9,
18+
"id": "defined-nerve",
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"class_map = json.load(open('../output/backgrounds/class_maps.json'))\n",
23+
"df = pd.DataFrame.from_records(list(map(json.loads, open('../output/backgrounds/details.log').readlines())))\n",
24+
"df = df.drop('render_args', axis=1).join(pd.DataFrame(df.render_args.values.tolist()))\n",
25+
"df['prediction'] = df['prediction'].apply(lambda x: class_map[x[0]])\n",
26+
"df['is_correct'] = (df['is_correct'] == 'True')"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": null,
32+
"id": "about-garbage",
33+
"metadata": {},
34+
"outputs": [],
35+
"source": [
36+
"df.groupby('environment').agg(accuracy=('is_correct', 'mean'),\n",
37+
" most_frequent_prediction=('prediction', lambda x: x.mode()))"
38+
]
39+
}
40+
],
41+
"metadata": {
42+
"kernelspec": {
43+
"display_name": "Python 3",
44+
"language": "python",
45+
"name": "python3"
46+
},
47+
"language_info": {
48+
"codemirror_mode": {
49+
"name": "ipython",
50+
"version": 3
51+
},
52+
"file_extension": ".py",
53+
"mimetype": "text/x-python",
54+
"name": "python",
55+
"nbconvert_exporter": "python",
56+
"pygments_lexer": "ipython3",
57+
"version": "3.8.5"
58+
}
59+
},
60+
"nbformat": 4,
61+
"nbformat_minor": 5
62+
}

analysis/.ipynb_checkpoints/heatmaps-checkpoint.ipynb

Lines changed: 111 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 5,
6+
"id": "aboriginal-marshall",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import pandas as pd\n",
11+
"import numpy as np\n",
12+
"import json"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": 6,
18+
"id": "perceived-storage",
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"class_map = json.load(open('../output/texture_swaps/class_maps.json'))\n",
23+
"df = pd.DataFrame.from_records(list(map(json.loads, open('../output/texture_swaps/details.log').readlines())))\n",
24+
"df = df.drop('render_args', axis=1).join(pd.DataFrame(df.render_args.values.tolist()))\n",
25+
"df['prediction'] = df['prediction'].apply(lambda x: class_map[x[0]])\n",
26+
"df['is_correct'] = (df['is_correct'] == 'True')"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": 7,
32+
"id": "german-positive",
33+
"metadata": {},
34+
"outputs": [
35+
{
36+
"data": {
37+
"text/html": [
38+
"<div>\n",
39+
"<style scoped>\n",
40+
" .dataframe tbody tr th:only-of-type {\n",
41+
" vertical-align: middle;\n",
42+
" }\n",
43+
"\n",
44+
" .dataframe tbody tr th {\n",
45+
" vertical-align: top;\n",
46+
" }\n",
47+
"\n",
48+
" .dataframe thead th {\n",
49+
" text-align: right;\n",
50+
" }\n",
51+
"</style>\n",
52+
"<table border=\"1\" class=\"dataframe\">\n",
53+
" <thead>\n",
54+
" <tr style=\"text-align: right;\">\n",
55+
" <th></th>\n",
56+
" <th>accuracy</th>\n",
57+
" <th>most_frequent_prediction</th>\n",
58+
" </tr>\n",
59+
" <tr>\n",
60+
" <th>MaterialControl.replacement_material</th>\n",
61+
" <th></th>\n",
62+
" <th></th>\n",
63+
" </tr>\n",
64+
" </thead>\n",
65+
" <tbody>\n",
66+
" <tr>\n",
67+
" <th>cow.blend</th>\n",
68+
" <td>0.000000</td>\n",
69+
" <td>ashcan, trash can, garbage can, wastebin, ash ...</td>\n",
70+
" </tr>\n",
71+
" <tr>\n",
72+
" <th>crocodile.blend</th>\n",
73+
" <td>0.000000</td>\n",
74+
" <td>mortar</td>\n",
75+
" </tr>\n",
76+
" <tr>\n",
77+
" <th>elephant.blend</th>\n",
78+
" <td>0.000000</td>\n",
79+
" <td>shopping basket</td>\n",
80+
" </tr>\n",
81+
" <tr>\n",
82+
" <th>keep_original</th>\n",
83+
" <td>0.136364</td>\n",
84+
" <td>bucket, pail</td>\n",
85+
" </tr>\n",
86+
" <tr>\n",
87+
" <th>zebra.blend</th>\n",
88+
" <td>0.000000</td>\n",
89+
" <td>zebra</td>\n",
90+
" </tr>\n",
91+
" </tbody>\n",
92+
"</table>\n",
93+
"</div>"
94+
],
95+
"text/plain": [
96+
" accuracy \\\n",
97+
"MaterialControl.replacement_material \n",
98+
"cow.blend 0.000000 \n",
99+
"crocodile.blend 0.000000 \n",
100+
"elephant.blend 0.000000 \n",
101+
"keep_original 0.136364 \n",
102+
"zebra.blend 0.000000 \n",
103+
"\n",
104+
" most_frequent_prediction \n",
105+
"MaterialControl.replacement_material \n",
106+
"cow.blend ashcan, trash can, garbage can, wastebin, ash ... \n",
107+
"crocodile.blend mortar \n",
108+
"elephant.blend shopping basket \n",
109+
"keep_original bucket, pail \n",
110+
"zebra.blend zebra "
111+
]
112+
},
113+
"execution_count": 7,
114+
"metadata": {},
115+
"output_type": "execute_result"
116+
}
117+
],
118+
"source": [
119+
"df.groupby('MaterialControl.replacement_material').agg(accuracy=('is_correct', 'mean'),\n",
120+
" most_frequent_prediction=('prediction', lambda x: x.mode()))"
121+
]
122+
},
123+
{
124+
"cell_type": "code",
125+
"execution_count": null,
126+
"id": "becoming-market",
127+
"metadata": {},
128+
"outputs": [],
129+
"source": []
130+
}
131+
],
132+
"metadata": {
133+
"kernelspec": {
134+
"display_name": "Python 3",
135+
"language": "python",
136+
"name": "python3"
137+
},
138+
"language_info": {
139+
"codemirror_mode": {
140+
"name": "ipython",
141+
"version": 3
142+
},
143+
"file_extension": ".py",
144+
"mimetype": "text/x-python",
145+
"name": "python",
146+
"nbconvert_exporter": "python",
147+
"pygments_lexer": "ipython3",
148+
"version": "3.8.5"
149+
}
150+
},
151+
"nbformat": 4,
152+
"nbformat_minor": 5
153+
}

0 commit comments

Comments
 (0)