Skip to content

5.x merge 4.x #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions testdata/dnn/download_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,13 +963,12 @@ def is_archive(self):
sha='2b181b55d1d7af718eaca6cabdeb741217b64c73',
filename='wechat_2021-01/sr.caffemodel'),
Model(
name='yolov7_not_simplified',
name='yolov7',
url=[
'https://docs.google.com/uc?export=download&id=1ljSh81ydO5ylsnDoV_mt3zj5RX_cgLu8',
'https://dl.opencv.org/models/yolov7/yolov7_not_simplified.onnx'
'https://dl.opencv.org/models/yolov7/yolov7.onnx'
],
sha='fcd0fa401c83bf2b29e18239a9c2c989c9b8669d',
filename='onnx/models/yolov7_not_simplified.onnx'),
sha='9f5199c266418462771a26a7b8ea25a90412ce2e',
filename='onnx/models/yolov7.onnx'),
Model(
name='yolox_s_inf_decoder',
url=[
Expand All @@ -988,6 +987,13 @@ def is_archive(self):
url='https://dl.opencv.org/models/yolov8/yolov8n.onnx',
sha='136807b88d0b02bc226bdeb9741141d857752e10',
filename='onnx/models/yolov8n.onnx'),

Model(
name='yolo_nas_s',
url='https://dl.opencv.org/models/yolo-nas/yolo_nas_s.onnx',
sha='089942fbdf8591875a7a6ff10ac50fb6864e7aa4',
filename='onnx/models/yolo_nas_s.onnx'),

Model(
name='NanoTrackV1 (ONNX, backbone)',
url='https://raw.githubusercontent.com/zihaomu/opencv_extra_data_backup/main/NanoTrack/models/nanotrack_backbone_sim.onnx',
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BxJ�x��?h��>��z?�j@$ �?�.z��8s?b��hdӽ�9�>(�>�%�?^�B?�0�= B�>]ת>�=�?R�iJ�>�Z�/d#��S'?�K]?��=��C@�(��Hm;= �?�2�?��?��>���>�Ec������!��� >*z�?��?�Oƾmǚ��6��&õ�gڿ��?�x�FKྙ[��� G?
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BscaleJ4��Y�L=e��>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BbiasJ �����k��QN�>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BxJ�x��?h��>��z?�j@$ �?�.z��8s?b��hdӽ�9�>(�>�%�?^�B?�0�= B�>]ת>�=�?R�iJ�>�Z�/d#��S'?�K]?��=��C@�(��Hm;= �?�2�?��?��>���>�Ec������!��� >*z�?��?�Oƾmǚ��6��&õ�gڿ��?�x�FKྙ[��� G?
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BscaleJ4��Y�L=e��>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BbiasJ �����k��QN�>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ByJ��!�,�>>�(���)��N���K�����ew���?4U*=�?���:�2?��>�z�>@�>�D.��!о�u����>J�>�8������b��������?��>�� ?��G?86B?���>|��>�+?��@� Y�A\��}�����������U���z�>�
7?ڇo?Q�<#�>�W�>��&>T�V?
Binary file not shown.
Binary file not shown.
33 changes: 31 additions & 2 deletions testdata/dnn/onnx/generate_onnx_models_with_onnxscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import onnx
import onnxscript as ost
from onnxscript import opset19 as op # opset19 is the lastest by 202309
from onnxscript import opset11
from onnxscript import opset13

np.random.seed(0)

Expand Down Expand Up @@ -69,8 +71,6 @@ def greater_input_dtype_int64(x: ost.FLOAT[27, 9]) ->ost.BOOL[27, 9]:
return y
make_model_and_data(greater_input_dtype_int64, np.random.randint(0, 100, size=[27, 9], dtype=np.int64), force_saving_input_as_dtype_float32=True, force_saving_output_as_dtype_float32=True)

from onnxscript import opset11

@ost.script()
def two_resizes_with_shared_subgraphs(x: ost.FLOAT["batch", 1, "height", "width"], y: ost.FLOAT[1, 1, 3, 2], z: ost.FLOAT[1, 1, 2, 1]) ->ost.FLOAT["batch", 1, "height", "width"]:
shape_src_1 = opset11.Shape(x)
Expand Down Expand Up @@ -310,3 +310,32 @@ def einsum_const_inputs(input_0: ost.FLOAT[3, 2, 2, 4]) -> ost.FLOAT[3, 2, 2, 2]
return op.Einsum(input_0, input_1, equation="bhwc, hkc -> bhwk")

make_model_and_data(einsum_const_inputs, input_0_data)

''' This subgraph looks the same as LayerNorm expanded, but it has
axes=1 in ReduceMean which does not meet the requirement of LayerNorm:
- axes[-1] = -1 or the axis of last dimension
- adjacent axes, e.g. [1, 2, 3] or [-3, -2, -1]
'''

n = 1
c = 4
h = w = 8
mul_weight = np.random.rand(c, 1, 1).astype(np.float32)
add_weight = np.random.rand(c, 1, 1).astype(np.float32)

@ost.script()
def layer_norm_no_fusion(x: ost.FLOAT[n, c, h, w]) -> ost.FLOAT[n, c, h, w]:
reduce_mean = opset13.ReduceMean(x, axes=[1], keepdims=1)
sub = opset13.Sub(x, reduce_mean)

pow = opset13.Pow(sub, opset13.Constant(value=onnx.helper.make_tensor("", onnx.TensorProto.FLOAT, [], np.array([2], dtype=np.float32))))
reduce_mean_1 = opset13.ReduceMean(pow, axes=[1], keepdims=1)
add = opset13.Add(reduce_mean_1, opset13.Constant(value=onnx.helper.make_tensor("", onnx.TensorProto.FLOAT, [], np.array([9.999999974752427e-7], dtype=np.float32))))
sqrt = opset13.Sqrt(add)

div = opset13.Div(sub, sqrt)
mul = opset13.Mul(opset13.Constant(value=onnx.helper.make_tensor("", onnx.TensorProto.FLOAT, [c, 1, 1], mul_weight)), div)
add = opset13.Add(mul, opset13.Constant(value=onnx.helper.make_tensor("", onnx.TensorProto.FLOAT, [c, 1, 1], add_weight)))

return add
make_model_and_data(layer_norm_no_fusion, np.random.rand(n, c, h, w).astype(np.float32))
Binary file not shown.