admin
commited on
Commit
·
680fb78
1
Parent(s):
f903536
try add in1k_v2
Browse files- vi_backbones.py +39 -17
vi_backbones.py
CHANGED
@@ -2,7 +2,7 @@ import os
|
|
2 |
import re
|
3 |
import requests
|
4 |
import datasets
|
5 |
-
import pandas as pd
|
6 |
from bs4 import BeautifulSoup
|
7 |
|
8 |
|
@@ -12,10 +12,10 @@ _HOMEPAGE = "https://huggingface.co/datasets/george-chou/" + _DBNAME
|
|
12 |
|
13 |
_URL = 'https://pytorch.org/vision/main/_modules/'
|
14 |
|
15 |
-
_TYPES = pd.read_csv(_HOMEPAGE + '/resolve/main/data/backbone.csv',
|
16 |
-
|
17 |
|
18 |
-
_NAMES = sorted(list(set(_TYPES.values())))
|
19 |
|
20 |
|
21 |
class vi_backbones(datasets.GeneratorBasedBuilder):
|
@@ -27,8 +27,8 @@ class vi_backbones(datasets.GeneratorBasedBuilder):
|
|
27 |
"ver": datasets.Value("string"),
|
28 |
"type": datasets.Value("string"),
|
29 |
# "type": datasets.features.ClassLabel(names=_NAMES),
|
30 |
-
"input_size": datasets.Value("
|
31 |
-
"
|
32 |
"url": datasets.Value("string"),
|
33 |
}
|
34 |
),
|
@@ -43,50 +43,72 @@ class vi_backbones(datasets.GeneratorBasedBuilder):
|
|
43 |
return BeautifulSoup(html, 'html.parser')
|
44 |
|
45 |
def _generate_dataset(self, url):
|
|
|
46 |
torch_page = self._parse_url(url)
|
47 |
article = torch_page.find('article', {'id': 'pytorch-article'})
|
48 |
ul = article.find('ul').find('ul')
|
49 |
-
|
|
|
50 |
for li in ul.find_all('li'):
|
51 |
name = str(li.text)
|
52 |
if name.__contains__('torchvision.models.') and len(name.split('.')) == 3:
|
53 |
if name.__contains__('_api') or name.__contains__('feature_extraction'):
|
54 |
continue
|
|
|
55 |
href = li.find('a').get('href')
|
56 |
model_page = self._parse_url(url + href)
|
57 |
divs = model_page.select('div.viewcode-block')
|
|
|
58 |
for div in divs:
|
59 |
div_id = str(div['id'])
|
60 |
if div_id.__contains__('_Weights'):
|
61 |
m_ver = div_id.split('_Weight')[0].lower()
|
62 |
m_type = re.search('[a-zA-Z]+', m_ver).group(0)
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
66 |
m_dict = {
|
67 |
'ver': m_ver,
|
68 |
'type': m_type,
|
69 |
'input_size': input_size,
|
|
|
70 |
'url': m_url
|
71 |
}
|
72 |
-
print('Adding ' + m_ver)
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
def _split_generators(self, dl_manager):
|
77 |
-
|
78 |
|
79 |
return [
|
80 |
datasets.SplitGenerator(
|
81 |
name="IMAGENET1K_V1",
|
82 |
gen_kwargs={
|
83 |
-
"files":
|
84 |
},
|
85 |
),
|
86 |
datasets.SplitGenerator(
|
87 |
name="IMAGENET1K_V2",
|
88 |
gen_kwargs={
|
89 |
-
"files":
|
90 |
},
|
91 |
),
|
92 |
]
|
@@ -97,6 +119,6 @@ class vi_backbones(datasets.GeneratorBasedBuilder):
|
|
97 |
"ver": model['ver'],
|
98 |
"type": model['type'],
|
99 |
"input_size": model['input_size'],
|
100 |
-
"
|
101 |
"url": model['url'],
|
102 |
}
|
|
|
2 |
import re
|
3 |
import requests
|
4 |
import datasets
|
5 |
+
# import pandas as pd
|
6 |
from bs4 import BeautifulSoup
|
7 |
|
8 |
|
|
|
12 |
|
13 |
_URL = 'https://pytorch.org/vision/main/_modules/'
|
14 |
|
15 |
+
# _TYPES = pd.read_csv(_HOMEPAGE + '/resolve/main/data/backbone.csv',
|
16 |
+
# index_col='ver').to_dict()['type']
|
17 |
|
18 |
+
# _NAMES = sorted(list(set(_TYPES.values())))
|
19 |
|
20 |
|
21 |
class vi_backbones(datasets.GeneratorBasedBuilder):
|
|
|
27 |
"ver": datasets.Value("string"),
|
28 |
"type": datasets.Value("string"),
|
29 |
# "type": datasets.features.ClassLabel(names=_NAMES),
|
30 |
+
"input_size": datasets.Value("int16"),
|
31 |
+
"num_params": datasets.Value("int32"),
|
32 |
"url": datasets.Value("string"),
|
33 |
}
|
34 |
),
|
|
|
43 |
return BeautifulSoup(html, 'html.parser')
|
44 |
|
45 |
def _generate_dataset(self, url):
|
46 |
+
|
47 |
torch_page = self._parse_url(url)
|
48 |
article = torch_page.find('article', {'id': 'pytorch-article'})
|
49 |
ul = article.find('ul').find('ul')
|
50 |
+
in1k_v1, in1k_v2 = [], []
|
51 |
+
|
52 |
for li in ul.find_all('li'):
|
53 |
name = str(li.text)
|
54 |
if name.__contains__('torchvision.models.') and len(name.split('.')) == 3:
|
55 |
if name.__contains__('_api') or name.__contains__('feature_extraction'):
|
56 |
continue
|
57 |
+
|
58 |
href = li.find('a').get('href')
|
59 |
model_page = self._parse_url(url + href)
|
60 |
divs = model_page.select('div.viewcode-block')
|
61 |
+
|
62 |
for div in divs:
|
63 |
div_id = str(div['id'])
|
64 |
if div_id.__contains__('_Weights'):
|
65 |
m_ver = div_id.split('_Weight')[0].lower()
|
66 |
m_type = re.search('[a-zA-Z]+', m_ver).group(0)
|
67 |
+
ints = div.find_all('span', {'class': 'mi'})
|
68 |
+
m_urls = div.find_all('span', {'class': 's2'})
|
69 |
+
input_size = int(ints[0].text)
|
70 |
+
num_params = int(ints[1].text)
|
71 |
+
m_url = m_urls[0].text
|
72 |
m_dict = {
|
73 |
'ver': m_ver,
|
74 |
'type': m_type,
|
75 |
'input_size': input_size,
|
76 |
+
'num_params': num_params,
|
77 |
'url': m_url
|
78 |
}
|
79 |
+
# print('Adding ' + m_ver + ' on IMAGENET1K_V1')
|
80 |
+
in1k_v1.append(m_dict)
|
81 |
+
|
82 |
+
if len(ints) > 2 and len(m_urls) > 1:
|
83 |
+
input_size = int(ints[2].text)
|
84 |
+
num_params = int(ints[3].text)
|
85 |
+
m_url = m_urls[1].text
|
86 |
+
m_dict = {
|
87 |
+
'ver': m_ver,
|
88 |
+
'type': m_type,
|
89 |
+
'input_size': input_size,
|
90 |
+
'num_params': num_params,
|
91 |
+
'url': m_url
|
92 |
+
}
|
93 |
+
# print('Adding ' + m_ver + ' on IMAGENET1K_V2')
|
94 |
+
in1k_v2.append(m_dict)
|
95 |
+
|
96 |
+
return in1k_v1, in1k_v2
|
97 |
|
98 |
def _split_generators(self, dl_manager):
|
99 |
+
in1k_v1, in1k_v2 = self._generate_dataset(_URL)
|
100 |
|
101 |
return [
|
102 |
datasets.SplitGenerator(
|
103 |
name="IMAGENET1K_V1",
|
104 |
gen_kwargs={
|
105 |
+
"files": in1k_v1,
|
106 |
},
|
107 |
),
|
108 |
datasets.SplitGenerator(
|
109 |
name="IMAGENET1K_V2",
|
110 |
gen_kwargs={
|
111 |
+
"files": in1k_v2,
|
112 |
},
|
113 |
),
|
114 |
]
|
|
|
119 |
"ver": model['ver'],
|
120 |
"type": model['type'],
|
121 |
"input_size": model['input_size'],
|
122 |
+
"num_params": model['num_params'],
|
123 |
"url": model['url'],
|
124 |
}
|