mirror of
https://github.com/HumanAIGC/lite-avatar.git
synced 2026-02-05 18:09:20 +08:00
add files
This commit is contained in:
0
funasr_local/export/test/__init__.py
Normal file
0
funasr_local/export/test/__init__.py
Normal file
20
funasr_local/export/test/test_onnx.py
Normal file
20
funasr_local/export/test/test_onnx.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import onnxruntime
|
||||
import numpy as np
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
onnx_path = "/mnt/workspace/export/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch/model.onnx"
|
||||
sess = onnxruntime.InferenceSession(onnx_path)
|
||||
input_name = [nd.name for nd in sess.get_inputs()]
|
||||
output_name = [nd.name for nd in sess.get_outputs()]
|
||||
|
||||
def _get_feed_dict(feats_length):
|
||||
return {'speech': np.zeros((1, feats_length, 560), dtype=np.float32), 'speech_lengths': np.array([feats_length,], dtype=np.int32)}
|
||||
|
||||
def _run(feed_dict):
|
||||
output = sess.run(output_name, input_feed=feed_dict)
|
||||
for name, value in zip(output_name, output):
|
||||
print('{}: {}'.format(name, value.shape))
|
||||
|
||||
_run(_get_feed_dict(100))
|
||||
_run(_get_feed_dict(200))
|
||||
18
funasr_local/export/test/test_onnx_punc.py
Normal file
18
funasr_local/export/test/test_onnx_punc.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import onnxruntime
|
||||
import numpy as np
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
onnx_path = "../damo/punc_ct-transformer_zh-cn-common-vocab272727-pytorch/model.onnx"
|
||||
sess = onnxruntime.InferenceSession(onnx_path)
|
||||
input_name = [nd.name for nd in sess.get_inputs()]
|
||||
output_name = [nd.name for nd in sess.get_outputs()]
|
||||
|
||||
def _get_feed_dict(text_length):
|
||||
return {'inputs': np.ones((1, text_length), dtype=np.int64), 'text_lengths': np.array([text_length,], dtype=np.int32)}
|
||||
|
||||
def _run(feed_dict):
|
||||
output = sess.run(output_name, input_feed=feed_dict)
|
||||
for name, value in zip(output_name, output):
|
||||
print('{}: {}'.format(name, value))
|
||||
_run(_get_feed_dict(10))
|
||||
22
funasr_local/export/test/test_onnx_punc_vadrealtime.py
Normal file
22
funasr_local/export/test/test_onnx_punc_vadrealtime.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import onnxruntime
|
||||
import numpy as np
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
onnx_path = "./export/damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727/model.onnx"
|
||||
sess = onnxruntime.InferenceSession(onnx_path)
|
||||
input_name = [nd.name for nd in sess.get_inputs()]
|
||||
output_name = [nd.name for nd in sess.get_outputs()]
|
||||
|
||||
def _get_feed_dict(text_length):
|
||||
return {'inputs': np.ones((1, text_length), dtype=np.int64),
|
||||
'text_lengths': np.array([text_length,], dtype=np.int32),
|
||||
'vad_masks': np.ones((1, 1, text_length, text_length), dtype=np.float32),
|
||||
'sub_masks': np.tril(np.ones((text_length, text_length), dtype=np.float32))[None, None, :, :].astype(np.float32)
|
||||
}
|
||||
|
||||
def _run(feed_dict):
|
||||
output = sess.run(output_name, input_feed=feed_dict)
|
||||
for name, value in zip(output_name, output):
|
||||
print('{}: {}'.format(name, value))
|
||||
_run(_get_feed_dict(10))
|
||||
26
funasr_local/export/test/test_onnx_vad.py
Normal file
26
funasr_local/export/test/test_onnx_vad.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import onnxruntime
|
||||
import numpy as np
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
onnx_path = "/mnt/workspace/export/damo/speech_fsmn_vad_zh-cn-16k-common-pytorch/model.onnx"
|
||||
sess = onnxruntime.InferenceSession(onnx_path)
|
||||
input_name = [nd.name for nd in sess.get_inputs()]
|
||||
output_name = [nd.name for nd in sess.get_outputs()]
|
||||
|
||||
def _get_feed_dict(feats_length):
|
||||
|
||||
return {'speech': np.random.rand(1, feats_length, 400).astype(np.float32),
|
||||
'in_cache0': np.random.rand(1, 128, 19, 1).astype(np.float32),
|
||||
'in_cache1': np.random.rand(1, 128, 19, 1).astype(np.float32),
|
||||
'in_cache2': np.random.rand(1, 128, 19, 1).astype(np.float32),
|
||||
'in_cache3': np.random.rand(1, 128, 19, 1).astype(np.float32),
|
||||
}
|
||||
|
||||
def _run(feed_dict):
|
||||
output = sess.run(output_name, input_feed=feed_dict)
|
||||
for name, value in zip(output_name, output):
|
||||
print('{}: {}'.format(name, value.shape))
|
||||
|
||||
_run(_get_feed_dict(100))
|
||||
_run(_get_feed_dict(200))
|
||||
17
funasr_local/export/test/test_torchscripts.py
Normal file
17
funasr_local/export/test/test_torchscripts.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import torch
|
||||
import numpy as np
|
||||
|
||||
if __name__ == '__main__':
|
||||
onnx_path = "/nfs/zhifu.gzf/export/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch/model.torchscripts"
|
||||
loaded = torch.jit.load(onnx_path)
|
||||
|
||||
x = torch.rand([2, 21, 560])
|
||||
x_len = torch.IntTensor([6, 21])
|
||||
res = loaded(x, x_len)
|
||||
print(res[0].size(), res[1])
|
||||
|
||||
x = torch.rand([5, 50, 560])
|
||||
x_len = torch.IntTensor([6, 21, 10, 30, 50])
|
||||
res = loaded(x, x_len)
|
||||
print(res[0].size(), res[1])
|
||||
|
||||
Reference in New Issue
Block a user