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

Multipart form format #2

Closed
kellansteele opened this issue Jan 27, 2021 · 3 comments
Closed

Multipart form format #2

kellansteele opened this issue Jan 27, 2021 · 3 comments

Comments

@kellansteele
Copy link

Could you provide an example of how you convert your images to bytes and how you're formatting your POST requests (specifically how to include the bytes)? As someone who's never seen any of this before, it would be really helpful! Thank you!

@louisoutin
Copy link
Owner

I do it like this:
from images files, I read the bytes and add each bytes array to a dict containing the batches for the network to predict, ex:

def get_predictions(raw_frames_path: List[Path],
                    batch_size: int
                    ):
    batch = {}
    cpt = 1
    predictions = []
    images_paths = [p.as_posix() for p in raw_frames_path]
    logging.warning(f"images_paths {str(images_paths)}")
    for frame in sorted(images_paths):
        key = "img" + str(cpt)
        cpt += 1
        batch[key] = open(frame, 'rb')
        if len(batch.keys()) >= batch_size:
            # call torchserve predictions
            predictions += _get_prediction(batch)
            batch = {}  # reset batch
            cpt = 1  # reset image idx
    if len(batch.keys()) > 0:
        predictions += _get_prediction(batch)
    return predictions

@kellansteele
Copy link
Author

What do you mean by List[Path] ?

@louisoutin
Copy link
Owner

My function accepts a list of pathlib.Path objects. But you can do the same functions with strings instead, it will work fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants