Interactive Table
This notebook demonstrate how to use the interactive tables for debugging.
In [1]:
Copied!
from active_vision import ActiveLearner
al = ActiveLearner(name="cycle-1")
al.load_model(model="resnet18", pretrained=True)
from active_vision import ActiveLearner
al = ActiveLearner(name="cycle-1")
al.load_model(model="resnet18", pretrained=True)
2025-02-07 00:10:01.724 | INFO | active_vision.core:_detect_optimal_device:87 - CUDA GPU detected - will load model on GPU 2025-02-07 00:10:01.724 | INFO | active_vision.core:load_model:73 - Loading a pretrained timm model `resnet18` on `cuda`
In [2]:
Copied!
import pandas as pd
initial_samples = pd.read_parquet("initial_samples.parquet")
al.load_dataset(initial_samples, filepath_col="filepath", label_col="label")
import pandas as pd
initial_samples = pd.read_parquet("initial_samples.parquet")
al.load_dataset(initial_samples, filepath_col="filepath", label_col="label")
2025-02-07 00:10:01.745 | INFO | active_vision.core:load_dataset:125 - Loading dataset from `filepath` and `label` columns 2025-02-07 00:10:01.926 | INFO | active_vision.core:load_dataset:159 - Creating new learner 2025-02-07 00:10:02.776 | INFO | active_vision.core:_optimize_learner:100 - Enabled mixed precision training 2025-02-07 00:10:02.777 | INFO | active_vision.core:_finalize_setup:109 - Training set size: 80 2025-02-07 00:10:02.777 | INFO | active_vision.core:_finalize_setup:110 - Validation set size: 20 2025-02-07 00:10:02.777 | INFO | active_vision.core:_finalize_setup:111 - Done. Ready to train.
In [3]:
Copied!
al.show_batch()
al.show_batch()
In [4]:
Copied!
al.train(epochs=5, lr=5e-3)
al.train(epochs=5, lr=5e-3)
2025-02-07 00:10:03.324 | INFO | active_vision.core:train:213 - Training head for 1 epochs 2025-02-07 00:10:03.326 | INFO | active_vision.core:train:214 - Training model end-to-end for 5 epochs 2025-02-07 00:10:03.326 | INFO | active_vision.core:train:215 - Learning rate: 0.005 with one-cycle learning rate scheduler
epoch | train_loss | valid_loss | accuracy | time |
---|---|---|---|---|
0 | 3.224167 | 0.949572 | 0.650000 | 00:01 |
epoch | train_loss | valid_loss | accuracy | time |
---|---|---|---|---|
0 | 0.772945 | 0.642391 | 0.800000 | 00:01 |
1 | 0.567139 | 0.425224 | 0.900000 | 00:01 |
2 | 0.422784 | 0.411804 | 0.900000 | 00:01 |
3 | 0.342287 | 0.462382 | 0.900000 | 00:01 |
4 | 0.282525 | 0.486187 | 0.900000 | 00:01 |
In [5]:
Copied!
evaluation_df = pd.read_parquet("evaluation_samples.parquet")
evaluation_df
evaluation_df = pd.read_parquet("evaluation_samples.parquet")
evaluation_df
Out[5]:
filepath | label | |
---|---|---|
0 | data/imagenette/2/00000.jpg | cassette player |
1 | data/imagenette/2/00001.jpg | cassette player |
2 | data/imagenette/2/00002.jpg | cassette player |
3 | data/imagenette/2/00003.jpg | cassette player |
4 | data/imagenette/2/00004.jpg | cassette player |
... | ... | ... |
3920 | data/imagenette/5/03920.jpg | French horn |
3921 | data/imagenette/5/03921.jpg | French horn |
3922 | data/imagenette/5/03922.jpg | French horn |
3923 | data/imagenette/5/03923.jpg | French horn |
3924 | data/imagenette/5/03924.jpg | French horn |
3925 rows × 2 columns
In the following cell, we evaluate the model on the first 100 samples in the evaluation set.
To view the results in an interactive table, we set the interactive
parameter to True
. One benefit of this is that we can see the images in the table. Also you can sort the table by clicking on the column headers.
In [6]:
Copied!
eval_df = al.evaluate(
evaluation_df.head(100),
filepath_col="filepath",
label_col="label",
interactive=True,
)
eval_df = al.evaluate(
evaluation_df.head(100),
filepath_col="filepath",
label_col="label",
interactive=True,
)
2025-02-07 00:10:12.672 | INFO | active_vision.core:evaluate:317 - Accuracy: 95.00% 2025-02-07 00:10:12.673 | INFO | active_vision.core:evaluate:320 - Rendering interactive table
image | filepath | label | pred_label | pred_conf | loss |
---|---|---|---|---|---|
Loading ITables v2.2.4 from the internet... (need help?) |
In [7]:
Copied!
df = pd.read_parquet("unlabeled_samples.parquet")
filepaths = df["filepath"].tolist()
len(filepaths)
df = pd.read_parquet("unlabeled_samples.parquet")
filepaths = df["filepath"].tolist()
len(filepaths)
Out[7]:
9369
The same can be done for the predict method.
In [8]:
Copied!
pred_df = al.predict(filepaths[:1000], batch_size=128, interactive=True)
pred_df = al.predict(filepaths[:1000], batch_size=128, interactive=True)
2025-02-07 00:10:12.991 | INFO | active_vision.core:predict:224 - Running inference on 1000 samples
2025-02-07 00:10:14.598 | INFO | active_vision.core:predict:269 - Rendering interactive table
image | filepath | pred_label | pred_conf | logits | embeddings |
---|---|---|---|---|---|
Loading ITables v2.2.4 from the internet... (need help?) |