Created
April 2, 2024 13:05
-
-
Save ozankaraali/5cb2beddfcb7261310c27ebbf330a124 to your computer and use it in GitHub Desktop.
Reproducible Error
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
from contextlib import asynccontextmanager | |
import open3d as o3d | |
import uvicorn | |
from fastapi import FastAPI | |
import torch | |
import torchvision.models as models | |
feature_extractor = {} | |
@asynccontextmanager | |
async def lifespan(app: FastAPI): | |
feature_extractor['fe'] = FeatureExtractor() | |
yield | |
app = FastAPI(lifespan=lifespan) | |
class FeatureExtractor(torch.nn.Module): | |
def __init__(self): | |
super(FeatureExtractor, self).__init__() | |
self.model = models.vgg16(weights=models.VGG16_Weights.DEFAULT).features | |
for param in self.model.parameters(): | |
param.requires_grad = False | |
def forward(self, x): | |
x = self.model(x) | |
return x | |
@app.get("/") | |
async def read_root(): | |
return {"version": o3d.__version__} | |
if __name__ == "__main__": | |
uvicorn.run(app, host="0.0.0.0", port=8000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment