Skip to content

Instantly share code, notes, and snippets.

View jacobmarks's full-sized avatar
🏗️
Building

Jacob Marks jacobmarks

🏗️
Building
View GitHub Profile
import fiftyone as fo
import fiftyone.utils.cvat as fouc
dataset = fo.Dataset("my-dataset")
fouc.import_annotations(
dataset,
task_ids=[...],
download_media=True,
)
view = dataset.match(
F("ground_truth.detections")
.filter(F("condition") == True)
.length() > 0
)
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")
@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)
# 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_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))
@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_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()
pred_conf_field = "predictions.detections.confidence"
pred_confs_jagged = dataset.values(pred_conf_field)
pred_conf_field = "predictions.detections.confidence"
pred_confs = dataset.values(pred_conf_field, unwind=True)