forked from open-edge-platform/model_api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare_data.py
More file actions
128 lines (116 loc) · 5.4 KB
/
Copy pathprepare_data.py
File metadata and controls
128 lines (116 loc) · 5.4 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#
# Copyright (C) 2020-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
import argparse
import asyncio
from io import BytesIO
from pathlib import Path
from zipfile import ZipFile
import httpx
async def download_images(data_dir):
async with httpx.AsyncClient(timeout=20.0) as client:
COCO128_URL = "https://ultralytics.com/assets/coco128.zip"
archive = await client.get(COCO128_URL, follow_redirects=True)
with ZipFile(BytesIO(archive.content)) as zfile:
zfile.extractall(data_dir)
image = await client.get(
"https://raw.githubusercontent.com/Shenggan/BCCD_Dataset/master/BCCD/JPEGImages/BloodImage_00007.jpg"
)
with open(data_dir / "BloodImage_00007.jpg", "wb") as im:
im.write(image.content)
async def stream_file(client, url, filename):
async with client.stream("GET", url) as stream:
with open(filename, "wb") as file:
async for data in stream.aiter_bytes():
file.write(data)
async def download_otx_model(client, otx_models_dir, model_name, format="xml"):
if format == "onnx":
await stream_file(
client,
f"https://storage.openvinotoolkit.org/repositories/model_api/test/otx_models/{model_name}/model.onnx",
f"{otx_models_dir}/{model_name}.onnx",
)
else:
await asyncio.gather(
stream_file(
client,
f"https://storage.openvinotoolkit.org/repositories/model_api/test/otx_models/{model_name}/openvino.xml",
f"{otx_models_dir}/{model_name}.xml",
),
stream_file(
client,
f"https://storage.openvinotoolkit.org/repositories/model_api/test/otx_models/{model_name}/openvino.bin",
f"{otx_models_dir}/{model_name}.bin",
),
)
async def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"-d",
"--data_dir",
type=Path,
required=True,
help="Directory to store downloaded models and datasets",
)
args = parser.parse_args()
otx_models_dir = args.data_dir / "otx_models"
otx_models_dir.mkdir(parents=True, exist_ok=True)
async with httpx.AsyncClient(timeout=20.0) as client:
await asyncio.gather(
download_images(args.data_dir),
download_otx_model(client, otx_models_dir, "mlc_mobilenetv3_large_voc"),
download_otx_model(client, otx_models_dir, "mlc_efficient_b0_voc"),
download_otx_model(client, otx_models_dir, "mlc_efficient_v2s_voc"),
download_otx_model(client, otx_models_dir, "det_mobilenetv2_atss_bccd"),
download_otx_model(
client, otx_models_dir, "det_mobilenetv2_atss_bccd_onnx", "onnx"
),
download_otx_model(client, otx_models_dir, "cls_mobilenetv3_large_cars"),
download_otx_model(
client, otx_models_dir, "cls_mobilenetv3_large_cars", "onnx"
),
download_otx_model(client, otx_models_dir, "cls_efficient_b0_cars"),
download_otx_model(client, otx_models_dir, "cls_efficient_v2s_cars"),
download_otx_model(client, otx_models_dir, "Lite-hrnet-18"),
download_otx_model(client, otx_models_dir, "Lite-hrnet-18_mod2"),
download_otx_model(client, otx_models_dir, "Lite-hrnet-s_mod2"),
download_otx_model(client, otx_models_dir, "Lite-hrnet-s_mod2", "onnx"),
download_otx_model(client, otx_models_dir, "Lite-hrnet-x-mod3"),
download_otx_model(
client, otx_models_dir, "is_efficientnetb2b_maskrcnn_coco_reduced"
),
download_otx_model(
client,
otx_models_dir,
"is_efficientnetb2b_maskrcnn_coco_reduced_onnx",
"onnx",
),
download_otx_model(
client, otx_models_dir, "is_resnet50_maskrcnn_coco_reduced"
),
download_otx_model(client, otx_models_dir, "mobilenet_v3_large_hc_cf"),
download_otx_model(
client, otx_models_dir, "classification_model_with_xai_head"
),
download_otx_model(client, otx_models_dir, "detection_model_with_xai_head"),
download_otx_model(
client, otx_models_dir, "segmentation_model_with_xai_head"
),
download_otx_model(client, otx_models_dir, "maskrcnn_model_with_xai_head"),
download_otx_model(client, otx_models_dir, "maskrcnn_xai_tiling"),
download_otx_model(client, otx_models_dir, "tile_classifier"),
download_otx_model(client, otx_models_dir, "anomaly_padim_bottle_mvtec"),
download_otx_model(client, otx_models_dir, "anomaly_stfpm_bottle_mvtec"),
download_otx_model(client, otx_models_dir, "deit-tiny"),
download_otx_model(
client, otx_models_dir, "cls_efficient_b0_shuffled_outputs"
),
download_otx_model(client, otx_models_dir, "action_cls_xd3_kinetic"),
download_otx_model(client, otx_models_dir, "sam_vit_b_zsl_encoder"),
download_otx_model(client, otx_models_dir, "sam_vit_b_zsl_decoder"),
download_otx_model(client, otx_models_dir, "rtmpose_tiny"),
download_otx_model(client, otx_models_dir, "segnext_t_tiling"),
)
if __name__ == "__main__":
asyncio.run(main())