-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathutils.py
More file actions
51 lines (35 loc) · 1.08 KB
/
utils.py
File metadata and controls
51 lines (35 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import tarfile
import requests
from imagenet_classes import imagenet_class
def print_file(dir_name, fname):
fpath = os.path.join(dir_name, fname)
with open(fpath, "r") as f:
for line in f:
print(line)
def maybe_download(dir_name, url):
''' create directory '''
filename = url.split('/')[-1]
# write to local disk
fpath = os.path.join(dir_name, filename)
if os.path.isfile(fpath):
print("Files already exists")
return
if not os.path.exists(dir_name):
os.makedirs(dir_name)
# download
print("Downloading %s ..."%(filename))
req = requests.get(url)
with open(fpath, "wb") as f:
f.write(req.content)
# unzip
print(fpath)
tar = tarfile.open(fpath, "r:gz")
tar.extractall(dir_name)
tar.close()
print("Download complete")
def imagenet_id_to_class(id):
return imagenet_class[id-1]
if __name__ == "__main__":
url = "http://download.tensorflow.org/models/tflite_11_05_08/mobilenet_v2_1.0_224_quant.tgz"
maybe_download("models/mobilenet", url)