Skip to content

Commit 8fc7aa4

Browse files
committed
Merge branch 4.x
2 parents af30797 + e0fd79b commit 8fc7aa4

18 files changed

+160
-5
lines changed
Loading
Loading

testdata/cv/mcc/mcc_ccm_test.jpg

72 KB
Loading

testdata/cv/mcc/mcc_ccm_test.yml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
%YAML:1.0
2+
---
3+
Macbeth_corners: [ 2.51388901e+02, 9.04293518e+01, 6.18812256e+02,
4+
9.31525421e+01, 6.40433594e+02, 3.47054962e+02, 2.34627167e+02,
5+
3.43148376e+02 ]
6+
chartsRGB: !!opencv-matrix
7+
rows: 72
8+
cols: 5
9+
dt: d
10+
data: [ 770., 9.7018181818181816e+01, 9.4645301922076519e-01, 95.,
11+
105., 770., 8.0824675324675326e+01, 1.1595628200085211e+00, 77.,
12+
87., 770., 5.3563636363636363e+01, 3.9092600386245806e+00, 42.,
13+
73., 798., 1.6569423558897242e+02, 9.7035861631224973e-01, 163.,
14+
169., 798., 1.3274310776942355e+02, 1.0188309020321478e+00, 130.,
15+
136., 798., 1.1540100250626566e+02, 2.0155035683620337e+00, 110.,
16+
126., 784., 8.2394132653061220e+01, 1.1851617743507668e+00, 78.,
17+
87., 784., 9.5862244897959172e+01, 1.1883374860876685e+00, 92.,
18+
99., 784., 1.2781377551020407e+02, 1.6244352332909029e+00, 122.,
19+
133., 770., 8.0270129870129864e+01, 1.4241940017300359e+00, 75.,
20+
85., 770., 1.0111298701298702e+02, 1.3537682520831342e+00, 96.,
21+
105., 770., 6.5819480519480521e+01, 3.9673845276050486e+00, 52.,
22+
94., 784., 1.1550765306122447e+02, 1.0773373271034734e+00, 113.,
23+
118., 784., 1.0674362244897958e+02, 1.0273480523763854e+00, 104.,
24+
110., 784., 1.4758545918367346e+02, 1.4233270858221301e+00, 143.,
25+
153., 783., 8.9015325670498086e+01, 1.8088105968192547e+00, 84.,
26+
96., 783., 1.5520561941251597e+02, 1.1798084539336262e+00, 152.,
27+
159., 783., 1.6633205619412516e+02, 1.3521967319711203e+00, 162.,
28+
170., 826., 1.7623728813559322e+02, 1.0562230700190447e+00, 171.,
29+
179., 826., 1.3204358353510898e+02, 1.8067773247212249e+00, 118.,
30+
138., 826., 3.6970944309927361e+01, 8.1682743222591547e+00, 9.,
31+
122., 842., 5.3210213776722092e+01, 1.6060278974867714e+00, 47.,
32+
60., 842., 5.7219714964370546e+01, 1.3923581440906183e+00, 54.,
33+
63., 842., 1.2389192399049882e+02, 1.8954768899411336e+00, 119.,
34+
131., 841., 1.6775148632580260e+02, 9.5875752068363906e-01, 164.,
35+
170., 841., 9.6422116527942919e+01, 9.3367991507067238e-01, 92.,
36+
100., 841., 7.7549346016646837e+01, 2.9950816084097802e+00, 67.,
37+
96., 841., 7.2869203329369796e+01, 1.3971315808677551e+00, 69.,
38+
83., 841., 5.8565992865636140e+01, 1.2426178667841234e+00, 55.,
39+
63., 841., 8.1378121284185482e+01, 2.3599304267415597e+00, 75.,
40+
91., 839., 1.3092252681764003e+02, 1.4074398956166911e+00, 125.,
41+
136., 839., 1.7468295589988080e+02, 1.2398172946695771e+00, 169.,
42+
178., 839., 8.6032181168057207e+01, 3.9496429597484721e+00, 72.,
43+
114., 841., 2.0054696789536266e+02, 1.0404396126431092e+00, 196.,
44+
203., 841., 1.7241379310344826e+02, 1.1332190844963712e+00, 167.,
45+
177., 841., 6.2807372175980973e+01, 4.6513131247204011e+00, 43.,
46+
95., 885., 2.9964971751412431e+01, 1.7963912740189363e+00, 24.,
47+
40., 885., 3.4445197740112995e+01, 1.5450274129158603e+00, 29.,
48+
43., 885., 9.7777401129943513e+01, 1.8567780923662216e+00, 92.,
49+
111., 886., 4.8639954853273132e+01, 2.0862187808505608e+00, 41.,
50+
56., 886., 1.1998081264108352e+02, 1.2144139102806220e+00, 115.,
51+
124., 886., 7.5695259593679452e+01, 3.7958216439826575e+00, 61.,
52+
93., 915., 1.4989726775956285e+02, 1.2291287817720791e+00, 146.,
53+
155., 915., 7.6278688524590166e+01, 1.4249664654205476e+00, 69.,
54+
82., 915., 5.0009836065573772e+01, 5.0767778899235987e+00, 33.,
55+
84., 870., 1.9989655172413794e+02, 1.1114294695204852e+00, 196.,
56+
204., 870., 1.9029655172413794e+02, 1.5600949187039233e+00, 180.,
57+
194., 870., 7.5060919540229889e+01, 4.8815593966427304e+00, 56.,
58+
122., 915., 1.5694754098360656e+02, 1.1247255729473995e+00, 154.,
59+
160., 915., 9.1795628415300541e+01, 1.1253572662403217e+00, 88.,
60+
95., 915., 1.2020765027322405e+02, 1.5627307079811592e+00, 115.,
61+
128., 899., 2.7309232480533925e+01, 3.0567552009661569e+00, 18.,
62+
37., 899., 9.4481646273637381e+01, 1.6059009521768621e+00, 89.,
63+
102., 899., 1.4615127919911012e+02, 1.5754745842609790e+00, 141.,
64+
151., 946., 1.8069238900634249e+02, 1.1250958149684871e+00, 178.,
65+
184., 946., 1.8332875264270615e+02, 1.0619091706908901e+00, 181.,
66+
187., 946., 1.8893340380549682e+02, 1.3369067670391985e+00, 185.,
67+
193., 962., 1.5142203742203742e+02, 9.5569896195477178e-01, 148.,
68+
154., 962., 1.5618087318087319e+02, 9.8350642724810333e-01, 153.,
69+
159., 962., 1.6121621621621622e+02, 1.2811714311504592e+00, 157.,
70+
166., 976., 1.2489241803278689e+02, 1.0796667164870304e+00, 121.,
71+
131., 976., 1.3006967213114754e+02, 1.0631988035078002e+00, 125.,
72+
134., 976., 1.3304815573770492e+02, 1.4899721777609278e+00, 126.,
73+
140., 946., 9.7050739957716701e+01, 1.2180654271464280e+00, 93.,
74+
101., 946., 1.0161733615221988e+02, 1.0421739390034210e+00, 98.,
75+
106., 946., 1.0038372093023256e+02, 2.4446752125049676e+00, 91.,
76+
111., 977., 7.0025588536335718e+01, 1.1929339413930722e+00, 66.,
77+
74., 977., 7.4783009211873079e+01, 1.2924463457807394e+00, 69.,
78+
80., 977., 7.0187308085977477e+01, 3.3076200939718361e+00, 57.,
79+
91., 978., 4.6092024539877308e+01, 1.9601651028627682e+00, 39.,
80+
59., 978., 4.9716768916155424e+01, 1.7120244148104067e+00, 45.,
81+
57., 978., 3.6976482617586917e+01, 4.2491980598153010e+00, 22.,
82+
54. ]
83+
ccm: !!opencv-matrix
84+
rows: 3
85+
cols: 3
86+
dt: d
87+
data: [ 1.5716570001850085e+00, -2.8092439445926803e-01,
88+
8.4539221097703107e-02, -2.1945308390378220e-02,
89+
1.3776087064810523e+00, -1.8039879125793784e-01,
90+
-2.8439953579767585e-02, 3.0335314988002327e-01,
91+
1.4714738669924146e+00 ]

testdata/cv/mcc/mcc_ccm_test_res.png

468 KB
Loading

testdata/dnn/download_models.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -984,9 +984,20 @@ def is_archive(self):
984984
filename='onnx/models/yolov6n.onnx'),
985985
Model(
986986
name='yolov8n',
987-
url='https://dl.opencv.org/models/yolov8/yolov8n.onnx',
987+
url=[
988+
'https://huggingface.co/cabelo/yolov8/resolve/main/yolov8n.onnx?download=true',
989+
'https://dl.opencv.org/models/yolov8/yolov8n.onnx'
990+
],
988991
sha='136807b88d0b02bc226bdeb9741141d857752e10',
989992
filename='onnx/models/yolov8n.onnx'),
993+
Model(
994+
name='yolov8x',
995+
url=[
996+
'https://huggingface.co/cabelo/yolov8/resolve/main/yolov8x.onnx?download=true',
997+
'https://dl.opencv.org/models/yolov8/yolov8x.onnx'
998+
],
999+
sha='462f15d668c046d38e27d3df01fe8142dd004cb4',
1000+
filename='onnx/models/yolov8x.onnx'),
9901001

9911002
Model(
9921003
name='yolo_nas_s',
4.13 KB
Binary file not shown.
16.1 KB
Binary file not shown.

testdata/dnn/onnx/generate_onnx_models_with_onnxscript.py

+26
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
from onnxscript import opset11
77
from onnxscript import opset13
88

9+
###############
10+
### CAUTION!!!
11+
### Be sure to put constant numpy arrays out of @ost.script() decorated fucntion.
12+
### Otherwise random values change each time eager mode is enter.
13+
### See discussions in https://github.com/microsoft/onnxscript/issues/1313
14+
###############
15+
916
np.random.seed(0)
1017

1118
def make_model_and_data(model, *args, **kwargs):
@@ -339,3 +346,22 @@ def layer_norm_no_fusion(x: ost.FLOAT[n, c, h, w]) -> ost.FLOAT[n, c, h, w]:
339346

340347
return add
341348
make_model_and_data(layer_norm_no_fusion, np.random.rand(n, c, h, w).astype(np.float32))
349+
350+
351+
''' Subgraph: [Input] -> MatMul<B> -> Add<A> -> [Output]
352+
'''
353+
354+
b = 2
355+
m = 32
356+
n = 64
357+
k = 16
358+
weight_data = np.random.rand(k, n).astype(np.float32)
359+
bias_data = np.random.rand(n).astype(np.float32)
360+
361+
@ost.script()
362+
def biased_matmul(x: ost.FLOAT[b, m, k]) -> ost.FLOAT[b, m, n]:
363+
weight = op.Constant(value=onnx.helper.make_tensor("", onnx.TensorProto.FLOAT, [k, n], weight_data))
364+
matmul = op.MatMul(x, weight)
365+
bias = op.Constant(value=onnx.helper.make_tensor("", onnx.TensorProto.FLOAT, [n], bias_data))
366+
return op.Add(bias, matmul)
367+
make_model_and_data(biased_matmul, np.random.rand(b, m, k).astype(np.float32), use_ort=True, ort_input_keys=["x"])
4.58 KB
Binary file not shown.
956 Bytes
Binary file not shown.
136 Bytes
Binary file not shown.
Binary file not shown.

testdata/dnn/tflite/generate.py

+31-4
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,18 @@ def save_tflite_model(model, inp, name):
5252
converter = tf.lite.TFLiteConverter.from_concrete_functions([func])
5353
tflite_model = converter.convert()
5454

55-
interpreter = tf.lite.Interpreter(model_content=tflite_model)
56-
5755
with open(f'{name}.tflite', 'wb') as f:
5856
f.write(tflite_model)
5957

6058
out = model(inp)
59+
out = np.array(out)
60+
61+
if len(inp.shape) == 4:
62+
inp = inp.transpose(0, 3, 1, 2)
63+
out = out.transpose(0, 3, 1, 2)
6164

62-
np.save(f'{name}_inp.npy', inp.transpose(0, 3, 1, 2))
63-
np.save(f'{name}_out_Identity.npy', np.array(out).transpose(0, 3, 1, 2))
65+
np.save(f'{name}_inp.npy', inp)
66+
np.save(f'{name}_out_Identity.npy', out)
6467

6568

6669
@tf.function(input_signature=[tf.TensorSpec(shape=[1, 3, 3, 1], dtype=tf.float32)])
@@ -75,3 +78,27 @@ def replicate_by_pack(x):
7578
inp = np.random.standard_normal((1, 3, 3, 1)).astype(np.float32)
7679
save_tflite_model(replicate_by_pack, inp, 'replicate_by_pack')
7780

81+
@tf.function(input_signature=[tf.TensorSpec(shape=[1, 3], dtype=tf.float32)])
82+
def split(x):
83+
splitted = tf.split(
84+
x, 3, axis=-1, num=None, name='split'
85+
)
86+
return tf.concat((splitted[2], splitted[1], splitted[0]), axis=-1)
87+
88+
inp = np.random.standard_normal((1, 3)).astype(np.float32)
89+
save_tflite_model(split, inp, 'split')
90+
91+
92+
fully_connected = tf.keras.models.Sequential([
93+
tf.keras.layers.Dense(3),
94+
tf.keras.layers.ReLU(),
95+
tf.keras.layers.Softmax(),
96+
])
97+
98+
fully_connected = tf.function(
99+
fully_connected.call,
100+
input_signature=[tf.TensorSpec((1,2), tf.float32)],
101+
)
102+
103+
inp = np.random.standard_normal((1, 2)).astype(np.float32)
104+
save_tflite_model(fully_connected, inp, 'fully_connected')

testdata/dnn/tflite/split.tflite

1.04 KB
Binary file not shown.

testdata/dnn/tflite/split_inp.npy

140 Bytes
Binary file not shown.
140 Bytes
Binary file not shown.
11 KB
Loading

0 commit comments

Comments
 (0)