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

Fast sample parsing #117

Merged
merged 24 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/file_hashing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ We can poke around in the dataset:

```python
# Print summary information about the dataset
print(dataset.summary())
dataset

# Print a random sample
print(dataset.view().take(1).first())
Expand All @@ -80,7 +80,7 @@ Create a view that filters only `mountain`
view = dataset.view().match({"ground_truth.label": "mountain"})

# Print summary information about the view
print(view.summary())
view

# Print the first sample in the view
print(view.first())
Expand All @@ -91,7 +91,7 @@ Create a view that sorts labels reverse-alphabetically
```python
view = dataset.view().sort_by("ground_truth.label", reverse=True)

print(view.summary())
view
print(view.first())
```

Expand Down Expand Up @@ -139,7 +139,7 @@ for sample in dataset:
sample["file_hash"] = fou.compute_filehash(sample.filepath)
sample.save()

print(dataset.summary())
dataset
```

We have two ways to visualize this new information:
Expand Down
6 changes: 3 additions & 3 deletions fiftyone/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,8 @@ def ingest_images(
return cls.from_images(image_paths, name=name)

def _initialize_dataset(self, name):
# Create ODMDatasetSample subclass
self._sample_doc_cls = type(self._name, (foo.ODMDatasetSample,), {})
# Create ODMSample subclass
self._sample_doc_cls = type(self._name, (foo.ODMSample,), {})

# Create dataset meta document
self._meta = foo.ODMDataset(
Expand All @@ -946,7 +946,7 @@ def _load_dataset(self, name):
# pylint: disable=no-member
self._meta = foo.ODMDataset.objects.get(name=name)

self._sample_doc_cls = type(self._name, (foo.ODMDatasetSample,), {})
self._sample_doc_cls = type(self._name, (foo.ODMSample,), {})

num_default_fields = len(self.get_field_schema())

Expand Down
2 changes: 1 addition & 1 deletion fiftyone/core/odm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
from .database import drop_database
from .dataset import SampleField, ODMDataset
from .document import ODMDocument, ODMEmbeddedDocument
from .sample import ODMNoDatasetSample, ODMDatasetSample
from .sample import NoDatasetSample, ODMSample
9 changes: 6 additions & 3 deletions fiftyone/core/odm/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ def __copy__(self):
return self.copy()

def copy(self):
"""Returns a copy of the document that does not have its `id` set.
"""Returns a copy of the document.

Returns:
a :class:`SerializableDocument`
"""
doc = deepcopy(self)
return doc
return deepcopy(self)

def to_dict(self, extended=False):
"""Serializes this document to a JSON dictionary.
Expand All @@ -66,6 +65,7 @@ def to_dict(self, extended=False):
Returns:
a JSON dict
"""
# pylint: disable=no-member
if extended:
return json.loads(self.to_json())

Expand Down Expand Up @@ -98,6 +98,7 @@ def from_dict(cls, d, created=False, extended=False):
Returns:
a :class:`ODMDocument`
"""
# pylint: disable=no-member
if not extended:
try:
# Attempt to load the document directly, assuming it is in
Expand Down Expand Up @@ -162,11 +163,13 @@ def ingest_time(self):
"""The time the document was added to the database, or ``None`` if it
has not been added to the database.
"""
# pylint: disable=no-member
return self.id.generation_time if self.in_db else None

@property
def in_db(self):
"""Whether the underlying :class:`fiftyone.core.odm.ODMDocument` has
been inserted into the database.
"""
# pylint: disable=no-member
return hasattr(self, "id") and self.id is not None