Spaces:
Runtime error
Runtime error
try resetting to older version of fastai
Browse files
app.py
CHANGED
@@ -20,38 +20,13 @@ import pandas as pd
|
|
20 |
from PIL import Image
|
21 |
import matplotlib.pyplot as plt
|
22 |
|
|
|
23 |
from fastai.vision import *
|
24 |
|
25 |
import gradio as gr
|
26 |
-
from fastai.vision.all import *
|
27 |
import skimage
|
28 |
|
29 |
-
class FlattenedLoss():
|
30 |
-
"Same as `func`, but flattens input and target."
|
31 |
-
def __init__(self, func, *args, axis:int=-1, floatify:bool=False, is_2d:bool=True, **kwargs):
|
32 |
-
self.func,self.axis,self.floatify,self.is_2d = func(*args,**kwargs),axis,floatify,is_2d
|
33 |
-
functools.update_wrapper(self, self.func)
|
34 |
-
|
35 |
-
def __repr__(self): return f"FlattenedLoss of {self.func}"
|
36 |
-
@property
|
37 |
-
def reduction(self): return self.func.reduction
|
38 |
-
@reduction.setter
|
39 |
-
def reduction(self, v): self.func.reduction = v
|
40 |
-
|
41 |
-
def __call__(self, input:Tensor, target:Tensor, **kwargs)->Rank0Tensor:
|
42 |
-
input = input.transpose(self.axis,-1).contiguous()
|
43 |
-
target = target.transpose(self.axis,-1).contiguous()
|
44 |
-
if self.floatify: target = target.float()
|
45 |
-
|
46 |
-
# Label smoothing experiment
|
47 |
-
target = (target * 0.9 + 0.05)
|
48 |
-
target[:,0] = 1
|
49 |
-
|
50 |
-
input = input.view(-1,input.shape[-1]) if self.is_2d else input.view(-1)
|
51 |
-
return self.func.__call__(input, target.view(-1), **kwargs)
|
52 |
-
|
53 |
-
learn = load_learner('stage2-resnet50-size256-export.pkl')
|
54 |
-
|
55 |
labels = learn.dls.vocab
|
56 |
def predict(img):
|
57 |
img = PILImage.create(img)
|
|
|
20 |
from PIL import Image
|
21 |
import matplotlib.pyplot as plt
|
22 |
|
23 |
+
import fastai==1.0.61
|
24 |
from fastai.vision import *
|
25 |
|
26 |
import gradio as gr
|
27 |
+
# from fastai.vision.all import *
|
28 |
import skimage
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
labels = learn.dls.vocab
|
31 |
def predict(img):
|
32 |
img = PILImage.create(img)
|