Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions analysis_CLIP.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -128,7 +128,7 @@
"genInput_dir = f\"{dataset_type}/train2\"\n",
"val_path = f\"{dataset_type}/val2\"\n",
"synth_path = f\"{dataset_type}/synthetic2\"\n",
"metadata_path = f\"{dataset_type}/metadata/analysis\" # create the metadata folder if it does not exist"
"metadata_path = f\"{dataset_type}/metadata/analysis\" # create the metadata folder if it does not exist"
]
},
{
Expand Down Expand Up @@ -240,7 +240,9 @@
"metadata": {},
"outputs": [],
"source": [
"clip_df.to_csv(f\"{metadata_path}/clip_analyze_{synth_path.replace('/','_')}.csv\", index=False)"
"clip_df.to_csv(\n",
" f\"{metadata_path}/clip_analyze_{synth_path.replace('/','_')}.csv\", index=False\n",
")"
]
},
{
Expand Down Expand Up @@ -321,7 +323,7 @@
],
"source": [
"# get base model class_to_idx\n",
"val2_path = f\"{dataset_type}/val\" # path to the full validation dataset that the classifier was tested on\n",
"val2_path = f\"{dataset_type}/val\" # path to the full validation dataset that the classifier was tested on\n",
"data.cacheValData(val2_path, \"imagenet2_val\", save_path=cache_path)\n",
"val2_dataset = data.loadData(\"imagenet2_val\", cache_path=cache_path)\n",
"base_class_to_idx = val2_dataset.class_to_idx\n",
Expand Down Expand Up @@ -967,11 +969,15 @@
},
{
"cell_type": "code",
"execution_count": 76,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"analysis.analyze_clf_stats(df, class_pairs=class_pairs, save_csv=f\"{metadata_path}/stats_clf_{synth_path.replace('/','_')}.csv\")"
"analysis.analyze_clf_stats(\n",
" df,\n",
" class_pairs=class_pairs,\n",
" save_csv=f\"{metadata_path}/stats_clf_{synth_path.replace('/','_')}.csv\",\n",
")"
]
},
{
Expand Down Expand Up @@ -1489,7 +1495,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1506,10 +1512,14 @@
" genInput_dir = f\"{combinations[ds]['dataset_type']}/train\"\n",
" val_path = f\"{combinations[ds]['dataset_type']}/val\"\n",
" synth_path = f\"{combinations[ds]['dataset_type']}/synthetic2{combinations[ds]['c']}\"\n",
" metadata_path = f\"{combinations[ds]['dataset_type']}/metadata/analysis{combinations[ds]['c']}\"\n",
" metadata_path = (\n",
" f\"{combinations[ds]['dataset_type']}/metadata/analysis{combinations[ds]['c']}\"\n",
" )\n",
" prompt_format = combinations[ds][\"prompt_format\"]\n",
"\n",
" df = pd.read_csv(f\"{metadata_path}/clip_clf_{synth_path.replace('/','_')}.csv\").copy()\n",
" df = pd.read_csv(\n",
" f\"{metadata_path}/clip_clf_{synth_path.replace('/','_')}.csv\"\n",
" ).copy()\n",
" classpairs = sorted(list(df[\"actual_class\"].unique()))\n",
" classnames = dict()\n",
" prompts = dict()\n",
Expand Down Expand Up @@ -1553,7 +1563,7 @@
" # main[\"Class\"].append(classnames[row[\"actual_class\"]])\n",
" # main[\"Prompt\"].append(prompts[row[\"actual_class\"]])\n",
" # main[\"CLIP Score to Prompt 1\"].append(row[\"sim_0\"])\n",
" # main[\"CLIP Score to Prompt 2\"].append(row[\"sim_1\"]) "
" # main[\"CLIP Score to Prompt 2\"].append(row[\"sim_1\"])"
]
},
{
Expand Down Expand Up @@ -1624,7 +1634,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -1650,7 +1660,9 @@
],
"source": [
"g = sns.FacetGrid(df_main, col=\"Type\", row=\"Dataset\", hue=\"Class\", sharex=False)\n",
"ax = g.map_dataframe(sns.kdeplot, x=\"CLIP Score to Prompt 1\", y=\"CLIP Score to Prompt 2\")\n",
"ax = g.map_dataframe(\n",
" sns.kdeplot, x=\"CLIP Score to Prompt 1\", y=\"CLIP Score to Prompt 2\"\n",
")\n",
"ax.set_titles(\"CLIP Score for {row_name}: {col_name}\")\n",
"ax.figure.legend(\n",
" loc=\"upper center\",\n",
Expand Down
24 changes: 12 additions & 12 deletions analysis_Classifier.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"wandb_results_dir = 'results/wandb'\n",
"output_dir = 'results'"
"wandb_results_dir = \"results/wandb\"\n",
"output_dir = \"results\""
]
},
{
Expand All @@ -69,16 +69,16 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dfs = dict()\n",
"for t in type:\n",
" fs = [f for f in files if t in f]\n",
" df = pd.concat([pd.read_csv(f'{wandb_results_dir}/' + f) for f in fs], axis=1)\n",
" df = pd.concat([pd.read_csv(f\"{wandb_results_dir}/\" + f) for f in fs], axis=1)\n",
" # drop columns if contain __MIN, __MAX, _step\n",
" df = df.drop([c for c in df.columns if '__MIN' in c], axis=1)\n",
" df = df.drop([c for c in df.columns if \"__MIN\" in c], axis=1)\n",
" df = df.drop([c for c in df.columns if \"__MAX\" in c], axis=1)\n",
" df = df.drop([c for c in df.columns if \"_step\" in c], axis=1)\n",
" # rename columns by replacing model names\n",
Expand All @@ -103,15 +103,15 @@
" \"epoch\": [],\n",
" }\n",
" for p in params:\n",
" pivot_dict[p.replace('epoch/','')] = []\n",
" pivot_dict[p.replace(\"epoch/\", \"\")] = []\n",
" for i, row in df.iterrows():\n",
" ep = row[\"epoch/epoch\"]\n",
" for m in models:\n",
" pivot_dict[\"type\"].append(t)\n",
" pivot_dict[\"model\"].append(m)\n",
" pivot_dict[\"epoch\"].append(ep)\n",
" for p in params:\n",
" param = p.replace('epoch/','')\n",
" param = p.replace(\"epoch/\", \"\")\n",
" pivot_dict[param].append(row[m + \" - \" + p])\n",
" pivot_df = pd.DataFrame(pivot_dict)\n",
" dfs[t] = pivot_df"
Expand Down Expand Up @@ -299,7 +299,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -376,14 +376,14 @@
}
],
"source": [
"df_plot['data'] = df_plot['model'].str.split('_').str[1]\n",
"df_plot[\"data\"] = df_plot[\"model\"].str.split(\"_\").str[1]\n",
"df_plot[\"model\"] = df_plot[\"model\"].str.split(\"_\").str[0]\n",
"df_plot.head(2)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -407,7 +407,7 @@
"g.add_legend()\n",
"g.set_titles(\"{row_name}: {col_name}\")\n",
"g.set_axis_labels(\"Epoch\", \"Accuracy@1\")\n",
"g.savefig(f'{output_dir}/merged_results.svg')"
"g.savefig(f\"{output_dir}/merged_results.svg\")"
]
},
{
Expand Down
Loading