active-vision 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- active_vision/__init__.py +1 -1
- active_vision/core.py +173 -119
- {active_vision-0.1.0.dist-info → active_vision-0.1.1.dist-info}/METADATA +57 -72
- active_vision-0.1.1.dist-info/RECORD +7 -0
- active_vision-0.1.0.dist-info/RECORD +0 -7
- {active_vision-0.1.0.dist-info → active_vision-0.1.1.dist-info}/LICENSE +0 -0
- {active_vision-0.1.0.dist-info → active_vision-0.1.1.dist-info}/WHEEL +0 -0
- {active_vision-0.1.0.dist-info → active_vision-0.1.1.dist-info}/top_level.txt +0 -0
active_vision/__init__.py
CHANGED
active_vision/core.py
CHANGED
@@ -2,7 +2,6 @@ import pandas as pd
|
|
2
2
|
from loguru import logger
|
3
3
|
from fastai.vision.all import *
|
4
4
|
import torch
|
5
|
-
import torch.nn.functional as F
|
6
5
|
|
7
6
|
import warnings
|
8
7
|
from typing import Callable
|
@@ -142,7 +141,8 @@ class ActiveLearner:
|
|
142
141
|
{
|
143
142
|
"filepath": filepaths,
|
144
143
|
"pred_label": [self.learn.dls.vocab[i] for i in cls_preds.numpy()],
|
145
|
-
"pred_conf": torch.max(
|
144
|
+
"pred_conf": torch.max(preds, dim=1)[0].numpy(),
|
145
|
+
"pred_raw": preds.numpy().tolist(),
|
146
146
|
}
|
147
147
|
)
|
148
148
|
return self.pred_df
|
@@ -275,107 +275,132 @@ class ActiveLearner:
|
|
275
275
|
filepaths = df["filepath"].tolist()
|
276
276
|
|
277
277
|
with gr.Blocks(head=shortcut_js) as demo:
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
278
|
+
with gr.Tabs():
|
279
|
+
with gr.Tab("Labeling"):
|
280
|
+
current_index = gr.State(value=0)
|
281
|
+
|
282
|
+
with gr.Row(min_height=500):
|
283
|
+
image = gr.Image(
|
284
|
+
type="filepath",
|
285
|
+
label="Image",
|
286
|
+
value=filepaths[0],
|
287
|
+
height=500
|
288
|
+
)
|
288
289
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
290
|
+
# Add bar plot with top 5 predictions
|
291
|
+
with gr.Column():
|
292
|
+
pred_plot = gr.BarPlot(
|
293
|
+
x="probability",
|
294
|
+
y="class",
|
295
|
+
title="Top 5 Predictions",
|
296
|
+
x_lim=[0, 1],
|
297
|
+
value=None
|
298
|
+
if "pred_raw" not in df.columns
|
299
|
+
else pd.DataFrame(
|
300
|
+
{
|
301
|
+
"class": self.class_names,
|
302
|
+
"probability": df["pred_raw"].iloc[0],
|
303
|
+
}
|
304
|
+
).nlargest(5, "probability"),
|
305
|
+
)
|
306
|
+
|
307
|
+
filename = gr.Textbox(
|
308
|
+
label="Filename", value=filepaths[0], interactive=False
|
309
|
+
)
|
310
|
+
|
311
|
+
pred_label = gr.Textbox(
|
312
|
+
label="Predicted Label",
|
313
|
+
value=df["pred_label"].iloc[0]
|
314
|
+
if "pred_label" in df.columns
|
315
|
+
else "",
|
316
|
+
interactive=False,
|
317
|
+
)
|
318
|
+
pred_conf = gr.Textbox(
|
319
|
+
label="Confidence",
|
320
|
+
value=f"{df['pred_conf'].iloc[0]:.2%}"
|
321
|
+
if "pred_conf" in df.columns
|
322
|
+
else "",
|
323
|
+
interactive=False,
|
324
|
+
)
|
325
|
+
|
326
|
+
category = gr.Radio(
|
327
|
+
choices=self.class_names,
|
328
|
+
label="Select Category",
|
329
|
+
value=df["pred_label"].iloc[0]
|
330
|
+
if "pred_label" in df.columns
|
331
|
+
else None,
|
332
|
+
)
|
303
333
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
334
|
+
with gr.Row():
|
335
|
+
back_btn = gr.Button("← Previous", elem_id="back_btn")
|
336
|
+
submit_btn = gr.Button(
|
337
|
+
"Submit (↑/Enter)",
|
338
|
+
variant="primary",
|
339
|
+
elem_id="submit_btn",
|
340
|
+
)
|
341
|
+
next_btn = gr.Button("Next →", elem_id="next_btn")
|
309
342
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
)
|
318
|
-
next_btn = gr.Button("Next →", elem_id="next_btn")
|
319
|
-
|
320
|
-
progress = gr.Slider(
|
321
|
-
minimum=0,
|
322
|
-
maximum=len(filepaths) - 1,
|
323
|
-
value=0,
|
324
|
-
label="Progress",
|
325
|
-
interactive=False,
|
326
|
-
)
|
343
|
+
progress = gr.Slider(
|
344
|
+
minimum=0,
|
345
|
+
maximum=len(filepaths) - 1,
|
346
|
+
value=0,
|
347
|
+
label="Progress",
|
348
|
+
interactive=False,
|
349
|
+
)
|
327
350
|
|
328
|
-
|
351
|
+
finish_btn = gr.Button("Finish Labeling", variant="primary")
|
329
352
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
353
|
+
with gr.Tab("Zero-Shot Inference"):
|
354
|
+
gr.Markdown("""
|
355
|
+
Uses a VLM to predict the label of the image.
|
356
|
+
""")
|
334
357
|
|
335
|
-
|
336
|
-
|
337
|
-
|
358
|
+
import xinfer
|
359
|
+
from xinfer.model_registry import model_registry
|
360
|
+
from xinfer.types import ModelInputOutput
|
338
361
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
362
|
+
# Get models and filter for image-to-text models
|
363
|
+
all_models = model_registry.list_models()
|
364
|
+
model_list = [
|
365
|
+
model.id
|
366
|
+
for model in all_models
|
367
|
+
if model.input_output == ModelInputOutput.IMAGE_TEXT_TO_TEXT
|
368
|
+
]
|
346
369
|
|
347
|
-
with gr.Row():
|
348
370
|
with gr.Row():
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
371
|
+
with gr.Row():
|
372
|
+
model_dropdown = gr.Dropdown(
|
373
|
+
choices=model_list,
|
374
|
+
label="Select a model",
|
375
|
+
value="vikhyatk/moondream2",
|
376
|
+
)
|
377
|
+
device_dropdown = gr.Dropdown(
|
378
|
+
choices=["cuda", "cpu"],
|
379
|
+
label="Device",
|
380
|
+
value="cuda" if torch.cuda.is_available() else "cpu",
|
381
|
+
)
|
382
|
+
dtype_dropdown = gr.Dropdown(
|
383
|
+
choices=["float32", "float16", "bfloat16"],
|
384
|
+
label="Data Type",
|
385
|
+
value="float16"
|
386
|
+
if torch.cuda.is_available()
|
387
|
+
else "float32",
|
388
|
+
)
|
389
|
+
|
390
|
+
with gr.Column():
|
391
|
+
prompt_textbox = gr.Textbox(
|
392
|
+
label="Prompt",
|
393
|
+
lines=5,
|
394
|
+
value=f"Classify the image into one of the following categories: {self.class_names}. Answer with the category name only.",
|
395
|
+
interactive=True,
|
358
396
|
)
|
359
|
-
|
360
|
-
choices=["float32", "float16", "bfloat16"],
|
361
|
-
label="Data Type",
|
362
|
-
value="float16" if torch.cuda.is_available() else "float32",
|
363
|
-
)
|
364
|
-
|
365
|
-
with gr.Column():
|
366
|
-
prompt_textbox = gr.Textbox(
|
367
|
-
label="Prompt",
|
368
|
-
lines=3,
|
369
|
-
value=f"Classify the image into one of the following categories: {self.class_names}",
|
370
|
-
interactive=True,
|
371
|
-
)
|
372
|
-
inference_btn = gr.Button("Run Inference", variant="primary")
|
397
|
+
inference_btn = gr.Button("Run Inference", variant="primary")
|
373
398
|
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
399
|
+
result_textbox = gr.Textbox(
|
400
|
+
label="Result",
|
401
|
+
lines=3,
|
402
|
+
interactive=False,
|
403
|
+
)
|
379
404
|
|
380
405
|
def run_zero_shot_inference(prompt, model, device, dtype, current_filename):
|
381
406
|
model = xinfer.create_model(model, device=device, dtype=dtype)
|
@@ -407,6 +432,16 @@ class ActiveLearner:
|
|
407
432
|
next_idx = current_idx + direction
|
408
433
|
|
409
434
|
if 0 <= next_idx < len(filepaths):
|
435
|
+
plot_data = (
|
436
|
+
None
|
437
|
+
if "pred_raw" not in df.columns
|
438
|
+
else pd.DataFrame(
|
439
|
+
{
|
440
|
+
"class": self.class_names,
|
441
|
+
"probability": df["pred_raw"].iloc[next_idx],
|
442
|
+
}
|
443
|
+
).nlargest(5, "probability")
|
444
|
+
)
|
410
445
|
return (
|
411
446
|
filepaths[next_idx],
|
412
447
|
filepaths[next_idx],
|
@@ -421,7 +456,18 @@ class ActiveLearner:
|
|
421
456
|
else None,
|
422
457
|
next_idx,
|
423
458
|
next_idx,
|
459
|
+
plot_data,
|
424
460
|
)
|
461
|
+
plot_data = (
|
462
|
+
None
|
463
|
+
if "pred_raw" not in df.columns
|
464
|
+
else pd.DataFrame(
|
465
|
+
{
|
466
|
+
"class": self.class_names,
|
467
|
+
"probability": df["pred_raw"].iloc[current_idx],
|
468
|
+
}
|
469
|
+
).nlargest(5, "probability")
|
470
|
+
)
|
425
471
|
return (
|
426
472
|
filepaths[current_idx],
|
427
473
|
filepaths[current_idx],
|
@@ -436,6 +482,7 @@ class ActiveLearner:
|
|
436
482
|
else None,
|
437
483
|
current_idx,
|
438
484
|
current_idx,
|
485
|
+
plot_data,
|
439
486
|
)
|
440
487
|
|
441
488
|
def save_and_next(current_idx, selected_category):
|
@@ -443,20 +490,21 @@ class ActiveLearner:
|
|
443
490
|
current_idx = int(current_idx)
|
444
491
|
|
445
492
|
if selected_category is None:
|
493
|
+
plot_data = None if "pred_raw" not in df.columns else pd.DataFrame(
|
494
|
+
{
|
495
|
+
"class": self.class_names,
|
496
|
+
"probability": df["pred_raw"].iloc[current_idx],
|
497
|
+
}
|
498
|
+
).nlargest(5, "probability")
|
446
499
|
return (
|
447
500
|
filepaths[current_idx],
|
448
501
|
filepaths[current_idx],
|
449
|
-
df["pred_label"].iloc[current_idx]
|
450
|
-
if "
|
451
|
-
|
452
|
-
f"{df['pred_conf'].iloc[current_idx]:.2%}"
|
453
|
-
if "pred_conf" in df.columns
|
454
|
-
else "",
|
455
|
-
df["pred_label"].iloc[current_idx]
|
456
|
-
if "pred_label" in df.columns
|
457
|
-
else None,
|
502
|
+
df["pred_label"].iloc[current_idx] if "pred_label" in df.columns else "",
|
503
|
+
f"{df['pred_conf'].iloc[current_idx]:.2%}" if "pred_conf" in df.columns else "",
|
504
|
+
df["pred_label"].iloc[current_idx] if "pred_label" in df.columns else None,
|
458
505
|
current_idx,
|
459
506
|
current_idx,
|
507
|
+
plot_data,
|
460
508
|
)
|
461
509
|
|
462
510
|
# Save the current annotation
|
@@ -466,35 +514,38 @@ class ActiveLearner:
|
|
466
514
|
# Move to next image if not at the end
|
467
515
|
next_idx = current_idx + 1
|
468
516
|
if next_idx >= len(filepaths):
|
517
|
+
plot_data = None if "pred_raw" not in df.columns else pd.DataFrame(
|
518
|
+
{
|
519
|
+
"class": self.class_names,
|
520
|
+
"probability": df["pred_raw"].iloc[current_idx],
|
521
|
+
}
|
522
|
+
).nlargest(5, "probability")
|
469
523
|
return (
|
470
524
|
filepaths[current_idx],
|
471
525
|
filepaths[current_idx],
|
472
|
-
df["pred_label"].iloc[current_idx]
|
473
|
-
if "
|
474
|
-
|
475
|
-
f"{df['pred_conf'].iloc[current_idx]:.2%}"
|
476
|
-
if "pred_conf" in df.columns
|
477
|
-
else "",
|
478
|
-
df["pred_label"].iloc[current_idx]
|
479
|
-
if "pred_label" in df.columns
|
480
|
-
else None,
|
526
|
+
df["pred_label"].iloc[current_idx] if "pred_label" in df.columns else "",
|
527
|
+
f"{df['pred_conf'].iloc[current_idx]:.2%}" if "pred_conf" in df.columns else "",
|
528
|
+
df["pred_label"].iloc[current_idx] if "pred_label" in df.columns else None,
|
481
529
|
current_idx,
|
482
530
|
current_idx,
|
531
|
+
plot_data,
|
483
532
|
)
|
533
|
+
|
534
|
+
plot_data = None if "pred_raw" not in df.columns else pd.DataFrame(
|
535
|
+
{
|
536
|
+
"class": self.class_names,
|
537
|
+
"probability": df["pred_raw"].iloc[next_idx],
|
538
|
+
}
|
539
|
+
).nlargest(5, "probability")
|
484
540
|
return (
|
485
541
|
filepaths[next_idx],
|
486
542
|
filepaths[next_idx],
|
487
|
-
df["pred_label"].iloc[next_idx]
|
488
|
-
if "
|
489
|
-
|
490
|
-
f"{df['pred_conf'].iloc[next_idx]:.2%}"
|
491
|
-
if "pred_conf" in df.columns
|
492
|
-
else "",
|
493
|
-
df["pred_label"].iloc[next_idx]
|
494
|
-
if "pred_label" in df.columns
|
495
|
-
else None,
|
543
|
+
df["pred_label"].iloc[next_idx] if "pred_label" in df.columns else "",
|
544
|
+
f"{df['pred_conf'].iloc[next_idx]:.2%}" if "pred_conf" in df.columns else "",
|
545
|
+
df["pred_label"].iloc[next_idx] if "pred_label" in df.columns else None,
|
496
546
|
next_idx,
|
497
547
|
next_idx,
|
548
|
+
plot_data,
|
498
549
|
)
|
499
550
|
|
500
551
|
def convert_csv_to_parquet():
|
@@ -519,6 +570,7 @@ class ActiveLearner:
|
|
519
570
|
category,
|
520
571
|
current_index,
|
521
572
|
progress,
|
573
|
+
pred_plot,
|
522
574
|
],
|
523
575
|
)
|
524
576
|
|
@@ -533,6 +585,7 @@ class ActiveLearner:
|
|
533
585
|
category,
|
534
586
|
current_index,
|
535
587
|
progress,
|
588
|
+
pred_plot,
|
536
589
|
],
|
537
590
|
)
|
538
591
|
|
@@ -547,6 +600,7 @@ class ActiveLearner:
|
|
547
600
|
category,
|
548
601
|
current_index,
|
549
602
|
progress,
|
603
|
+
pred_plot,
|
550
604
|
],
|
551
605
|
)
|
552
606
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: active-vision
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.1
|
4
4
|
Summary: Active learning for edge vision.
|
5
5
|
Requires-Python: >=3.10
|
6
6
|
Description-Content-Type: text/markdown
|
@@ -71,17 +71,18 @@ cd active-vision
|
|
71
71
|
pip install -e .
|
72
72
|
```
|
73
73
|
|
74
|
-
I recommend using [uv](https://docs.astral.sh/uv/) to set up a virtual environment and install the package. You can also use other virtual env of your choice.
|
75
|
-
|
76
|
-
If you're using uv:
|
77
|
-
|
78
|
-
```bash
|
79
|
-
uv venv
|
80
|
-
uv sync
|
81
|
-
```
|
82
|
-
Once the virtual environment is created, you can install the package using pip.
|
83
74
|
|
84
75
|
> [!TIP]
|
76
|
+
> I recommend using [uv](https://docs.astral.sh/uv/) to set up a virtual environment and install the package. You can also use other virtual env of your choice.
|
77
|
+
>
|
78
|
+
> If you're using uv:
|
79
|
+
>
|
80
|
+
> ```bash
|
81
|
+
> uv venv
|
82
|
+
> uv sync
|
83
|
+
> ```
|
84
|
+
> Once the virtual environment is created, you can install the package using pip.
|
85
|
+
>
|
85
86
|
> If you're using uv add a `uv` before the pip install command to install into your virtual environment. Eg:
|
86
87
|
> ```bash
|
87
88
|
> uv pip install active-vision
|
@@ -120,12 +121,16 @@ pred_df = al.predict(filepaths)
|
|
120
121
|
# Sample low confidence predictions from unlabeled set
|
121
122
|
uncertain_df = al.sample_uncertain(pred_df, num_samples=10)
|
122
123
|
|
123
|
-
# Launch a Gradio UI to label the low confidence samples
|
124
|
+
# Launch a Gradio UI to label the low confidence samples, save the labeled samples to a file
|
124
125
|
al.label(uncertain_df, output_filename="uncertain")
|
125
126
|
```
|
126
127
|
|
127
128
|

|
128
129
|
|
130
|
+
In the UI, you can optionally run zero-shot inference on the image. This will use a VLM to predict the label of the image. There are a dozen VLM models as supported in the [x.infer project](https://github.com/dnth/x.infer).
|
131
|
+
|
132
|
+

|
133
|
+
|
129
134
|
Once complete, the labeled samples will be save into a new df.
|
130
135
|
We can now add the newly labeled data to the training set.
|
131
136
|
|
@@ -170,12 +175,12 @@ The active learning loop is a iterative process and can keep going until you hit
|
|
170
175
|
For this dataset,I decided to stop the active learning loop at 275 labeled images because the performance on the evaluation set is close to the top performing model on the leaderboard.
|
171
176
|
|
172
177
|
|
173
|
-
| #Labeled Images
|
174
|
-
|
175
|
-
| 9469
|
176
|
-
| 9469
|
177
|
-
| 275
|
178
|
-
| 275
|
178
|
+
| #Labeled Images | Evaluation Accuracy | Train Epochs | Model | Active Learning | Source |
|
179
|
+
|----------------: |--------------------: |-------------: |---------------------- |:---------------: |------------------------------------------------------------------------------------- |
|
180
|
+
| 9469 | 94.90% | 80 | xse_resnext50 | ❌ | [Link](https://github.com/fastai/imagenette) |
|
181
|
+
| 9469 | 95.11% | 200 | xse_resnext50 | ❌ | [Link](https://github.com/fastai/imagenette) |
|
182
|
+
| 275 | 99.33% | 6 | convnext_small_in22k | ✓ | [Link](https://github.com/dnth/active-vision/blob/main/nbs/05_retrain_larger.ipynb) |
|
183
|
+
| 275 | 93.40% | 4 | resnet18 | ✓ | [Link](https://github.com/dnth/active-vision/blob/main/nbs/04_relabel_loop.ipynb) |
|
179
184
|
|
180
185
|
### Dog Food
|
181
186
|
- num classes: 2
|
@@ -185,11 +190,11 @@ To start the active learning loop, I labeled 20 images (10 images from each clas
|
|
185
190
|
|
186
191
|
I decided to stop the active learning loop at 160 labeled images because the performance on the evaluation set is close to the top performing model on the leaderboard. You can decide your own stopping point based on your use case.
|
187
192
|
|
188
|
-
| #Labeled Images
|
189
|
-
|
190
|
-
| 2100
|
191
|
-
| 160
|
192
|
-
| 160
|
193
|
+
| #Labeled Images | Evaluation Accuracy | Train Epochs | Model | Active Learning | Source |
|
194
|
+
|----------------: |--------------------: |-------------: |---------------------- |:---------------: |--------------------------------------------------------------------------------------------- |
|
195
|
+
| 2100 | 99.70% | ? | vit-base-patch16-224 | ❌ | [Link](https://huggingface.co/abhishek/autotrain-dog-vs-food) |
|
196
|
+
| 160 | 100.00% | 6 | convnext_small_in22k | ✓ | [Link](https://github.com/dnth/active-vision/blob/main/nbs/dog_food_dataset/02_train.ipynb) |
|
197
|
+
| 160 | 97.60% | 4 | resnet18 | ✓ | [Link](https://github.com/dnth/active-vision/blob/main/nbs/dog_food_dataset/01_label.ipynb) |
|
193
198
|
|
194
199
|
### Oxford-IIIT Pet
|
195
200
|
- num classes: 37
|
@@ -199,13 +204,27 @@ To start the active learning loop, I labeled 370 images (10 images from each cla
|
|
199
204
|
|
200
205
|
I decided to stop the active learning loop at 612 labeled images because the performance on the evaluation set is close to the top performing model on the leaderboard. You can decide your own stopping point based on your use case.
|
201
206
|
|
202
|
-
| #Labeled Images
|
203
|
-
|
204
|
-
| 3680
|
205
|
-
| 612
|
206
|
-
| 612
|
207
|
+
| #Labeled Images | Evaluation Accuracy | Train Epochs | Model | Active Learning | Source |
|
208
|
+
|----------------: |--------------------: |-------------: |---------------------- |:---------------: |------------------------------------------------------------------------------------------------- |
|
209
|
+
| 3680 | 95.40% | 5 | vit-base-patch16-224 | ❌ | [Link](https://huggingface.co/walterg777/vit-base-oxford-iiit-pets) |
|
210
|
+
| 612 | 90.26% | 11 | convnext_small_in22k | ✓ | [Link](https://github.com/dnth/active-vision/blob/main/nbs/oxford_iiit_pets/02_train.ipynb) |
|
211
|
+
| 612 | 91.38% | 11 | vit-base-patch16-224 | ✓ | [Link](https://github.com/dnth/active-vision/blob/main/nbs/oxford_iiit_pets/03_train_vit.ipynb) |
|
212
|
+
|
213
|
+
### Eurosat RGB
|
214
|
+
- num classes: 10
|
215
|
+
- num images: 16100
|
216
|
+
|
217
|
+
To start the active learning loop, I labeled 100 images (10 images from each class) and iteratively labeled the most informative images until I hit 1188 labeled images.
|
218
|
+
|
219
|
+
I decided to stop the active learning loop at 1188 labeled images because the performance on the evaluation set is close to the top performing model on the leaderboard. You can decide your own stopping point based on your use case.
|
207
220
|
|
208
221
|
|
222
|
+
| #Labeled Images | Evaluation Accuracy | Train Epochs | Model | Active Learning | Source |
|
223
|
+
|----------------: |--------------------: |-------------: |---------------------- |:---------------: |-------------------------------------------------------------------------------------------- |
|
224
|
+
| 16100 | 98.55% | 6 | vit-base-patch16-224 | ❌ | [Link](https://github.com/dnth/active-vision/blob/main/nbs/eurosat_rgb/03_train_all.ipynb) |
|
225
|
+
| 1188 | 94.59% | 6 | vit-base-patch16-224 | ✓ | [Link](https://github.com/dnth/active-vision/blob/main/nbs/eurosat_rgb/02_train.ipynb) |
|
226
|
+
| 1188 | 96.57% | 13 | vit-base-patch16-224 | ✓ | [Link](https://github.com/dnth/active-vision/blob/main/nbs/eurosat_rgb/02_train.ipynb) |
|
227
|
+
|
209
228
|
|
210
229
|
## ➿ Workflow
|
211
230
|
This section describes a more detailed workflow for active learning. There are two workflows for active learning that we can use depending on the availability of labeled data.
|
@@ -273,55 +292,21 @@ graph TD
|
|
273
292
|
|
274
293
|
|
275
294
|
|
276
|
-
|
277
|
-
To test out the workflows we will use the [imagenette dataset](https://huggingface.co/datasets/frgfm/imagenette). But this will be applicable to any dataset.
|
278
|
-
|
279
|
-
Imagenette is a subset of the ImageNet dataset with 10 classes. We will use this dataset to test out the workflows. Additionally, Imagenette has an existing leaderboard which we can use to evaluate the performance of the models.
|
280
|
-
|
281
|
-
### Step 1: Download the dataset
|
282
|
-
Download the imagenette dataset. The imagenette dataset has a train and validation split. Since the leaderboard is based on the validation set, we will evalutate the performance of our model on the validation set to make it easier to compare to the leaderboard.
|
283
|
-
|
284
|
-
We will treat the imagenette train set as a unlabeled set and iteratively sample from it while monitoring the performance on the validation set. Ideally we will be able to get to a point where the performance on the validation set is close to the leaderboard with minimal number of labeled images.
|
295
|
+
## 🧱 Sampling Approaches
|
285
296
|
|
286
|
-
|
297
|
+
Recommendation 1:
|
298
|
+
- 10% randomly selected from unlabeled items.
|
299
|
+
- 80% selected from the lowest confidence items.
|
300
|
+
- 10% selected as outliers.
|
287
301
|
|
288
|
-
|
289
|
-
```python
|
290
|
-
from datasets import load_dataset
|
291
|
-
|
292
|
-
unlabeled_dataset = load_dataset("dnth/active-learning-imagenette", "unlabeled")
|
293
|
-
eval_dataset = load_dataset("dnth/active-learning-imagenette", "evaluation")
|
294
|
-
```
|
302
|
+
Recommendation 2:
|
295
303
|
|
296
|
-
|
297
|
-
|
304
|
+
- Sample 100 predicted images at 10–20% confidence.
|
305
|
+
- Sample 100 predicted images at 20–30% confidence.
|
306
|
+
- Sample 100 predicted images at 30–40% confidence, and so on.
|
298
307
|
|
299
|
-
### Step 3: Training the proxy model
|
300
|
-
Train a proxy model on the initial dataset. The proxy model will be a small model that is easy to train and deploy. We will use the fastai framework to train the model. We will use the resnet18 architecture as a starting point. Once training is complete, compute the accuracy of the proxy model on the validation set and compare it to the leaderboard.
|
301
308
|
|
302
|
-
|
303
|
-
> With the initial model we got 91.24% accuracy on the validation set. See the [notebook](./nbs/01_initial_sampling.ipynb) for more details.
|
304
|
-
> | Train Epochs | Number of Images | Validation Accuracy | Source |
|
305
|
-
> |--------------|-----------------|----------------------|------------------|
|
306
|
-
> | 10 | 100 | 91.24% | Initial sampling [notebook](./nbs/01_initial_sampling.ipynb) |
|
307
|
-
> | 80 | 9469 | 94.90% | fastai |
|
308
|
-
> | 200 | 9469 | 95.11% | fastai |
|
309
|
+
Uncertainty and diversity sampling are most effective when combined. For instance, you could first sample the most uncertain items using an uncertainty sampling method, then apply a diversity sampling method such as clustering to select a diverse set from the uncertain items.
|
309
310
|
|
311
|
+
Ultimately, the right ratios can depend on the specific task and dataset.
|
310
312
|
|
311
|
-
|
312
|
-
### Step 4: Inference on the unlabeled dataset
|
313
|
-
Run inference on the unlabeled dataset (the remaining imagenette train set) and evaluate the performance of the proxy model.
|
314
|
-
|
315
|
-
### Step 5: Active learning
|
316
|
-
Use active learning to select the most informative images to label from the unlabeled set. Pick the top 10 images from the unlabeled set that the proxy model is least confident about and label them.
|
317
|
-
|
318
|
-
### Step 6: Repeat
|
319
|
-
Repeat step 3 - 5 until the performance on the validation set is close to the leaderboard. Note the number of labeled images vs the performance on the validation set. Ideally we want to get to a point where the performance on the validation set is close to the leaderboard with minimal number of labeled images.
|
320
|
-
|
321
|
-
|
322
|
-
After the first iteration we got 94.57% accuracy on the validation set. See the [notebook](./nbs/03_retrain_model.ipynb) for more details.
|
323
|
-
|
324
|
-
> [!TIP]
|
325
|
-
> | Train Epochs | Number of Images | Validation Accuracy | Source |
|
326
|
-
> |--------------|-----------------|----------------------|------------------|
|
327
|
-
> | 10 | 200 | 94.57% | First relabeling [notebook](./nbs/03_retrain_model.ipynb) | -->
|
@@ -0,0 +1,7 @@
|
|
1
|
+
active_vision/__init__.py,sha256=xWa6YKvR3wF8p_D9PprKNGP3VnxjbyVpcwnPCMhhaHM,43
|
2
|
+
active_vision/core.py,sha256=jWzTOx3GCB2Sq5-JGgoi-ZD2teoIGTYas9StqZxXefo,24999
|
3
|
+
active_vision-0.1.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
4
|
+
active_vision-0.1.1.dist-info/METADATA,sha256=U8-IH0WJnPj6KPBsfsxcW4GZCTDY0KFxrqz7migcnro,15454
|
5
|
+
active_vision-0.1.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
6
|
+
active_vision-0.1.1.dist-info/top_level.txt,sha256=7qUQvccN2UU63z5S9vrgJmqK-8sFGrtpf1e9Z86nihE,14
|
7
|
+
active_vision-0.1.1.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
active_vision/__init__.py,sha256=dDQijes3C7zAUc_08TyblLSP6Lk0PcPPI8PYgEliKCI,43
|
2
|
-
active_vision/core.py,sha256=D_ve-nMv2EWSaQCOBTggleo-1op8JHXchk0QLicGDqg,21715
|
3
|
-
active_vision-0.1.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
4
|
-
active_vision-0.1.0.dist-info/METADATA,sha256=aA793OK3PGKnKVchMQthXl1H14xcBh_kq9tAO9o6jf0,15944
|
5
|
-
active_vision-0.1.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
6
|
-
active_vision-0.1.0.dist-info/top_level.txt,sha256=7qUQvccN2UU63z5S9vrgJmqK-8sFGrtpf1e9Z86nihE,14
|
7
|
-
active_vision-0.1.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|