Origami-Cloudless-AI / TinyMLaaS-2023-winter

Run Hello World of TensorFlow Lite for micro automatically in Docker
https://Origami-TinyML.github.io/tflm_hello_world
Apache License 2.0
1 stars 2 forks source link

WebApp accepts image data via network #49

Open doyu opened 1 year ago

doyu commented 1 year ago

The parent issue #45 User stories https://miro.com/app/board/uXjVPwQdIjc=/

Acceptance test

  1. nc sends an image data via TCP.
  2. nc sends the checksum of an image data via TCP.
  3. WebApp recieves an image via TCP port.
  4. WebApp verifies if checksum of image data is same as the checksum sent.

Question

How to deal with a file (per connection vs REST PUT)?

doyu commented 1 year ago

@ArttuLe @FexbYk23

Can you guys specify which interface woud be suitable for this? We don't need anything complicated or performinat at all, but something simple enough to implement for this purpose.

FexbYk23 commented 1 year ago

@ArttuLe @FexbYk23

Can you guys specify which interface woud be suitable for this? We don't need anything complicated or performinat at all, but something simple enough to implement for this purpose.

I think that a REST API would be a nicer and easier to maintain solution than some custom protocol built with TCP. However I'm not sure how such API should be implemented. Streamlit doesn't currently seem to support handling custom requests, so some additional library would be needed.

But before implementing anything I think we need to decide how networking code should interact with the web app. Some options include:

  1. Streamlit app asynchronously listens for connections. (this is what's done currently)

  2. A separate thread in the streamlit app listens for connections.

  3. A separate server process/container listens for connections, streamlit app acts as a client.

  4. Streamlit app somehow runs inside a web framework which listens for connections.

I'd like to know if there are other ways to do things, or which of the above should be used. Personally I like the third option the most.

doyu commented 1 year ago

A separate server process/container listens for connections, streamlit app acts as a client.

That was the original idea of using nc -l server process, storing the received data into a file in another process in the same container. This is not performant at all, but it's easier to implement and to support defferent meida type too. Then, WebApp would just read a file from storage. What do you think?

You could think this way, you don't have to implmenet necessarily from scratch but you just need to satisfy the target by any means (e.g. making use of any existing solutions)

For example, if the above `nc -l' server is connected / disconnected per a file transfter in an infinite while-loop of it. Each file could be stored in a storage after connection is closed. Then how should we pass its label info? Any idea? A list of file info could be sent in the first connection? This depends on the human detection label format. What's human detection label?

Basically I'm not for putting a lot of things in the same source with Streamlit. I just want to keep streamlit part minimal. One of the reasons for that is, streamlit is good for prototyping but eventually we'll need a REST API server and UIs would be implemented in any client side UI framework (e.g. Flutter or Pyscript).

FexbYk23 commented 1 year ago

A separate server process/container listens for connections, streamlit app acts as a client.

That was the original idea of using nc -l sever process, storing the received data into a file. This is not fast at all, but easier to implement and to support defferent meida type too. Then, WebApp would just read a file from storage. What do you think?

You could think this way, you don't have to implmenet necessarily from scratch but you just need to satisfy the target by any means (e.g. making use of any existing solutions)

For example, if the above `nc -l' server is connected / disconnected per a file transfter in an infinit loop of it. Each file could be stored in a storage after connection is done. Then how should we pass its label info? Any idea? A list of file info could be sent in the first connection? This depends on the human detection label format. What's human detection label?

Basically I'm not for putting a lot of things in the same source with Streamlit. I just want to keep streamlit part minimal. One of the reasons for that is, streamlit is good for prototyping but eventually we'll need a REST API server and UIs would be implemented in any client side UI framework (e.g. Flutter or Pyscript).

I was thinking that we would implement our own REST API server with some web framework. It would offer more flexibility than nc, and allow us to easily handle different types of data such as labels.

But I guess I can just use nc -l for this task.

By the way, what images should I be sending? The hello_world isn't producing any, and there doesn't seem to be a task for making it do that. Do I just copy a test image to the container and send that?

doyu commented 1 year ago

I was thinking that we would implement our own REST API server with some web framework. It would offer more flexibility than nc, and allow us to easily handle different types of data such as labels. But I guess I can just use nc -l for this task.

If it doesn't take much effort, you could too (e.g. auto-generate a REST API server from OpenAPI spec file) since we are under some pressure to present demo. In demo UI part matters a lot.

By the way, what images should I be sending? The hello_world isn't producing any, and there doesn't seem to be a task for making it do that. Do I just copy a test image to the container and send that?

Or ask @ArttuLe, he might have extracted human detection data already. Alos you need to consider how to pass its label info too if you deal with pretrained dataset?

ArttuLe commented 1 year ago

This was the dataset that I was talking about. https://www.kaggle.com/datasets/constantinwerner/human-detection-dataset

doyu commented 1 year ago

Wouldn't it be nice to share this data being used in the team in some document?

doyu commented 1 year ago

As commented in the Discord, WebRTC can be one option to meet our requirement here, but not in Sprint 3. https://discord.com/channels/1062449235729068212/1062449236177854526/1076816520002408519

In Sprint 3, we should investigate if we could make use of existing API in file uploader, explained, here, https://discord.com/channels/1062449235729068212/1062449236177854526/1076883920248901743