Spaces:
Running
Running
update app/meta to pull spaces model
Browse files
README.md
CHANGED
@@ -8,6 +8,8 @@ sdk_version: 3.31.0
|
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
python_version: 3.10
|
|
|
|
|
11 |
---
|
12 |
|
13 |
[](https://paperswithcode.com/sota/fine-grained-image-classification-on-cub-200?p=metaformer-a-unified-meta-framework-for-fine)
|
|
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
python_version: 3.10
|
11 |
+
models:
|
12 |
+
- joshvm/inaturalist_sgd_4k
|
13 |
---
|
14 |
|
15 |
[](https://paperswithcode.com/sota/fine-grained-image-classification-on-cub-200?p=metaformer-a-unified-meta-framework-for-fine)
|
app.py
CHANGED
@@ -2,12 +2,13 @@ from inference import Inference
|
|
2 |
import argparse
|
3 |
import gradio as gr
|
4 |
import glob
|
|
|
5 |
|
6 |
def parse_option():
|
7 |
parser = argparse.ArgumentParser('MetaFG Inference script', add_help=False)
|
8 |
parser.add_argument('--cfg', type=str, metavar="FILE", help='path to config file', default="configs/MetaFG_2_224.yaml")
|
9 |
# easy config modification
|
10 |
-
parser.add_argument('--model-path', type=str, help="path to model data", default=
|
11 |
parser.add_argument('--img-size', type=int, default=384, help='path to image')
|
12 |
parser.add_argument('--meta-path', default="meta.txt", type=str, help='path to meta data')
|
13 |
parser.add_argument('--names-path', default="names_mf2.txt", type=str, help='path to meta data')
|
@@ -17,19 +18,33 @@ def parse_option():
|
|
17 |
if __name__ == '__main__':
|
18 |
args = parse_option()
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def classify(image):
|
25 |
-
preds = model.infer(img_path=image, meta_data_path="meta.txt")
|
26 |
-
|
27 |
-
print(model.classes)
|
28 |
-
confidences = {c: float(preds[i]) for i,c in enumerate(model.classes)}
|
29 |
|
30 |
-
return
|
31 |
|
32 |
-
gr.Interface(
|
33 |
inputs=gr.Image(shape=(args.img_size, args.img_size), type="pil"),
|
34 |
outputs=gr.Label(num_top_classes=10),
|
35 |
examples=glob.glob("./example_images/*")).launch()
|
|
|
2 |
import argparse
|
3 |
import gradio as gr
|
4 |
import glob
|
5 |
+
from huggingface_hub import hf_hub_download
|
6 |
|
7 |
def parse_option():
|
8 |
parser = argparse.ArgumentParser('MetaFG Inference script', add_help=False)
|
9 |
parser.add_argument('--cfg', type=str, metavar="FILE", help='path to config file', default="configs/MetaFG_2_224.yaml")
|
10 |
# easy config modification
|
11 |
+
parser.add_argument('--model-path', type=str, help="path to model data", default=None)
|
12 |
parser.add_argument('--img-size', type=int, default=384, help='path to image')
|
13 |
parser.add_argument('--meta-path', default="meta.txt", type=str, help='path to meta data')
|
14 |
parser.add_argument('--names-path', default="names_mf2.txt", type=str, help='path to meta data')
|
|
|
18 |
if __name__ == '__main__':
|
19 |
args = parse_option()
|
20 |
|
21 |
+
if not args.model_path:
|
22 |
+
model_path = hf_hub_download(repo_id="joshvm/inaturalist_sgd_4k", filename="ckpt_epoch_35.pth")
|
23 |
+
else:
|
24 |
+
model_path = args.model_path
|
25 |
+
|
26 |
+
if not args.cfg:
|
27 |
+
model_config = hf_hub_download(repo_id="joshvm/inaturalist_sgd_4k", filename="MetaFG_2_224.yaml")
|
28 |
+
else:
|
29 |
+
model_config = args.cfg
|
30 |
+
|
31 |
+
if not args.names_path:
|
32 |
+
names_path = hf_hub_download(repo_id="joshvm/inaturalist_sgd_4k", filename="names_mf2.txt")
|
33 |
+
else:
|
34 |
+
names_path = args.names_path
|
35 |
+
|
36 |
+
|
37 |
+
model = Inference(config_path=model_config,
|
38 |
+
model_path=model_path,
|
39 |
+
names_path=names_path)
|
40 |
|
41 |
def classify(image):
|
42 |
+
preds = model.infer(img_path=image, meta_data_path="meta.txt")
|
43 |
+
#confidences = {c: float(preds[i]) for i,c in enumerate(model.classes)}
|
|
|
|
|
44 |
|
45 |
+
return preds
|
46 |
|
47 |
+
gr.Interface(fn=classify,
|
48 |
inputs=gr.Image(shape=(args.img_size, args.img_size), type="pil"),
|
49 |
outputs=gr.Label(num_top_classes=10),
|
50 |
examples=glob.glob("./example_images/*")).launch()
|
meta.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
this is a picture of a plant or animal, taken in Singapore
|