Created
March 21, 2023 19:26
-
-
Save jacobmarks/6b0c26b3771bf1d50fe19ca7c19de921 to your computer and use it in GitHub Desktop.
3D Detection Evaluation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] | |
for j in range(50): | |
gt_detections = [] | |
pred_detections = [] | |
point_cloud = [] | |
for _ in range(10): | |
dimensions = np.random.uniform([1, 1, 1], [3, 3, 3]) | |
location = np.random.uniform([-10, -10, 0], [10, 10, 10]) | |
rotation = np.random.uniform(-np.pi, np.pi, size=3) | |
conf = npr() | |
gt_detection = fo.Detection( | |
label = "dog", | |
dimensions=list(dimensions), | |
location=list(location), | |
rotation=list(rotation), | |
) | |
gt_detections.append(gt_detection) | |
pred_detection = fo.Detection( | |
label = "dog", | |
confidence=conf, | |
dimensions=list(dimensions + 0.3 * npr()), | |
location=list(location + 0.3 * npr()), | |
rotation=list(rotation + 0.3 * npr()), | |
) | |
if npr() > 0.2: | |
pred_detections.append(pred_detection) | |
R = o3d.geometry.get_rotation_matrix_from_xyz(rotation) | |
points = np.random.uniform(-dimensions / 2, dimensions / 2, size=(1000, 3)) | |
points = points @ R.T + location[np.newaxis, :] | |
point_cloud.extend(points) | |
pc = o3d.geometry.PointCloud() | |
pc.points = o3d.utility.Vector3dVector(np.array(point_cloud)) | |
o3d.io.write_point_cloud(f"/tmp/toy{j}.pcd", pc) | |
sample = fo.Sample( | |
filepath=f"/tmp/toy{j}.pcd", | |
ground_truth=fo.Detections(detections=gt_detections), | |
predictions=fo.Detections(detections=pred_detections), | |
) | |
samples.append(sample) | |
dataset = fo.Dataset("3d-eval", persistent = True) | |
dataset.add_samples(samples) | |
## set in-app visualization configuration | |
dataset.app_config.plugins["3d"] = { | |
"defaultCameraPosition": {"x": 0, "y": 0, "z": 20} | |
} | |
fo.launch_app(dataset) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment