Anonymous commited on
Commit
89a4a7b
·
verified ·
1 Parent(s): 7fff8d1

Upload example.ipynb

Browse files
Files changed (1) hide show
  1. example.ipynb +187 -0
example.ipynb ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# 🧠 NOVA Benchmark: Extreme Stress-Test for Out-of-Distribution Detection in Brain MRI\n",
8
+ "\n",
9
+ "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",
10
+ "\n",
11
+ "This notebook walks you through how to:\n",
12
+ "\n",
13
+ "- Load the NOVA dataset directly from Hugging Face 🤗\n",
14
+ "- Access images, captions, and diagnostic metadata\n",
15
+ "- Visualize expert-annotated bounding boxes (gold standard and raters)\n",
16
+ "- Explore one of the most challenging testbeds for generalization and reasoning under uncertainty\n",
17
+ "\n",
18
+ "> ⚠️ This benchmark is intended **only for evaluation**. No training should be performed on NOVA.\n",
19
+ "\n",
20
+ "📘 For more details, visit the [dataset page on Hugging Face](https://huggingface.co/datasets/Ano-2090/Nova).\n"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": null,
26
+ "metadata": {},
27
+ "outputs": [],
28
+ "source": [
29
+ "import matplotlib.pyplot as plt\n",
30
+ "import matplotlib.patches as patches\n",
31
+ "from datasets import load_dataset\n",
32
+ "import random"
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "markdown",
37
+ "metadata": {},
38
+ "source": [
39
+ "### Load dataset\n"
40
+ ]
41
+ },
42
+ {
43
+ "cell_type": "code",
44
+ "execution_count": null,
45
+ "metadata": {},
46
+ "outputs": [],
47
+ "source": [
48
+ "ds = load_dataset(\"Ano-2090/Nova\")"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type": "markdown",
53
+ "metadata": {},
54
+ "source": [
55
+ "### Select a random example\n"
56
+ ]
57
+ },
58
+ {
59
+ "cell_type": "code",
60
+ "execution_count": null,
61
+ "metadata": {},
62
+ "outputs": [],
63
+ "source": [
64
+ "example = random.choice(ds[\"test\"])\n",
65
+ "image = example[\"image\"]"
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "markdown",
70
+ "metadata": {},
71
+ "source": [
72
+ "### Create figure and display image\n"
73
+ ]
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "execution_count": null,
78
+ "metadata": {},
79
+ "outputs": [],
80
+ "source": [
81
+ "fig, ax = plt.subplots(1, figsize=(8, 8))\n",
82
+ "ax.imshow(image)"
83
+ ]
84
+ },
85
+ {
86
+ "cell_type": "markdown",
87
+ "metadata": {},
88
+ "source": [
89
+ "### Plot gold standard bounding boxes (gold)\n"
90
+ ]
91
+ },
92
+ {
93
+ "cell_type": "code",
94
+ "execution_count": null,
95
+ "metadata": {},
96
+ "outputs": [],
97
+ "source": [
98
+ "bbox = example[\"bbox_gold\"]\n",
99
+ "for x, y, w, h in zip(bbox[\"x\"], bbox[\"y\"], bbox[\"width\"], bbox[\"height\"]):\n",
100
+ " rect = patches.Rectangle((x, y), w, h, linewidth=2, edgecolor=\"gold\", facecolor=\"none\")\n",
101
+ " ax.add_patch(rect)"
102
+ ]
103
+ },
104
+ {
105
+ "cell_type": "markdown",
106
+ "metadata": {},
107
+ "source": [
108
+ "### Plot rater bounding boxes (turquoise, salmon) with labels\n"
109
+ ]
110
+ },
111
+ {
112
+ "cell_type": "code",
113
+ "execution_count": null,
114
+ "metadata": {},
115
+ "outputs": [],
116
+ "source": [
117
+ "colors = ['#40E0D0', '#FA8072']\n",
118
+ "raters = example[\"bbox_raters\"]\n",
119
+ "if raters:\n",
120
+ " for i in range(len(raters[\"x\"])):\n",
121
+ " rater = raters[\"rater\"][i]\n",
122
+ " x = raters[\"x\"][i]\n",
123
+ " y = raters[\"y\"][i]\n",
124
+ " w = raters[\"width\"][i]\n",
125
+ " h = raters[\"height\"][i]\n",
126
+ " rect = patches.Rectangle((x, y), w, h, linewidth=1.5, edgecolor=colors[i], facecolor=\"none\", linestyle=\"--\")\n",
127
+ " ax.add_patch(rect)\n",
128
+ " if i == 0:\n",
129
+ " ax.text(x, y - 5, rater, color=colors[i], fontsize=8, weight=\"bold\", va=\"bottom\")\n",
130
+ " else: \n",
131
+ " ax.text(x + w/2, y + h + 15, rater, color=colors[i], fontsize=8, weight=\"bold\", va=\"bottom\")"
132
+ ]
133
+ },
134
+ {
135
+ "cell_type": "markdown",
136
+ "metadata": {},
137
+ "source": [
138
+ "### Visualize example\n"
139
+ ]
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "execution_count": null,
144
+ "metadata": {},
145
+ "outputs": [],
146
+ "source": [
147
+ "plt.title(f'{example[\"filename\"]} — {example[\"final_diagnosis\"]}', fontsize=12)\n",
148
+ "plt.axis(\"off\")\n",
149
+ "plt.tight_layout()\n",
150
+ "plt.show()"
151
+ ]
152
+ },
153
+ {
154
+ "cell_type": "markdown",
155
+ "metadata": {},
156
+ "source": [
157
+ "### Print other metadata \n"
158
+ ]
159
+ },
160
+ {
161
+ "cell_type": "code",
162
+ "execution_count": null,
163
+ "metadata": {},
164
+ "outputs": [],
165
+ "source": [
166
+ "print('*-------------------------------------------------------*')\n",
167
+ "print('*-------------------------------------------------------*')\n",
168
+ "print('caption:', example[\"caption\"])\n",
169
+ "print('*-------------------------------------------------------*')\n",
170
+ "print('clinical history:', example[\"clinical_history\"])\n",
171
+ "print('*-------------------------------------------------------*')\n",
172
+ "print('differential diagnosis:', example[\"differential_diagnosis\"])\n",
173
+ "print('*-------------------------------------------------------*')\n",
174
+ "print('final diagnosis:', example[\"final_diagnosis\"])\n",
175
+ "print('*-------------------------------------------------------*')\n",
176
+ "print('*-------------------------------------------------------*')"
177
+ ]
178
+ }
179
+ ],
180
+ "metadata": {
181
+ "language_info": {
182
+ "name": "python"
183
+ }
184
+ },
185
+ "nbformat": 4,
186
+ "nbformat_minor": 2
187
+ }