Skip to content

Commit

Permalink
Merge pull request #256 from jeffmaury/GH-220
Browse files Browse the repository at this point in the history
fix: update object_detection recipe for be compatible with AI Lab
  • Loading branch information
Gregory-Pereira authored Apr 16, 2024
2 parents 605ceee + f47f18f commit 9016778
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
from transformers import AutoImageProcessor, AutoModelForObjectDetection
from huggingface_hub import snapshot_download
from PIL import Image, ImageDraw
from fastapi import FastAPI
from pydantic import BaseModel
import torch
import base64
import os
import io
import shutil


app = FastAPI()
model = os.getenv("MODEL_PATH", default="facebook/detr-resnet-101")
revision = os.getenv("MODEL_REVISION", default="no_timm")

processor = AutoImageProcessor.from_pretrained(model, revision=revision)
model = AutoModelForObjectDetection.from_pretrained(model, revision=revision)
if os.path.isfile(model):
model_name = os.getenv("MODEL_NAME", default="facebook/detr-resnet-101")
snapshot_download(repo_id=model_name,
revision=revision,
local_dir=f"/tmp/{model}",
local_dir_use_symlinks=False)
shutil.copyfile(model, f"/tmp/{model}/pytorch_model.bin")
processor = AutoImageProcessor.from_pretrained(f"/tmp/{model}", revision=revision)
model = AutoModelForObjectDetection.from_pretrained(f"/tmp/{model}", revision=revision)
else:
processor = AutoImageProcessor.from_pretrained(model, revision=revision)
model = AutoModelForObjectDetection.from_pretrained(model, revision=revision)

class Item(BaseModel):
image: bytes
Expand Down

0 comments on commit 9016778

Please sign in to comment.