Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict patching to correct Run class #3015

Merged
merged 1 commit into from
May 12, 2023
Merged

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented May 12, 2023

The patch_XXX() utils needed to restrict to the appropriate Run class.

from bson import ObjectId, DBRef
import numpy as np

import fiftyone as fo
import fiftyone.brain as fob
import fiftyone.zoo as foz
import fiftyone.core.odm as foo

db = foo.get_db_conn()

dataset = foz.load_zoo_dataset("quickstart", max_samples=10)

dataset.evaluate_detections(
    "predictions",
    gt_field="ground_truth",
    eval_key="eval",
)

fob.compute_similarity(
    dataset,
    embeddings=np.random.randn(len(dataset), 12),
    brain_key="sim",
)

dataset.save_view("test", dataset.limit(10))

# Break some references
dataset_dict = db.datasets.find_one({"name": dataset.name})
dataset_dict["saved_views"] = [ObjectId()]
dataset_dict["evaluations"] = {"eval": ObjectId()}
dataset_dict["brain_methods"] = {"sim": ObjectId()}
db.datasets.replace_one({"name": dataset.name}, dataset_dict)

# Bad IDs present as DBRefs
dataset.reload()
assert isinstance(dataset._doc.saved_views[0], DBRef)
assert isinstance(dataset._doc.evaluations["eval"], DBRef)
assert isinstance(dataset._doc.brain_methods["sim"], DBRef)

foo.patch_saved_views(dataset.name)
# Purging 1 bad saved view ID(s) {ObjectId('645d8f018fdea805437ee4b3')} from dataset
# Adding 1 misplaced saved view(s) [(ObjectId('645d8f018fdea805437ee4b2'), 'test')] back to dataset

foo.patch_evaluations(dataset.name)
# Purging 1 evaluation(s) {('eval', ObjectId('645d8f018fdea805437ee4b4'))} from dataset
# Adding 1 misplaced evaluation(s) {('eval', ObjectId('645d8f018fdea805437ee4ac'))} to dataset

foo.patch_brain_runs(dataset.name)
# Purging 1 brain method run(s) {('sim', ObjectId('645d8f018fdea805437ee4b5'))} from dataset
# Adding 1 misplaced brain method run(s) {('sim', ObjectId('645d8f018fdea805437ee4af'))} to dataset

dataset.reload()
assert len(dataset.list_saved_views()) == 1
assert len(dataset.list_evaluations()) == 1
assert len(dataset.list_brain_runs()) == 1

@brimoor brimoor added the bug Bug fixes label May 12, 2023
@brimoor brimoor requested a review from a team May 12, 2023 00:59
@brimoor brimoor self-assigned this May 12, 2023
@brimoor brimoor merged commit 1bc48d3 into release/v0.21.0 May 12, 2023
@brimoor brimoor deleted the bugfix/patch-runs branch May 12, 2023 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants