Skip to content

Instantly share code, notes, and snippets.

View jacobmarks's full-sized avatar

Jacob Marks jacobmarks

View GitHub Profile
@jacobmarks
jacobmarks / dbscan_cluster_fiftyone.py
Created March 21, 2023 23:07
Add group slice with DBSCAN clustering colors to a grouped dataset in FiftyOne
import open3d as o3d
import matplotlib.pyplot as plt
import fiftyone.core.utils as fou
def add_cluster_samples(dataset, eps = 0.5, min_points = 500):
cluster_samples = []
dataset.group_slice = "pcd"
filepaths, groups = dataset.values(["filepath", "group"])
@jacobmarks
jacobmarks / evaluate_3d_detections.py
Created March 21, 2023 19:26
3D Detection Evaluation
import fiftyone as fo
from fiftyone import ViewField as F
import numpy as np
from numpy.random import random as npr
import open3d as o3d
samples = []
pred_conf_field = "predictions.detections.confidence"
pred_confs = dataset.values(pred_conf_field, unwind=True)
pred_conf_field = "predictions.detections.confidence"
pred_confs_jagged = dataset.values(pred_conf_field)
@jacobmarks
jacobmarks / 2022_11_25_classif_eval.py
Last active November 9, 2022 22:56
binary classification task evaluation
results = dataset.evaluate_classifications(
"predictions",
gt_field="ground_truth",
eval_key="eval",
method="binary",
classes=["classA", "classB"],
)
results.print_report()
@jacobmarks
jacobmarks / 2022_11_25_detection_eval.py
Last active November 9, 2022 22:56
multi-class detection task evaluation
results = dataset.evaluate_detections(
"predictions",
gt_field="ground_truth",
eval_key="eval",
compute_mAP=True,
)
# Get the 10 most common classes in the dataset
counts = dataset.count_values("ground_truth.detections.label")
classes_top10 = sorted(counts, key=counts.get, reverse=True)[:10]
@jacobmarks
jacobmarks / 2022_11_25_transform_field.py
Last active November 9, 2022 23:29
Aggregations on Transformed Field Values
## Option 1
aggregation = fo.Mean(F("predictions.detections.confidence") ** 2)
squared_conf_mean = dataset.aggregate(aggregation)
## Option 2
squared_conf_mean = dataset.mean(F("predictions.detections.confidence") ** 2))
# will count the number of samples in a dataset
sample_count = fo.Count()
# will retrieve the distinct labels in the `ground_truth` field
distinct_labels = fo.Distinct("ground_truth.detections.label")
# will compute a histogram of the `uniqueness` field
histogram_values = fo.HistogramValues("uniqueness")
# efficiently compute all three results
@jacobmarks
jacobmarks / 2022_11_25_mult_datasets.py
Last active November 9, 2022 23:28
One Aggregation; Multiple Datasets
mean_agg = fo.Mean("predictions.detections.confidence")
mean_value1 = dataset1.aggregate(mean)
mean_value2 = dataset2.aggregate(mean)
for batch in range(0, len(dataset), batch_size):
view = dataset[batch*batch_size : (batch+1) * batch_size]
results = view.annotate(..., backend="labelstudio", project_name="my_project")