-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from furiosamg/update-docs-0.10.0
- Loading branch information
Showing
28 changed files
with
648 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from tempfile import NamedTemporaryFile | ||
from typing import Dict, List | ||
|
||
from fastapi import FastAPI, File, UploadFile | ||
import numpy as np | ||
import uvicorn | ||
|
||
from furiosa.common.thread import synchronous | ||
from furiosa.models import vision | ||
from furiosa.serving import ServeAPI, ServeModel | ||
|
||
serve = ServeAPI() | ||
app: FastAPI = serve.app | ||
|
||
resnet50 = vision.ResNet50() | ||
# ServeModel does not support in-memory model binary for now, | ||
# so we write model into temp file and pass its path | ||
model_file = NamedTemporaryFile() | ||
model_file.write(resnet50.model_source()) | ||
model_file_path = model_file.name | ||
|
||
model: ServeModel = synchronous(serve.model("furiosart"))('ResNet50', location=model_file_path) | ||
|
||
|
||
@model.post("/infer") | ||
async def infer(image: UploadFile = File(...)) -> Dict[str, str]: | ||
# Model Zoo's preprocesses do not consider in-memory image file for now | ||
# (note that it's different from in-memory tensor) | ||
# so we write in-memory image into temp file and pass its path | ||
image_file_path = NamedTemporaryFile() | ||
image_file_path.write(await image.read()) | ||
|
||
tensors, _ctx = resnet50.preprocess(image_file_path.name) | ||
|
||
# Infer from ServeModel | ||
result: List[np.ndarray] = await model.predict(tensors) | ||
|
||
response: str = resnet50.postprocess(result) | ||
|
||
return {"result": response} | ||
|
||
|
||
# Run the server if current Python script is called directly | ||
if __name__ == "__main__": | ||
uvicorn.run(app, host="0.0.0.0", port=8000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.