diff --git a/utils/viewer.ipynb b/utils/viewer.ipynb index b0e6f9c..2bd044a 100644 --- a/utils/viewer.ipynb +++ b/utils/viewer.ipynb @@ -614,6 +614,66 @@ } ], "metadata": {} + }, + { + "cell_type": "code", + "execution_count": null, + "source": [ + "def query_viz(query, n_rows, n_cols, image_mode = False):\n", + " items = [set() for _ in range(n_cols)]\n", + " if image_mode:\n", + " # image mode\n", + " else:\n", + " pick = query.groupby('category_id').sample(n_rows*2, replace=True)[['id', 'image_id', 'category_id', 'category_name', 'X', 'Y', 'W', 'H']].values.tolist()\n", + "\n", + " for obj in pick:\n", + " if len(items[obj[2]]) >= n_rows: continue\n", + " items[obj[2]].add(tuple(obj))\n", + " max_len = 0\n", + " for item in items:\n", + " max_len = max(max_len,len(item))\n", + "\n", + " fig, axes = plt.subplots(max_len, n_cols, sharex=False, sharey=False, figsize=(30, 32))\n", + " fig.suptitle(f\"{label_name}\", fontsize=28)\n", + "\n", + " for col in range(n_cols):\n", + " for row, (obj_id, img_id, label, name, x, y, w, h) in enumerate(items[col]):\n", + " y, x, h, w = int(x), int(y), int(w), int(h)\n", + " image, target, image_id = single_view_dataset[img_id]\n", + " if w > 1 and h > 1:\n", + " axes[row, col].imshow(image[x:x+w+1,y:y+h+1,:])\n", + " axes[row, col].set_title(f\"[{img_id:0>4d}.jpg/{obj_id}], [{h},{w}]\", fontsize=10)\n", + " # axes[row, col].set_title(f\"[{pick:0>4d}.jpg/{object_pick}] [{label}]{name} ({w},{h})\", fontsize=24)\n", + " axes[row, col].axis('off')\n", + "\n", + " plt.tight_layout(rect=[0, 0, 1, 0.97])\n", + " plt.show()" + ], + "outputs": [], + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": null, + "source": [ + "n_rows = 10\n", + "query = df[df['X'] < 5] \n", + "num_class = 10\n", + "query_viz(query, n_rows, num_class)" + ], + "outputs": [], + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": null, + "source": [ + "n_rows, num_class = 10, 10\n", + "query = df[(df['W'] < 10) & (df['W'] > 0)] \n", + "query_viz(query, n_rows, num_class)" + ], + "outputs": [], + "metadata": {} } ], "metadata": {