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

3D Scene I/O optimization and bugfixes #4442

Merged
merged 9 commits into from
Jun 6, 2024
Merged

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented May 30, 2024

Change log

Optimizations

  • Added a cache to compute_metadata() to avoid recomputing metadata for repeated 3D asset paths

Bugfixes

  • Handle partial maps when updating Scene asset paths
    • Unit test added would previously fail but now succeeds as expected

Summary by CodeRabbit

  • New Features

    • Introduced include_assets parameter in various fo.Dataset methods to handle 3D scene assets.
    • Added download_scenes method to the fo.Dataset class.
  • Bug Fixes

    • Enhanced asset path handling in SceneMetadata and Scene classes to ensure correct path resolution and scene modification.
    • Updated Exporter class to handle different export modes based on self.export_mode.
  • Tests

    • Added test_update_asset_paths method to verify asset path updates in scenes.
    • Adjusted unit tests to align with new path handling logic.

@brimoor brimoor added the bug Bug fixes label May 30, 2024
Copy link
Contributor

coderabbitai bot commented May 30, 2024

Walkthrough

The updates span across several modules, focusing on enhancing the handling of 3D scene assets, refining path resolution logic, and improving metadata computation. Key changes include refactoring methods to include caching, updating path resolution functions, and adding new test cases to ensure functionality. Additionally, new parameters were introduced to handle 3D scene assets in various dataset operations.

Changes

Files/Modules Change Summary
fiftyone/core/metadata.py Refactored SceneMetadata class, added asset parsing and cache parameters in metadata functions.
fiftyone/core/storage.py Renamed resolve function to realpath with updated docstring.
fiftyone/core/threed/object_3d.py Simplified _get_asset_paths method and updated _asset_path_fields.
fiftyone/core/threed/scene_3d.py Modified asset path resolution and updating logic in the Scene class.
fiftyone/utils/data/exporters.py Removed export_mode parameter from _handle_fo3d_file method, adjusted logic for different export modes.
fiftyone/utils/utils3d.py Simplified asset path resolution in _get_scene_asset_paths_single function.
tests/unittests/metadata_tests.py Adjusted file paths and comparison logic in test_build_for method.
tests/unittests/utils3d_tests.py Removed os.path.realpath calls in test_get_scene_asset_paths function.
tests/unittests/threed/scene_3d_tests.py Added test_update_asset_paths method to verify updated asset paths in a scene object.
docs/source/teams/cloud_media.rst Added include_assets parameter to various fo.Dataset methods for handling 3D scene assets.

Sequence Diagram(s) (Beta)

No sequence diagrams are necessary for these changes.

Poem

In the land of code, where data flows,
A rabbit sings as it goes.
Paths resolved, scenes refined,
Metadata cached, all aligned.
Export modes dance, assets in tow,
Fiftyone's magic, watch it grow! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d7a6e0d and 50943b9.

Files selected for processing (3)
  • fiftyone/core/threed/object_3d.py (3 hunks)
  • fiftyone/core/threed/scene_3d.py (2 hunks)
  • tests/unittests/threed/scene_3d_tests.py (1 hunks)
Additional comments not posted (4)
tests/unittests/threed/scene_3d_tests.py (1)

74-102: The new unit test test_update_asset_paths effectively checks the functionality of updating asset paths in a scene object. It's good to see that the test covers various types of asset paths, including relative paths and specific file types. This should help ensure that the asset path update logic handles different scenarios correctly.

fiftyone/core/threed/object_3d.py (2)

Line range hint 29-40: The change in the Object3D class to inherit from object and the simplification of the _asset_path_fields to an empty list are both straightforward and align with the PR's objective to simplify asset path management. This should reduce complexity and potential errors in asset path handling.


230-230: The _get_asset_paths method has been simplified due to the empty _asset_path_fields. This change should improve performance slightly by reducing unnecessary attribute checks and method calls.

fiftyone/core/threed/scene_3d.py (1)

189-189: The updates to the Scene class to handle asset path updates more robustly are well-implemented. The method update_asset_paths now correctly handles both the scene's assets and the background assets, ensuring that all paths are updated as specified. This is crucial for maintaining consistency and correctness when asset paths are changed.
[APROVED]

Also applies to: 279-279, 287-290, 296-296

@brimoor brimoor changed the title Handle partial maps when updating Scene asset paths 3D Scene I/O optimization and bugfixes Jun 3, 2024
@findtopher
Copy link
Member

should this be targeting release/v0.24.1 to go out with release/v1.7.1 or is this a develop-only bug?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Outside diff range and nitpick comments (12)
fiftyone/core/storage.py (3)

Line range hint 8-8: Remove unused import.

The contextlib.contextmanager is imported but not used in this file. Removing unused imports can help reduce the file size and improve load time.

- from contextlib import contextmanager

285-286: Clarify the documentation for path resolution.

The documentation for the resolve function could be enhanced by specifying what types of symlinks and relative paths are resolved. This would provide clearer guidance to users on how the function behaves.


Line range hint 885-885: Avoid using bare except statements.

Similar to the previous comment in the other file, avoid using bare except statements to improve error handling specificity and maintainability.

-    except:
+    except Exception as e:
+        logger.error(f"Failed to open file due to: {str(e)}")
+        return None
fiftyone/utils/data/exporters.py (9)

Line range hint 541-541: Avoid using bare except statements.

- except:
+ except Exception as e:

Line range hint 571-571: Avoid using bare except statements.

- except:
+ except Exception as e:

Line range hint 614-614: Avoid using bare except statements.

- except:
+ except Exception as e:

Line range hint 649-649: Avoid using bare except statements.

- except:
+ except Exception as e:

Line range hint 904-904: Avoid using bare except statements.

- except:
+ except Exception as e:

Line range hint 3815-3815: Use direct truth checks instead of comparing to False.

- if include_confidence == False:
+ if not include_confidence:

Line range hint 3815-3815: Use direct truth checks instead of comparing to False.

- if include_attributes == False:
+ if not include_attributes:

Line range hint 3941-3941: Use direct truth checks instead of comparing to True.

- if include_confidence == True:
+ if include_confidence:

Line range hint 3946-3946: Use direct truth checks instead of comparing to True.

- if include_attributes == True:
+ if include_attributes:
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 50943b9 and 08fe5e0.

Files selected for processing (5)
  • fiftyone/core/metadata.py (7 hunks)
  • fiftyone/core/storage.py (1 hunks)
  • fiftyone/core/threed/scene_3d.py (3 hunks)
  • fiftyone/utils/data/exporters.py (3 hunks)
  • fiftyone/utils/utils3d.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • fiftyone/core/threed/scene_3d.py
Additional context used
Ruff
fiftyone/core/metadata.py

561-561: Do not use bare except

fiftyone/core/storage.py

8-8: contextlib.contextmanager imported but unused


885-885: Do not use bare except

fiftyone/utils/data/exporters.py

541-541: Do not use bare except


571-571: Do not use bare except


614-614: Do not use bare except


649-649: Do not use bare except


904-904: Do not use bare except


3815-3815: Avoid inequality comparisons to False; use if include_confidence: for truth checks


3815-3815: Avoid inequality comparisons to False; use if include_attributes: for truth checks


3941-3941: Avoid equality comparisons to True; use if include_confidence: for truth checks


3946-3946: Avoid equality comparisons to True; use if include_attributes: for truth checks

Additional comments not posted (2)
fiftyone/core/metadata.py (1)

Line range hint 486-527: Verify the effectiveness of the new caching mechanism.

fiftyone/utils/utils3d.py (1)

474-474: Simplified asset path resolution enhances readability and potentially improves performance.

scene_dir = os.path.dirname(original_scene_path)
for i, asset_path in enumerate(asset_paths):
if not fos.isabs(asset_path):
asset_path = fos.join(scene_dir, asset_path)
asset_paths[i] = fos.resolve(asset_path)
asset_paths[i] = fos.resolve(fos.join(scene_dir, asset_path))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize asset path resolution logic.

The current implementation resolves the absolute path for each asset sequentially within a loop. This could be inefficient if there are many assets. Consider using vectorized operations or list comprehensions to handle path operations in bulk, which could potentially improve performance.

fiftyone/core/metadata.py Show resolved Hide resolved
Comment on lines +229 to +267
@classmethod
def build_for(cls, scene_path, mime_type=None, _cache=None):
"""Builds a :class:`SceneMetadata` object for the given 3D scene.

Args:
scene_path: a scene path
mime_type (None): the MIME type of the scene. If not provided,
defaults to ``application/octet-stream``

Returns:
a :class:`SceneMetadata`
"""
if scene_path.startswith("http"):
return cls._build_for_url(
scene_path, mime_type=mime_type, cache=_cache
)

return cls._build_for_local(
scene_path, mime_type=mime_type, cache=_cache
)

@classmethod
def _build_for_local(cls, scene_path, mime_type=None, cache=None):
if mime_type is None:
mime_type = "application/octet-stream"

scene_size = os.path.getsize(scene_path)
scene = fo3d.Scene.from_fo3d(scene_path)

asset_counts, asset_size = _parse_assets(
scene, scene_path, cache=cache
)
size_bytes = scene_size + asset_size

return cls(
size_bytes=size_bytes,
mime_type=mime_type,
asset_counts=asset_counts,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor to improve caching mechanism.

The caching mechanism can be improved by ensuring that the cache is utilized more efficiently. Consider checking the cache before making file system calls or processing assets, which could save significant processing time, especially for large datasets.

fiftyone/core/metadata.py Show resolved Hide resolved

try:
return _get_metadata(filepath, media_type)
return _get_metadata(filepath, media_type, cache=cache)
except:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using bare except statements.

Using bare except statements can catch unexpected exceptions and make debugging more difficult. Specify the exception type to improve error handling.

-    except:
+    except Exception as e:
+        logger.error(f"Failed to get metadata due to: {str(e)}")
+        return None

Committable suggestion was skipped due low confidence.

Tools
Ruff

561-561: Do not use bare except

@brimoor brimoor changed the base branch from develop to release/v0.24.1 June 4, 2024 12:36
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 08fe5e0 and ac7cf2f.

Files selected for processing (1)
  • fiftyone/utils/data/exporters.py (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • fiftyone/utils/data/exporters.py

@brimoor brimoor changed the base branch from release/v0.24.1 to develop June 4, 2024 12:41
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ac7cf2f and 200c285.

Files selected for processing (7)
  • fiftyone/core/metadata.py (7 hunks)
  • fiftyone/core/storage.py (3 hunks)
  • fiftyone/core/threed/scene_3d.py (3 hunks)
  • fiftyone/utils/data/exporters.py (6 hunks)
  • fiftyone/utils/utils3d.py (3 hunks)
  • tests/unittests/metadata_tests.py (1 hunks)
  • tests/unittests/utils3d_tests.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • tests/unittests/utils3d_tests.py
Files skipped from review as they are similar to previous changes (4)
  • fiftyone/core/storage.py
  • fiftyone/core/threed/scene_3d.py
  • fiftyone/utils/data/exporters.py
  • fiftyone/utils/utils3d.py
Additional comments not posted (3)
tests/unittests/metadata_tests.py (2)

33-35: Ensure the logic for not counting duplicate assets is correctly implemented in the metadata computation.

#!/bin/bash
# Description: Verify that duplicate assets are not counted in the metadata computation.

# Test: Search for the logic handling duplicate assets in metadata computation.
rg --type python $'metadata.asset_counts' --context 5

43-45: Ensure the calculation of expected_size correctly includes the size of the scene file and all assets.

#!/bin/bash
# Description: Verify that the size calculation includes all assets.

# Test: Search for the size calculation logic in the metadata computation.
rg --type python $'metadata.size_bytes' --context 5
fiftyone/core/metadata.py (1)

486-488: Ensure the caching mechanism is correctly implemented and utilized across metadata computation functions.

#!/bin/bash
# Description: Verify that the caching mechanism is correctly implemented.

# Test: Search for the usage of the cache parameter in metadata computation functions.
rg --type python $'cache=' --context 5

Also applies to: 525-527, 546-548, 554-555

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 200c285 and dbb78b4.

Files selected for processing (1)
  • fiftyone/utils/data/exporters.py (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • fiftyone/utils/data/exporters.py

@brimoor brimoor changed the base branch from develop to release/v0.24.1 June 5, 2024 15:00
@brimoor brimoor changed the base branch from release/v0.24.1 to develop June 5, 2024 15:12
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dbb78b4 and ab5ef1f.

Files selected for processing (1)
  • tests/unittests/threed/scene_3d_tests.py (2 hunks)
Files skipped from review due to trivial changes (1)
  • tests/unittests/threed/scene_3d_tests.py

@brimoor brimoor requested review from benjaminpkane and removed request for allenleetc June 6, 2024 13:01
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ab5ef1f and 3f2cbdd.

Files selected for processing (1)
  • docs/source/teams/cloud_media.rst (12 hunks)

docs/source/teams/cloud_media.rst Show resolved Hide resolved
def resolve(path):
"""Resolves path to absolute, resolving symlinks and relative path
indicators such as `.` and `..`.
def realpath(path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting this is a public API change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes true. My thinking was that this was only introduced in fiftyone==0.24.0 and the spirit of the fiftyone.core.storage module is to exactly match the os package's naming convention for the methods that it wraps, so this felt consistent.

Copy link
Contributor

@benjaminpkane benjaminpkane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@brimoor brimoor merged commit f633834 into develop Jun 6, 2024
12 checks passed
@brimoor brimoor deleted the bugfix/3d-update-asset-paths branch June 6, 2024 13:45
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.

3 participants