eto-ai / rikai

Parquet-based ML data format optimized for working with unstructured data
https://rikai.readthedocs.io/en/latest/
Apache License 2.0
137 stars 19 forks source link

[no ci] Rikai DSL for Image Visualization on Mojito #562

Closed da-tubi closed 2 years ago

da-tubi commented 2 years ago

github preview: https://github.com/da-tubi/rikai/blob/feature/mojito_dsl/notebooks/MojitoDSL.ipynb google colab: https://colab.research.google.com/github/da-tubi/rikai/blob/feature/mojito_dsl/notebooks/MojitoDSL.ipynb

eddyxu commented 2 years ago

we should not need to use box2d_demo.to_image().to_pil() to display an image.

text_demo = image | Box2d(118, 18, 520, 136) | Text("Mojito", (118, 8))
text_demo.to_image().to_pil()

change to

image | Box2d(118, 18, 520, 136) | Text("Mojito", (118, 8))
da-tubi commented 2 years ago
text_demo.to_image().to_pil()

is used to make github preview work.

eddyxu commented 2 years ago

isnt this a bug?

Otherwise, it gives user an impression that we have to make to_image().to_pil() to make the notebook work.

For example, image itself can work well, can we just make the rendered visualized image work the same?

da-tubi commented 2 years ago

isnt this a bug?

It is a github ipynb render bug.

Otherwise, it gives user an impression that we have to make to_image().to_pil() to make the notebook work.

Let me add comments in the notebook.

For example, image itself can work well, can we just make the rendered visualized image work the same?

The current impl is ok. It is a github bug. Github only support previewing an old version of ipynb.

da-tubi commented 2 years ago

comment added:

image
eddyxu commented 2 years ago

I guess what I meant is that, for example, in the github preview notebook, Cell [1] works directly from rikai.types.Image, right?

Can we make

box2d_demo = image | Box2d(118, 18, 520, 136)

where box2d_demo share the same impl as rikai.types.Image when the display is called?

da-tubi commented 2 years ago

We can not make box2d_demo (rikai ImageDraw) or box2d_demo.to_image() (rikai Image) work in Github Preview now.

Cell [1] works because it is an external image. xyz_demo is embedded image. For embedded images, the current impl is a work around for Databricks notebook. See #434

If we make it work for Github Preview, it may break Databricks notebook.

da-tubi commented 2 years ago

My first attempt (the third commit of this pr), try xyz_demo.to_image():

image
eddyxu commented 2 years ago

i dont think this is an inline vs embedded problem. For example, after to_pil(), that is an in memory PIL image as well. Can we understand what protocol makes PIL works , and implement the same for ImageDraw?

da-tubi commented 2 years ago

Thats why pil works and image/draw do not work:

image

It works in Google colab. It is a Github Preview issue.

eddyxu commented 2 years ago

For example, can we make Image or ImageDraw 's display() returns a PIL image instead?

da-tubi commented 1 year ago

Finally done here: https://github.com/liga-ai/ligavision/pull/6