wangli commited on
update py scripts and axcl x86 lib
Browse files- .gitattributes +1 -0
- install/lib/axcl_x86/libyoloworld.so +2 -2
- pyyoloworld/__pycache__/pyaxdev.cpython-310.pyc +0 -0
- pyyoloworld/__pycache__/pyyoloworld.cpython-310.pyc +0 -0
- pyyoloworld/example.py +8 -0
- pyyoloworld/gradio_example.py +35 -12
- pyyoloworld/libyoloworld.so +3 -0
- pyyoloworld/pyyoloworld.py +1 -1
.gitattributes
CHANGED
|
@@ -46,3 +46,4 @@ result.png filter=lfs diff=lfs merge=lfs -text
|
|
| 46 |
host.jpg filter=lfs diff=lfs merge=lfs -text
|
| 47 |
result_axcl.png filter=lfs diff=lfs merge=lfs -text
|
| 48 |
result_host.jpg filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 46 |
host.jpg filter=lfs diff=lfs merge=lfs -text
|
| 47 |
result_axcl.png filter=lfs diff=lfs merge=lfs -text
|
| 48 |
result_host.jpg filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
pyyoloworld/libyoloworld.so filter=lfs diff=lfs merge=lfs -text
|
install/lib/axcl_x86/libyoloworld.so
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b6eaf2e52ce0de74de782b85b07163b5089c4e48ac77843349fc06152987c77a
|
| 3 |
+
size 5534896
|
pyyoloworld/__pycache__/pyaxdev.cpython-310.pyc
ADDED
|
Binary file (4.44 kB). View file
|
|
|
pyyoloworld/__pycache__/pyyoloworld.cpython-310.pyc
ADDED
|
Binary file (4.1 kB). View file
|
|
|
pyyoloworld/example.py
CHANGED
|
@@ -16,20 +16,28 @@ if __name__ == '__main__':
|
|
| 16 |
|
| 17 |
|
| 18 |
# 枚举设备
|
|
|
|
|
|
|
| 19 |
devices_info = enum_devices()
|
| 20 |
print("可用设备:", devices_info)
|
| 21 |
if devices_info['host']['available']:
|
| 22 |
print("host device available")
|
| 23 |
sys_init(AxDeviceType.host_device, -1)
|
|
|
|
|
|
|
| 24 |
elif devices_info['devices']['count'] > 0:
|
| 25 |
print("axcl device available, use device-0")
|
| 26 |
sys_init(AxDeviceType.axcl_device, 0)
|
|
|
|
|
|
|
| 27 |
else:
|
| 28 |
raise Exception("No available device")
|
| 29 |
|
| 30 |
try:
|
| 31 |
# 创建CLIP实例
|
| 32 |
yw = YOLOWORLD({
|
|
|
|
|
|
|
| 33 |
'text_encoder_path': args.tenc,
|
| 34 |
'tokenizer_path': args.vocab,
|
| 35 |
'yoloworld_path': args.yoloworld,
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
# 枚举设备
|
| 19 |
+
dev_type = AxDeviceType.unknown_device
|
| 20 |
+
dev_id = -1
|
| 21 |
devices_info = enum_devices()
|
| 22 |
print("可用设备:", devices_info)
|
| 23 |
if devices_info['host']['available']:
|
| 24 |
print("host device available")
|
| 25 |
sys_init(AxDeviceType.host_device, -1)
|
| 26 |
+
dev_type = AxDeviceType.host_device
|
| 27 |
+
dev_id = -1
|
| 28 |
elif devices_info['devices']['count'] > 0:
|
| 29 |
print("axcl device available, use device-0")
|
| 30 |
sys_init(AxDeviceType.axcl_device, 0)
|
| 31 |
+
dev_type = AxDeviceType.axcl_device
|
| 32 |
+
dev_id = 0
|
| 33 |
else:
|
| 34 |
raise Exception("No available device")
|
| 35 |
|
| 36 |
try:
|
| 37 |
# 创建CLIP实例
|
| 38 |
yw = YOLOWORLD({
|
| 39 |
+
'dev_type': dev_type,
|
| 40 |
+
'devid': dev_id,
|
| 41 |
'text_encoder_path': args.tenc,
|
| 42 |
'tokenizer_path': args.vocab,
|
| 43 |
'yoloworld_path': args.yoloworld,
|
pyyoloworld/gradio_example.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
import colorsys
|
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import cv2
|
| 4 |
from pyaxdev import enum_devices, sys_init, sys_deinit, AxDeviceType
|
|
@@ -12,29 +14,47 @@ parser = argparse.ArgumentParser()
|
|
| 12 |
parser.add_argument('--yoloworld', type=str, default='cnclip/cnclip_vit_l14_336px_vision_u16u8.axmodel')
|
| 13 |
parser.add_argument('--tenc', type=str, default='cnclip/cnclip_vit_l14_336px_text_u16.axmodel')
|
| 14 |
parser.add_argument('--vocab', type=str, default='cnclip/cn_vocab.txt')
|
| 15 |
-
parser.add_argument('--dev_type', type=str, default='host', choices=['host', 'axcl'])
|
| 16 |
args = parser.parse_args()
|
| 17 |
|
| 18 |
# ========== 模型和设备初始化 ==========
|
|
|
|
|
|
|
| 19 |
devices_info = enum_devices()
|
| 20 |
-
|
| 21 |
if devices_info['host']['available']:
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
elif devices_info['devices']['count'] > 0:
|
|
|
|
| 26 |
sys_init(AxDeviceType.axcl_device, 0)
|
| 27 |
-
|
| 28 |
-
|
| 29 |
else:
|
| 30 |
raise Exception("No available device")
|
| 31 |
|
| 32 |
yw = YOLOWORLD({
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
def generate_vivid_colors(n):
|
| 40 |
colors = []
|
|
@@ -102,5 +122,8 @@ with gr.Blocks() as demo:
|
|
| 102 |
outputs=image_output
|
| 103 |
)
|
| 104 |
|
|
|
|
|
|
|
|
|
|
| 105 |
# ========== 启动 ==========
|
| 106 |
demo.launch(server_name="0.0.0.0")
|
|
|
|
| 1 |
import colorsys
|
| 2 |
+
import re
|
| 3 |
+
import subprocess
|
| 4 |
import gradio as gr
|
| 5 |
import cv2
|
| 6 |
from pyaxdev import enum_devices, sys_init, sys_deinit, AxDeviceType
|
|
|
|
| 14 |
parser.add_argument('--yoloworld', type=str, default='cnclip/cnclip_vit_l14_336px_vision_u16u8.axmodel')
|
| 15 |
parser.add_argument('--tenc', type=str, default='cnclip/cnclip_vit_l14_336px_text_u16.axmodel')
|
| 16 |
parser.add_argument('--vocab', type=str, default='cnclip/cn_vocab.txt')
|
|
|
|
| 17 |
args = parser.parse_args()
|
| 18 |
|
| 19 |
# ========== 模型和设备初始化 ==========
|
| 20 |
+
dev_type = AxDeviceType.unknown_device
|
| 21 |
+
dev_id = -1
|
| 22 |
devices_info = enum_devices()
|
| 23 |
+
print("可用设备:", devices_info)
|
| 24 |
if devices_info['host']['available']:
|
| 25 |
+
print("host device available")
|
| 26 |
+
sys_init(AxDeviceType.host_device, -1)
|
| 27 |
+
dev_type = AxDeviceType.host_device
|
| 28 |
+
dev_id = -1
|
| 29 |
elif devices_info['devices']['count'] > 0:
|
| 30 |
+
print("axcl device available, use device-0")
|
| 31 |
sys_init(AxDeviceType.axcl_device, 0)
|
| 32 |
+
dev_type = AxDeviceType.axcl_device
|
| 33 |
+
dev_id = 0
|
| 34 |
else:
|
| 35 |
raise Exception("No available device")
|
| 36 |
|
| 37 |
yw = YOLOWORLD({
|
| 38 |
+
'dev_type': dev_type,
|
| 39 |
+
'devid': dev_id,
|
| 40 |
+
'text_encoder_path': args.tenc,
|
| 41 |
+
'tokenizer_path': args.vocab,
|
| 42 |
+
'yoloworld_path': args.yoloworld,
|
| 43 |
+
})
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def get_all_local_ips():
|
| 47 |
+
result = subprocess.run(['ip', 'a'], capture_output=True, text=True)
|
| 48 |
+
output = result.stdout
|
| 49 |
+
|
| 50 |
+
# 匹配所有IPv4
|
| 51 |
+
ips = re.findall(r'inet (\d+\.\d+\.\d+\.\d+)', output)
|
| 52 |
+
|
| 53 |
+
# 过滤掉回环地址
|
| 54 |
+
real_ips = [ip for ip in ips if not ip.startswith('127.')]
|
| 55 |
+
|
| 56 |
+
return real_ips
|
| 57 |
+
|
| 58 |
|
| 59 |
def generate_vivid_colors(n):
|
| 60 |
colors = []
|
|
|
|
| 122 |
outputs=image_output
|
| 123 |
)
|
| 124 |
|
| 125 |
+
ips = get_all_local_ips()
|
| 126 |
+
for ip in ips:
|
| 127 |
+
print(f"* Running on local URL: http://{ip}:7860")
|
| 128 |
# ========== 启动 ==========
|
| 129 |
demo.launch(server_name="0.0.0.0")
|
pyyoloworld/libyoloworld.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b6eaf2e52ce0de74de782b85b07163b5089c4e48ac77843349fc06152987c77a
|
| 3 |
+
size 5534896
|
pyyoloworld/pyyoloworld.py
CHANGED
|
@@ -71,7 +71,7 @@ class YOLOWORLD:
|
|
| 71 |
self.init_info = YWInit()
|
| 72 |
|
| 73 |
# 设置初始化参数
|
| 74 |
-
self.init_info.dev_type = init_info.get('dev_type', AxDeviceType.
|
| 75 |
self.init_info.devid = init_info.get('devid', 0)
|
| 76 |
self.init_info.threshold = init_info.get('threshold', 0.1)
|
| 77 |
|
|
|
|
| 71 |
self.init_info = YWInit()
|
| 72 |
|
| 73 |
# 设置初始化参数
|
| 74 |
+
self.init_info.dev_type = init_info.get('dev_type', AxDeviceType.axcl_device)
|
| 75 |
self.init_info.devid = init_info.get('devid', 0)
|
| 76 |
self.init_info.threshold = init_info.get('threshold', 0.1)
|
| 77 |
|