2022-02-20 06:42:10 +02:00
|
|
|
from pydantic import BaseModel
|
|
|
|
from fastapi import FastAPI
|
|
|
|
|
2022-02-21 05:17:36 +02:00
|
|
|
from .object_detection import object_detection
|
|
|
|
from .image_classifier import image_classifier
|
2022-02-20 06:42:10 +02:00
|
|
|
|
2022-02-21 05:17:36 +02:00
|
|
|
from tf2_yolov4.anchors import YOLOV4_ANCHORS
|
|
|
|
from tf2_yolov4.model import YOLOv4
|
2022-02-20 06:42:10 +02:00
|
|
|
|
|
|
|
|
2022-02-21 05:17:36 +02:00
|
|
|
HEIGHT, WIDTH = (640, 960)
|
2022-02-20 06:42:10 +02:00
|
|
|
|
|
|
|
# Warm up model
|
2022-02-21 05:17:36 +02:00
|
|
|
image_classifier.warm_up()
|
2022-02-20 06:42:10 +02:00
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
class TagImagePayload(BaseModel):
|
|
|
|
thumbnail_path: str
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/tagImage")
|
|
|
|
async def post_root(payload: TagImagePayload):
|
2022-02-21 05:17:36 +02:00
|
|
|
image_path = payload.thumbnail_path
|
2022-02-20 06:42:10 +02:00
|
|
|
|
2022-02-21 05:17:36 +02:00
|
|
|
if image_path[0] == '.':
|
|
|
|
image_path = image_path[2:]
|
2022-02-20 06:42:10 +02:00
|
|
|
|
2022-02-21 05:17:36 +02:00
|
|
|
return image_classifier.classify_image(image_path=image_path)
|
2022-02-20 06:42:10 +02:00
|
|
|
|
|
|
|
|
2022-02-21 05:17:36 +02:00
|
|
|
@app.get("/")
|
|
|
|
async def test():
|
|
|
|
|
|
|
|
object_detection.run_detection()
|
|
|
|
# image = tf.io.read_file("./app/cars.jpg")
|
|
|
|
# image = tf.image.decode_image(image)
|
|
|
|
# image = tf.image.resize(image, (HEIGHT, WIDTH))
|
|
|
|
# images = tf.expand_dims(image, axis=0) / 255.0
|
|
|
|
|
|
|
|
# model = YOLOv4(
|
|
|
|
# (HEIGHT, WIDTH, 3),
|
|
|
|
# 80,
|
|
|
|
# YOLOV4_ANCHORS,
|
|
|
|
# "darknet",
|
|
|
|
# )
|