Hi Team, I am using daft to process a large batch ...
# daft-dev
s
Hi Team, I am using daft to process a large batch of images for embedding. It just fails with error below. After some debugging I found that it failed for this image

http://images.cocodataset.org/test2017/000000522914.jpg▾

, perhaps because is it grayscale instead of rgb. • Does daft support grayscale image embedding? • Is there a better way to figure out which row failed out of 1 million? I used binary search. It would be nice to have a better way.
Copy code
TypeError: Cannot handle this data type: (1, 1, 1), |u1

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/senlin/Work/smoosense/smoosense-py/tests/do.py", line 33, in <module>
    run()
  File "/Users/senlin/Work/smoosense/smoosense-py/tests/do.py", line 20, in run
    df = df.to_pandas()
  File "/Users/senlin/Work/smoosense/smoosense-py/.venv/lib/python3.9/site-packages/daft/api_annotations.py", line 38, in _wrap
    return func(*args, **kwargs)
  File "/Users/senlin/Work/smoosense/smoosense-py/.venv/lib/python3.9/site-packages/daft/dataframe/dataframe.py", line 4221, in to_pandas
    self.collect()
  File "/Users/senlin/Work/smoosense/smoosense-py/.venv/lib/python3.9/site-packages/daft/api_annotations.py", line 38, in _wrap
    return func(*args, **kwargs)
  File "/Users/senlin/Work/smoosense/smoosense-py/.venv/lib/python3.9/site-packages/daft/dataframe/dataframe.py", line 4014, in collect
    self._materialize_results()
  File "/Users/senlin/Work/smoosense/smoosense-py/.venv/lib/python3.9/site-packages/daft/dataframe/dataframe.py", line 3976, in _materialize_results
    self._result_cache = get_or_create_runner().run(self._builder)
  File "/Users/senlin/Work/smoosense/smoosense-py/.venv/lib/python3.9/site-packages/daft/runners/native_runner.py", line 66, in run
    results = list(self.run_iter(builder))
  File "/Users/senlin/Work/smoosense/smoosense-py/.venv/lib/python3.9/site-packages/daft/runners/native_runner.py", line 99, in run_iter
    yield from results_gen
  File "/Users/senlin/Work/smoosense/smoosense-py/.venv/lib/python3.9/site-packages/daft/execution/native_executor.py", line 42, in <genexpr>
    return (
  File "/Users/senlin/Work/smoosense/smoosense-py/.venv/lib/python3.9/site-packages/daft/execution/udf.py", line 139, in eval_input
    raise UDFException(response[1]) from base_exc
daft.errors.UDFException: User-defined function `<daft.ai._expressions._ImageEmbedderExpression object at 0x116c4d190>` failed when executing on inputs:
  - __TruncateRootUDF_0-12-0__ (Image[MIXED], length=1)
c
you can decode the images into RGB. And for any failures, you can set the error mode to null, then filter at the end for nulls to find out which were the errors.
Copy code
import daft

df = daft.from_pydict({"path": ["http://images.cocodataset.org/test2017/000000522914.jpg"]})
df = df.with_column(
    "image",
    daft.col("path")
    .url.download(on_error="null")
    .image.decode(mode=daft.ImageMode.RGB, on_error="null")
)
df.show()
We're working on some better failure handlers, but in the meantime setting to null on error should work
d
Just curious, were you using our embed_image function?
s
Yes, I am using
embed_image
Copy code
df = (daft.read_parquet(url).limit(1000)
          .with_column("image_data", col("coco_url").url.download(on_error="null"))
          .with_column("emb", embed_image(col("image_data").image.decode()))
          )
Confirming that setting RGB mode works.
Thanks for the help
Well, now there is a new problem. When I scale up to full dataframe, it failed with error. I was hoping daft to handle parallel and throttling, maxing out my laptop resources but without crashing. Is daft designed for that, or I need to manage the level of parallelism?
Copy code
OSError: [Errno 24] Too many open files
c
are you writing somewhere?
s
Not until the end.
Copy code
import daft
from daft import col
from daft.functions.ai import embed_image

def run():
    url = 'https://cdn.smoosense.ai/datasets/COCO/images-emb-2d.parquet'
    df = (daft.read_parquet(url).limit(100000)
          .with_column("image_data", col("coco_url").url.download(on_error="null"))
          .with_column("emb", embed_image(col("image_data").image.decode(mode=daft.ImageMode.RGB, on_error="null")))
          )


    df = df.to_pandas()
    df.drop(columns=['image_data'], inplace=True)
    df.to_parquet('test.parquet')
s
@Colin Ho @Colin Ho thoughts on setting the default to RGB?
s
I think
embed_image
only expects rgb, so an auto conversion layer either in
embed_image
or
encode
will nicely reduce user friction.
👍 1
s
Yeah that’s a good idea, we can likely push down the dtype expectation into the decode_image call