Spaces:
Runtime error
Runtime error
sankhyikii
commited on
Commit
•
dc07155
1
Parent(s):
2c852c2
bug fix
Browse files
app.py
CHANGED
@@ -5,14 +5,19 @@ from timm import create_model
|
|
5 |
from timm.data import resolve_data_config
|
6 |
from timm.data.transforms_factory import create_transform
|
7 |
|
|
|
8 |
IMAGENET_1k_URL = "https://storage.googleapis.com/bit_models/ilsvrc2012_wordnet_lemmas.txt"
|
9 |
-
|
|
|
10 |
|
|
|
11 |
model = create_model('resnet50',pretrained=True)
|
12 |
transform = create_transform(**resolve_data_config({},model=model))
|
13 |
-
|
14 |
model.eval()
|
15 |
|
|
|
|
|
16 |
def predict(img):
|
17 |
img = img.convert('RGB')
|
18 |
img = transform(img).unsqueeze(0)
|
|
|
5 |
from timm.data import resolve_data_config
|
6 |
from timm.data.transforms_factory import create_transform
|
7 |
|
8 |
+
# url for accesing the image DB
|
9 |
IMAGENET_1k_URL = "https://storage.googleapis.com/bit_models/ilsvrc2012_wordnet_lemmas.txt"
|
10 |
+
# fetching labels from the URL
|
11 |
+
LABELS = requests.get(IMAGENET_1k_URL).text.strip().split('\n')
|
12 |
|
13 |
+
#using a pretrained resnet50 model
|
14 |
model = create_model('resnet50',pretrained=True)
|
15 |
transform = create_transform(**resolve_data_config({},model=model))
|
16 |
+
# we do not need to train model , hence using model.eval() to use it only for inference
|
17 |
model.eval()
|
18 |
|
19 |
+
# declaring the main fn. for returning the prediction from our model
|
20 |
+
# we use softmax, to take probabilities of the outputs.
|
21 |
def predict(img):
|
22 |
img = img.convert('RGB')
|
23 |
img = transform(img).unsqueeze(0)
|