Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,6 +34,19 @@ import torch.nn.functional as F
|
|
34 |
# learn = load_learner(repo_id)
|
35 |
#learner = from_pretrained_fastai(repo_id)
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
from huggingface_hub import from_pretrained_fastai
|
38 |
import torchvision.transforms as transforms
|
39 |
# from Transform import ItemTransform
|
|
|
34 |
# learn = load_learner(repo_id)
|
35 |
#learner = from_pretrained_fastai(repo_id)
|
36 |
|
37 |
+
|
38 |
+
class ItemTransform(Transform):
|
39 |
+
"A transform that always take tuples as items"
|
40 |
+
_retain = True
|
41 |
+
def __call__(self, x, **kwargs): return self._call1(x, '__call__', **kwargs)
|
42 |
+
def decode(self, x, **kwargs): return self._call1(x, 'decode', **kwargs)
|
43 |
+
def _call1(self, x, name, **kwargs):
|
44 |
+
if not _is_tuple(x): return getattr(super(), name)(x, **kwargs)
|
45 |
+
y = getattr(super(), name)(list(x), **kwargs)
|
46 |
+
if not self._retain: return y
|
47 |
+
if is_listy(y) and not isinstance(y, tuple): y = tuple(y)
|
48 |
+
return retain_type(y, x)
|
49 |
+
|
50 |
from huggingface_hub import from_pretrained_fastai
|
51 |
import torchvision.transforms as transforms
|
52 |
# from Transform import ItemTransform
|