Skip to content

Commit

Permalink
[Data] Cherry-pick object detection example to 2.5.0 release (ray-pro…
Browse files Browse the repository at this point in the history
…ject#35637)

* [Data] Add batch inference object detection example (ray-project#35143)

Signed-off-by: Hao Chen <chenh1024@gmail.com>

* Fix object detection example test

Signed-off-by: Hao Chen <chenh1024@gmail.com>

---------

Signed-off-by: Hao Chen <chenh1024@gmail.com>
  • Loading branch information
raulchen authored May 23, 2023
1 parent 896f834 commit c0d657a
Show file tree
Hide file tree
Showing 6 changed files with 1,090 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/source/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ parts:
- file: data/examples/ocr_example
title: Scaling OCR with Ray Data
- file: data/examples/random-access
- file: data/examples/batch_inference_object_detection
title: Object Detection Batch Inference with PyTorch
- file: data/faq
- file: data/api/api
- file: data/glossary
Expand Down
8 changes: 8 additions & 0 deletions doc/source/data/batch_inference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,14 @@ tutorials and examples:

Batch Inference on NYC taxi data using Ray Data

.. grid-item-card::
:img-top: /images/ray_logo.png
:class-img-top: pt-2 w-75 d-block mx-auto fixed-height-img

.. button-ref:: /data/examples/batch_inference_object_detection

Object Detection Batch Inference with PyTorch

.. grid-item-card::
:img-top: /images/ray_logo.png
:class-img-top: pt-2 w-75 d-block mx-auto fixed-height-img
Expand Down
8 changes: 8 additions & 0 deletions doc/source/data/examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ filegroup(
srcs = glob(["*.ipynb"]),
visibility = ["//doc:__subpackages__"]
)

py_test_run_all_notebooks(
size = "medium",
include = ["batch_inference_object_detection.ipynb"],
exclude = [],
data = ["//doc/source/data/examples:data_examples"],
tags = ["exclusive", "team:data", "gpu"],
)
1,059 changes: 1,059 additions & 0 deletions doc/source/data/examples/batch_inference_object_detection.ipynb

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion doc/test_myst_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ def postprocess_notebook(notebook):
return notebook


if __name__ == "__main__":
DISPLAY_FUNCTION = """
def display(*args, **kwargs):
print(*args, **kwargs)
"""


if __name__ == "__main__":
args, remainder = parser.parse_known_args()

path = Path(args.path)
Expand All @@ -66,6 +71,9 @@ def postprocess_notebook(notebook):

name = ""
with tempfile.NamedTemporaryFile("w", delete=False) as f:
# Define the display function, which is available in notebooks,
# but not in normal Python scripts.
f.write(DISPLAY_FUNCTION)
jupytext.write(notebook, f, fmt="py:percent")
name = f.name

Expand Down
5 changes: 4 additions & 1 deletion python/ray/data/_internal/table_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ def _compact_if_needed(self) -> None:
assert self._columns
if self._uncompacted_size.size_bytes() < MAX_UNCOMPACTED_SIZE_BYTES:
return
block = self._table_from_pydict(self._columns)
columns = {
key: convert_udf_returns_to_numpy(col) for key, col in self._columns.items()
}
block = self._table_from_pydict(columns)
self.add_block(block)
self._uncompacted_size = SizeEstimator()
self._columns.clear()
Expand Down

0 comments on commit c0d657a

Please sign in to comment.