Spaces:
Running
Running
admin
commited on
Commit
Β·
1efa705
1
Parent(s):
95df7de
upd gradio
Browse files
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: π₯οΈπ
|
|
4 |
colorFrom: pink
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
|
|
4 |
colorFrom: pink
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.44.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
app.py
CHANGED
@@ -7,123 +7,105 @@ import pandas as pd
|
|
7 |
from tqdm import tqdm
|
8 |
from bs4 import BeautifulSoup
|
9 |
|
10 |
-
cache_json =
|
11 |
|
12 |
|
13 |
def parse_url(url):
|
14 |
response = requests.get(url)
|
15 |
html = response.text
|
16 |
-
return BeautifulSoup(html,
|
17 |
|
18 |
|
19 |
def special_type(m_ver):
|
20 |
-
m_type = re.search(
|
21 |
|
22 |
-
if m_type ==
|
23 |
-
return
|
24 |
|
25 |
-
elif m_type ==
|
26 |
-
return
|
27 |
|
28 |
-
elif m_type ==
|
29 |
-
return
|
30 |
|
31 |
return m_type
|
32 |
|
33 |
|
34 |
def info_on_dataset(m_ver, m_type, in1k_span):
|
35 |
-
url_span = in1k_span.find_next_sibling(
|
36 |
-
size_span = url_span.find_next_sibling(
|
37 |
m_url = str(url_span.text[1:-1])
|
38 |
input_size = int(size_span.text)
|
39 |
-
m_dict = {
|
40 |
-
'ver': m_ver,
|
41 |
-
'type': m_type,
|
42 |
-
'input_size': input_size,
|
43 |
-
'url': m_url
|
44 |
-
}
|
45 |
return m_dict, size_span
|
46 |
|
47 |
|
48 |
-
def gen_dataframe(url=
|
49 |
torch_page = parse_url(url)
|
50 |
-
article = torch_page.find(
|
51 |
-
ul = article.find(
|
52 |
in1k_v1, in1k_v2 = [], []
|
53 |
|
54 |
-
for li in tqdm(ul.find_all(
|
55 |
name = str(li.text)
|
56 |
-
if name.__contains__(
|
57 |
|
58 |
-
if
|
59 |
-
name.__contains__(
|
60 |
-
|
|
|
|
|
61 |
continue
|
62 |
|
63 |
-
href = li.find(
|
64 |
model_page = parse_url(url + href)
|
65 |
-
divs = model_page.select(
|
66 |
|
67 |
for div in divs:
|
68 |
-
div_id = str(div[
|
69 |
-
if div_id.__contains__(
|
70 |
-
m_ver = div_id.split(
|
71 |
|
72 |
-
if m_ver.__contains__(
|
73 |
continue
|
74 |
|
75 |
m_type = special_type(m_ver)
|
76 |
|
77 |
in1k_v1_span = div.find(
|
78 |
-
name=
|
79 |
-
attrs={'class': 'n'},
|
80 |
-
string='IMAGENET1K_V1'
|
81 |
)
|
82 |
|
83 |
if not in1k_v1_span:
|
84 |
continue
|
85 |
|
86 |
-
m_dict, size_span = info_on_dataset(
|
87 |
-
m_ver,
|
88 |
-
m_type,
|
89 |
-
in1k_v1_span
|
90 |
-
)
|
91 |
in1k_v1.append(m_dict)
|
92 |
|
93 |
in1k_v2_span = size_span.find_next_sibling(
|
94 |
-
name=
|
95 |
-
attrs={'class': 'n'},
|
96 |
-
string='IMAGENET1K_V2'
|
97 |
)
|
98 |
|
99 |
if in1k_v2_span:
|
100 |
-
m_dict, _ = info_on_dataset(
|
101 |
-
m_ver,
|
102 |
-
m_type,
|
103 |
-
in1k_v2_span
|
104 |
-
)
|
105 |
in1k_v2.append(m_dict)
|
106 |
|
107 |
-
dataset = {
|
108 |
-
'IMAGENET1K_V1': in1k_v1,
|
109 |
-
'IMAGENET1K_V2': in1k_v2
|
110 |
-
}
|
111 |
|
112 |
-
with open(
|
113 |
for item in in1k_v1:
|
114 |
-
jsonl_file.write(json.dumps(item) +
|
115 |
|
116 |
-
with open(
|
117 |
for item in in1k_v2:
|
118 |
-
jsonl_file.write(json.dumps(item) +
|
119 |
|
120 |
return dataset
|
121 |
|
122 |
|
123 |
def inference(subset):
|
124 |
-
cache_json = f
|
125 |
if os.path.exists(cache_json):
|
126 |
-
with open(cache_json,
|
127 |
dataset = [json.loads(line) for line in jsonl_file]
|
128 |
else:
|
129 |
dataset = gen_dataframe()[subset]
|
@@ -132,7 +114,7 @@ def inference(subset):
|
|
132 |
|
133 |
|
134 |
def sync(subset):
|
135 |
-
cache_json = f
|
136 |
if os.path.exists(cache_json):
|
137 |
os.remove(cache_json)
|
138 |
|
@@ -142,26 +124,15 @@ def sync(subset):
|
|
142 |
with gr.Blocks() as demo:
|
143 |
with gr.Row():
|
144 |
subset_opt = gr.Dropdown(
|
145 |
-
choices=[
|
146 |
-
value='IMAGENET1K_V1'
|
147 |
)
|
148 |
sync_btn = gr.Button("Clean cache")
|
149 |
dld_file = gr.components.File(label="Download JSON lines")
|
150 |
|
151 |
with gr.Row():
|
152 |
-
data_frame = gr.Dataframe(
|
153 |
-
|
154 |
-
|
|
|
155 |
|
156 |
-
|
157 |
-
inference,
|
158 |
-
inputs=subset_opt,
|
159 |
-
outputs=[data_frame, dld_file]
|
160 |
-
)
|
161 |
-
sync_btn.click(
|
162 |
-
sync,
|
163 |
-
inputs=subset_opt,
|
164 |
-
outputs=dld_file
|
165 |
-
)
|
166 |
-
|
167 |
-
demo.launch(share=True)
|
|
|
7 |
from tqdm import tqdm
|
8 |
from bs4 import BeautifulSoup
|
9 |
|
10 |
+
cache_json = "cv_backbones.json"
|
11 |
|
12 |
|
13 |
def parse_url(url):
|
14 |
response = requests.get(url)
|
15 |
html = response.text
|
16 |
+
return BeautifulSoup(html, "html.parser")
|
17 |
|
18 |
|
19 |
def special_type(m_ver):
|
20 |
+
m_type = re.search("[a-zA-Z]+", m_ver).group(0)
|
21 |
|
22 |
+
if m_type == "wide" or m_type == "resnext":
|
23 |
+
return "resnet"
|
24 |
|
25 |
+
elif m_type == "swin":
|
26 |
+
return "swin_transformer"
|
27 |
|
28 |
+
elif m_type == "inception":
|
29 |
+
return "googlenet"
|
30 |
|
31 |
return m_type
|
32 |
|
33 |
|
34 |
def info_on_dataset(m_ver, m_type, in1k_span):
|
35 |
+
url_span = in1k_span.find_next_sibling("span", {"class": "s2"})
|
36 |
+
size_span = url_span.find_next_sibling("span", {"class": "mi"})
|
37 |
m_url = str(url_span.text[1:-1])
|
38 |
input_size = int(size_span.text)
|
39 |
+
m_dict = {"ver": m_ver, "type": m_type, "input_size": input_size, "url": m_url}
|
|
|
|
|
|
|
|
|
|
|
40 |
return m_dict, size_span
|
41 |
|
42 |
|
43 |
+
def gen_dataframe(url="https://pytorch.org/vision/main/_modules/"):
|
44 |
torch_page = parse_url(url)
|
45 |
+
article = torch_page.find("article", {"id": "pytorch-article"})
|
46 |
+
ul = article.find("ul").find("ul")
|
47 |
in1k_v1, in1k_v2 = [], []
|
48 |
|
49 |
+
for li in tqdm(ul.find_all("li"), desc="Crawling cv backbone info..."):
|
50 |
name = str(li.text)
|
51 |
+
if name.__contains__("torchvision.models.") and len(name.split(".")) == 3:
|
52 |
|
53 |
+
if (
|
54 |
+
name.__contains__("_api")
|
55 |
+
or name.__contains__("feature_extraction")
|
56 |
+
or name.__contains__("maxvit")
|
57 |
+
):
|
58 |
continue
|
59 |
|
60 |
+
href = li.find("a").get("href")
|
61 |
model_page = parse_url(url + href)
|
62 |
+
divs = model_page.select("div.viewcode-block")
|
63 |
|
64 |
for div in divs:
|
65 |
+
div_id = str(div["id"])
|
66 |
+
if div_id.__contains__("_Weights"):
|
67 |
+
m_ver = div_id.split("_Weight")[0].lower()
|
68 |
|
69 |
+
if m_ver.__contains__("swin_v2_"):
|
70 |
continue
|
71 |
|
72 |
m_type = special_type(m_ver)
|
73 |
|
74 |
in1k_v1_span = div.find(
|
75 |
+
name="span", attrs={"class": "n"}, string="IMAGENET1K_V1"
|
|
|
|
|
76 |
)
|
77 |
|
78 |
if not in1k_v1_span:
|
79 |
continue
|
80 |
|
81 |
+
m_dict, size_span = info_on_dataset(m_ver, m_type, in1k_v1_span)
|
|
|
|
|
|
|
|
|
82 |
in1k_v1.append(m_dict)
|
83 |
|
84 |
in1k_v2_span = size_span.find_next_sibling(
|
85 |
+
name="span", attrs={"class": "n"}, string="IMAGENET1K_V2"
|
|
|
|
|
86 |
)
|
87 |
|
88 |
if in1k_v2_span:
|
89 |
+
m_dict, _ = info_on_dataset(m_ver, m_type, in1k_v2_span)
|
|
|
|
|
|
|
|
|
90 |
in1k_v2.append(m_dict)
|
91 |
|
92 |
+
dataset = {"IMAGENET1K_V1": in1k_v1, "IMAGENET1K_V2": in1k_v2}
|
|
|
|
|
|
|
93 |
|
94 |
+
with open("IMAGENET1K_V1.jsonl", "w", encoding="utf-8") as jsonl_file:
|
95 |
for item in in1k_v1:
|
96 |
+
jsonl_file.write(json.dumps(item) + "\n")
|
97 |
|
98 |
+
with open("IMAGENET1K_V2.jsonl", "w", encoding="utf-8") as jsonl_file:
|
99 |
for item in in1k_v2:
|
100 |
+
jsonl_file.write(json.dumps(item) + "\n")
|
101 |
|
102 |
return dataset
|
103 |
|
104 |
|
105 |
def inference(subset):
|
106 |
+
cache_json = f"{subset}.jsonl"
|
107 |
if os.path.exists(cache_json):
|
108 |
+
with open(cache_json, "r", encoding="utf-8") as jsonl_file:
|
109 |
dataset = [json.loads(line) for line in jsonl_file]
|
110 |
else:
|
111 |
dataset = gen_dataframe()[subset]
|
|
|
114 |
|
115 |
|
116 |
def sync(subset):
|
117 |
+
cache_json = f"{subset}.jsonl"
|
118 |
if os.path.exists(cache_json):
|
119 |
os.remove(cache_json)
|
120 |
|
|
|
124 |
with gr.Blocks() as demo:
|
125 |
with gr.Row():
|
126 |
subset_opt = gr.Dropdown(
|
127 |
+
choices=["IMAGENET1K_V1", "IMAGENET1K_V2"], value="IMAGENET1K_V1"
|
|
|
128 |
)
|
129 |
sync_btn = gr.Button("Clean cache")
|
130 |
dld_file = gr.components.File(label="Download JSON lines")
|
131 |
|
132 |
with gr.Row():
|
133 |
+
data_frame = gr.Dataframe(headers=["ver", "type", "input_size", "url"])
|
134 |
+
|
135 |
+
subset_opt.change(inference, inputs=subset_opt, outputs=[data_frame, dld_file])
|
136 |
+
sync_btn.click(sync, inputs=subset_opt, outputs=dld_file)
|
137 |
|
138 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|