{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 🧠 NOVA Benchmark: Extreme Stress-Test for Out-of-Distribution Detection in Brain MRI\n", "\n", "Welcome to the NOVA dataset — a carefully curated, evaluation-only benchmark designed to push the limits of machine learning models in real-world clinical scenarios. With over **900 brain MRI scans**, **281 rare pathologies**, and **rich clinical metadata**, NOVA goes beyond traditional anomaly detection.\n", "\n", "This notebook walks you through how to:\n", "\n", "- Load the NOVA dataset directly from Hugging Face 🤗\n", "- Access images, captions, and diagnostic metadata\n", "- Visualize expert-annotated bounding boxes (gold standard and raters)\n", "- Explore one of the most challenging testbeds for generalization and reasoning under uncertainty\n", "\n", "> ⚠️ This benchmark is intended **only for evaluation**. No training should be performed on NOVA.\n", "\n", "📘 For more details, visit the [dataset page on Hugging Face](https://huggingface.co/datasets/Ano-2090/Nova).\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib\n", "matplotlib.use('agg')\n", "import matplotlib.pyplot as plt\n", "import matplotlib.patches as patches\n", "from datasets import load_dataset\n", "import random" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Load dataset\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ds = load_dataset(\"Ano-2090/Nova\", trust_remote_code=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Select a random example\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "example = random.choice(ds[\"test\"])\n", "image = example[\"image\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create figure and display image\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(1, figsize=(8, 8))\n", "ax.imshow(image)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Plot gold standard bounding boxes (gold)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bbox = example[\"bbox_gold\"]\n", "for x, y, w, h in zip(bbox[\"x\"], bbox[\"y\"], bbox[\"width\"], bbox[\"height\"]):\n", " rect = patches.Rectangle((x, y), w, h, linewidth=2, edgecolor=\"gold\", facecolor=\"none\")\n", " ax.add_patch(rect)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Plot rater bounding boxes (turquoise, salmon) with labels\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "colors = ['#40E0D0', '#FA8072']\n", "raters = example[\"bbox_raters\"]\n", "if raters:\n", " for i in range(len(raters[\"x\"])):\n", " rater = raters[\"rater\"][i]\n", " x = raters[\"x\"][i]\n", " y = raters[\"y\"][i]\n", " w = raters[\"width\"][i]\n", " h = raters[\"height\"][i]\n", " rect = patches.Rectangle((x, y), w, h, linewidth=1.5, edgecolor=colors[i], facecolor=\"none\", linestyle=\"--\")\n", " ax.add_patch(rect)\n", " if i == 0:\n", " ax.text(x, y - 5, rater, color=colors[i], fontsize=8, weight=\"bold\", va=\"bottom\")\n", " else: \n", " ax.text(x + w/2, y + h + 15, rater, color=colors[i], fontsize=8, weight=\"bold\", va=\"bottom\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Visualize example\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.title(f'{example[\"filename\"]} — {example[\"final_diagnosis\"]}', fontsize=12)\n", "plt.axis(\"off\")\n", "plt.tight_layout()\n", "display(fig)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Print other metadata \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('*-------------------------------------------------------*')\n", "print('*-------------------------------------------------------*')\n", "print('caption:', example[\"caption\"])\n", "print('*-------------------------------------------------------*')\n", "print('clinical history:', example[\"clinical_history\"])\n", "print('*-------------------------------------------------------*')\n", "print('differential diagnosis:', example[\"differential_diagnosis\"])\n", "print('*-------------------------------------------------------*')\n", "print('final diagnosis:', example[\"final_diagnosis\"])\n", "print('*-------------------------------------------------------*')\n", "print('*-------------------------------------------------------*')" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 2 }