File size: 5,476 Bytes
89a4a7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e11f4e7
 
89a4a7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e11f4e7
89a4a7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e11f4e7
89a4a7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
{
 "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
}