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

Updates to suppor latest fastai library changes #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cougar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from starlette.responses import JSONResponse, HTMLResponse, RedirectResponse
from fastai.vision import (
ImageDataBunch,
ConvLearner,
create_cnn,
open_image,
get_transforms,
models,
Expand Down Expand Up @@ -47,7 +47,7 @@ async def get_bytes(url):
ds_tfms=get_transforms(),
size=224,
)
cat_learner = ConvLearner(cat_data, models.resnet34)
cat_learner = create_cnn(cat_data, models.resnet34)
cat_learner.model.load_state_dict(
torch.load("usa-inaturalist-cats.pth", map_location="cpu")
)
Expand All @@ -68,7 +68,7 @@ async def classify_url(request):

def predict_image_from_bytes(bytes):
img = open_image(BytesIO(bytes))
losses = img.predict(cat_learner)
_, _, losses = cat_learner.predict(img)
return JSONResponse({
"predictions": sorted(
zip(cat_learner.data.classes, map(float, losses)),
Expand Down