rogermt commited on
Commit
23347ef
·
verified ·
1 Parent(s): ea33d55

V67 fix: tasks 176/292 remove fixed_shapes (variable widths, verified 25/25+28/28), task 315 Gather replaces Resize (onnx_tool crash), task 339 remove fixed_shapes (arc-gen variable)

Browse files
own-solver/neurogolf_solver/solvers/wave8.py CHANGED
@@ -1,458 +1 @@
1
- #!/usr/bin/env python3
2
- """Wave 8: More reverse-engineered solvers from submission-5743.
3
-
4
- Tasks targeted (ALL genuinely unsolved in V65):
5
- - s_fill_mask_delta: Task 176 — fill specific spatial positions with delta color (3x25)
6
- - s_recolor_col_mask: Task 292 — recolor channel 4 at columnar mask positions (3x20)
7
- - s_palette_lookup_markers: Task 262 — look up palette from column position of markers (3x3)
8
- - s_count_dominant_bar: Task 339 — count non-bg pixels, output bar of dominant color (3x3→1x9)
9
- - s_maxpool_3x3_downsample: Task 130 — MaxPool 3x3 stride 3 downsample (9x9→3x3)
10
- - s_tile_mask_color2: Task 315 — tile 3x3→9x9, mask by color 2 presence
11
- - s_matmul_projection: Task 296 — MatMul projection from 5x7→3x3
12
- - s_count_colors_pattern_bank: Task 61 — count colors 4-9 present → modular pattern (18x18)
13
-
14
- Architecture source: submission-5743.zip (LB leader)
15
- All architectures validated: 50/50 exact match on random inputs.
16
- NOTE: Minimal detection — build unconditionally, let validate() filter.
17
-
18
- V66 fixes:
19
- - Task 315: Replaced Resize with Gather-based 3x upscale (onnx_tool crashes on ResizeNode)
20
- - Task 339: Removed fixed_shapes() gate — arc-gen has variable sizes, check first examples only
21
- """
22
-
23
- import numpy as np
24
- from onnx import helper as oh, numpy_helper as onh, TensorProto
25
- from ..data_loader import get_exs, fixed_shapes
26
-
27
-
28
- def s_fill_mask_delta(td):
29
- """Task 176: At hardcoded spatial mask positions in a 3x25 grid,
30
- convert bg (color 0) to color 4.
31
-
32
- Architecture: Slice(3x25) -> Conv1x1(sum all channels) -> Mul(mask) -> Mul(delta_ch) -> Add -> Pad
33
- """
34
- exs = get_exs(td)
35
- if len(exs) < 2:
36
- return None
37
- sp = fixed_shapes(td)
38
- if sp is None:
39
- return None
40
- (IH, IW), (OH, OW) = sp
41
- if IH != 3 or IW != 25 or OH != 3 or OW != 25:
42
- return None
43
-
44
- MASK = np.array([
45
- [0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0],
46
- [1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1],
47
- [1,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1]
48
- ], dtype=np.float32).reshape(1, 1, 3, 25)
49
-
50
- delta_ch = np.zeros((1, 10, 1, 1), dtype=np.float32)
51
- delta_ch[0, 0, 0, 0] = -1.0
52
- delta_ch[0, 4, 0, 0] = 1.0
53
-
54
- Wall = np.ones((1, 10, 1, 1), dtype=np.float32)
55
-
56
- inits = [
57
- onh.from_array(Wall, 'Wall'),
58
- onh.from_array(MASK, 'MASK'),
59
- onh.from_array(delta_ch, 'delta_ch'),
60
- onh.from_array(np.array([0, 0, 0, 0], dtype=np.int64), 'crop_starts'),
61
- onh.from_array(np.array([1, 10, 3, 25], dtype=np.int64), 'crop_ends'),
62
- onh.from_array(np.array([0, 1, 2, 3], dtype=np.int64), 'crop_axes'),
63
- onh.from_array(np.array([1, 1, 1, 1], dtype=np.int64), 'crop_steps'),
64
- onh.from_array(np.array([0, 0, 0, 0, 0, 0, 27, 5], dtype=np.int64), 'pad_to_external'),
65
- onh.from_array(np.float32(0.0), 'pad_zero'),
66
- ]
67
-
68
- nodes = [
69
- oh.make_node('Slice', ['input', 'crop_starts', 'crop_ends', 'crop_axes', 'crop_steps'], ['input_inner']),
70
- oh.make_node('Conv', ['input_inner', 'Wall'], ['inside'], kernel_shape=[1, 1], pads=[0, 0, 0, 0]),
71
- oh.make_node('Mul', ['MASK', 'inside'], ['efmask']),
72
- oh.make_node('Mul', ['efmask', 'delta_ch'], ['delta']),
73
- oh.make_node('Add', ['input_inner', 'delta'], ['output_inner']),
74
- oh.make_node('Pad', ['output_inner', 'pad_to_external', 'pad_zero'], ['output']),
75
- ]
76
-
77
- x = oh.make_tensor_value_info('input', TensorProto.FLOAT, [1, 10, 30, 30])
78
- y = oh.make_tensor_value_info('output', TensorProto.FLOAT, [1, 10, 30, 30])
79
- g = oh.make_graph(nodes, 'g', [x], [y], initializer=inits)
80
- return oh.make_model(g, ir_version=8, opset_imports=[oh.make_opsetid('', 11)])
81
-
82
-
83
- def s_recolor_col_mask(td):
84
- """Task 292: At every-3rd-column positions in a 3x20 grid,
85
- recolor color 4 -> color 6.
86
-
87
- Architecture: Slice(3x20) -> Conv1x1(select ch4) -> Mul(col_mask) -> Conv1x1(recolor 4->6) -> Add -> Pad
88
- """
89
- exs = get_exs(td)
90
- if len(exs) < 2:
91
- return None
92
- sp = fixed_shapes(td)
93
- if sp is None:
94
- return None
95
- (IH, IW), (OH, OW) = sp
96
- if IH != 3 or IW != 20 or OH != 3 or OW != 20:
97
- return None
98
-
99
- w_ch4 = np.zeros((1, 10, 1, 1), dtype=np.float32)
100
- w_ch4[0, 4, 0, 0] = 1.0
101
-
102
- col_mask = np.zeros((1, 1, 3, 20), dtype=np.float32)
103
- for c in range(0, 20, 3):
104
- col_mask[0, 0, :, c] = 1.0
105
-
106
- w_paint = np.zeros((10, 1, 1, 1), dtype=np.float32)
107
- w_paint[4, 0, 0, 0] = -1.0
108
- w_paint[6, 0, 0, 0] = 1.0
109
-
110
- inits = [
111
- onh.from_array(w_ch4, 'w_ch4'),
112
- onh.from_array(col_mask, 'col_mask'),
113
- onh.from_array(w_paint, 'w_paint'),
114
- onh.from_array(np.array([0, 0, 0, 0], dtype=np.int64), 'crop_starts'),
115
- onh.from_array(np.array([1, 10, 3, 20], dtype=np.int64), 'crop_ends'),
116
- onh.from_array(np.array([0, 1, 2, 3], dtype=np.int64), 'crop_axes'),
117
- onh.from_array(np.array([1, 1, 1, 1], dtype=np.int64), 'crop_steps'),
118
- onh.from_array(np.array([0, 0, 0, 0, 0, 0, 27, 10], dtype=np.int64), 'pad_to_external'),
119
- onh.from_array(np.float32(0.0), 'pad_zero'),
120
- ]
121
-
122
- nodes = [
123
- oh.make_node('Slice', ['input', 'crop_starts', 'crop_ends', 'crop_axes', 'crop_steps'], ['input_inner']),
124
- oh.make_node('Conv', ['input_inner', 'w_ch4'], ['mask4'], kernel_shape=[1, 1], pads=[0, 0, 0, 0]),
125
- oh.make_node('Mul', ['mask4', 'col_mask'], ['convert']),
126
- oh.make_node('Conv', ['convert', 'w_paint'], ['paint'], kernel_shape=[1, 1], pads=[0, 0, 0, 0]),
127
- oh.make_node('Add', ['input_inner', 'paint'], ['output_inner']),
128
- oh.make_node('Pad', ['output_inner', 'pad_to_external', 'pad_zero'], ['output']),
129
- ]
130
-
131
- x = oh.make_tensor_value_info('input', TensorProto.FLOAT, [1, 10, 30, 30])
132
- y = oh.make_tensor_value_info('output', TensorProto.FLOAT, [1, 10, 30, 30])
133
- g = oh.make_graph(nodes, 'g', [x], [y], initializer=inits)
134
- return oh.make_model(g, ir_version=8, opset_imports=[oh.make_opsetid('', 11)])
135
-
136
-
137
- def s_palette_lookup_markers(td):
138
- """Task 262: Look up palette from column positions of color-5 markers.
139
-
140
- Input: 3x3 grid with color-5 markers (one per row).
141
- For each row, the column where the marker is indexes into palette [2,4,3].
142
- Output: 3x3 grid where each row is filled with the looked-up color.
143
- """
144
- exs = get_exs(td)
145
- if len(exs) < 2:
146
- return None
147
- sp = fixed_shapes(td)
148
- if sp is None:
149
- return None
150
- (IH, IW), (OH, OW) = sp
151
- if IH != 3 or IW != 3 or OH != 3 or OW != 3:
152
- return None
153
-
154
- inits = [
155
- onh.from_array(np.array([5, 0, 0], dtype=np.int64), 'starts'),
156
- onh.from_array(np.array([6, 3, 3], dtype=np.int64), 'ends'),
157
- onh.from_array(np.array([1, 2, 3], dtype=np.int64), 'axes'),
158
- onh.from_array(np.array([1, 1, 1], dtype=np.int64), 'steps'),
159
- onh.from_array(np.array([1], dtype=np.int64), 'squeeze_axes'),
160
- onh.from_array(np.array([2, 4, 3], dtype=np.int64), 'palette'),
161
- onh.from_array(np.array([2], dtype=np.int64), 'unsqueeze_axes'),
162
- onh.from_array(np.array([1, 3, 3], dtype=np.int64), 'tile_shape'),
163
- onh.from_array(np.array([0, 0, 0, 0, 27, 27], dtype=np.int64), 'pads'),
164
- onh.from_array(np.array(10, dtype=np.int64), 'pad_value'),
165
- onh.from_array(np.array(10, dtype=np.int64), 'depth'),
166
- onh.from_array(np.array([0.0, 1.0], dtype=np.float32), 'onehot_values'),
167
- ]
168
-
169
- nodes = [
170
- oh.make_node('Slice', ['input', 'starts', 'ends', 'axes', 'steps'], ['marker']),
171
- oh.make_node('ArgMax', ['marker'], ['col_with_5'], axis=3, keepdims=0),
172
- oh.make_node('Squeeze', ['col_with_5', 'squeeze_axes'], ['row_col']),
173
- oh.make_node('Gather', ['palette', 'row_col'], ['row_labels'], axis=0),
174
- oh.make_node('Unsqueeze', ['row_labels', 'unsqueeze_axes'], ['row_labels_col']),
175
- oh.make_node('Expand', ['row_labels_col', 'tile_shape'], ['labels_3x3']),
176
- oh.make_node('Pad', ['labels_3x3', 'pads', 'pad_value'], ['labels_30x30']),
177
- oh.make_node('OneHot', ['labels_30x30', 'depth', 'onehot_values'], ['output'], axis=1),
178
- ]
179
-
180
- x = oh.make_tensor_value_info('input', TensorProto.FLOAT, [1, 10, 30, 30])
181
- y = oh.make_tensor_value_info('output', TensorProto.FLOAT, [1, 10, 30, 30])
182
- g = oh.make_graph(nodes, 'g', [x], [y], initializer=inits)
183
- return oh.make_model(g, ir_version=8, opset_imports=[oh.make_opsetid('', 16)])
184
-
185
-
186
- def s_count_dominant_bar(td):
187
- """Task 339: Count non-bg pixels in 3x3 grid, find dominant color,
188
- output 1x9 bar filled with that color for 'count' cells.
189
-
190
- NOTE: Does NOT use fixed_shapes() because arc-gen has variable sizes.
191
- Gates on first few train+test examples having 3x3 input and 1x9 output.
192
- validate() handles the rest.
193
- """
194
- exs = get_exs(td)
195
- if len(exs) < 2:
196
- return None
197
-
198
- # Check that examples have 3x3 -> 1x9 shape (don't require ALL to match)
199
- for inp, out in exs[:3]:
200
- if inp.shape != (3, 3) or out.shape != (1, 9):
201
- return None
202
-
203
- mask_bank = np.zeros((9, 1, 1, 9), dtype=np.float32)
204
- for i in range(9):
205
- mask_bank[i, 0, 0, :i+1] = 1.0
206
-
207
- inits = [
208
- onh.from_array(np.array([1, 0, 0], dtype=np.int64), 'starts'),
209
- onh.from_array(np.array([10, 3, 3], dtype=np.int64), 'ends'),
210
- onh.from_array(np.array([1, 2, 3], dtype=np.int64), 'axes'),
211
- onh.from_array(np.array([1, 1, 1], dtype=np.int64), 'steps'),
212
- onh.from_array(np.array([1], dtype=np.int64), 'one'),
213
- onh.from_array(np.array([2, 3], dtype=np.int64), 'spatial_axes'),
214
- onh.from_array(np.array(10, dtype=np.int64), 'depth'),
215
- onh.from_array(np.array([0.0, 1.0], dtype=np.float32), 'hot_values'),
216
- onh.from_array(mask_bank, 'mask_bank'),
217
- onh.from_array(np.array([0, 0, 0, 0, 0, 0, 29, 21], dtype=np.int64), 'pads'),
218
- onh.from_array(np.float32(0.0), 'pad_value'),
219
- ]
220
-
221
- nodes = [
222
- oh.make_node('Slice', ['input', 'starts', 'ends', 'axes', 'steps'], ['colored']),
223
- oh.make_node('ReduceSum', ['colored', 'axes'], ['count_float'], keepdims=0),
224
- oh.make_node('Cast', ['count_float'], ['count_i64'], to=TensorProto.INT64),
225
- oh.make_node('Sub', ['count_i64', 'one'], ['count_index']),
226
- oh.make_node('ReduceSum', ['colored', 'spatial_axes'], ['color_counts'], keepdims=0),
227
- oh.make_node('ArgMax', ['color_counts'], ['color_index0'], axis=1, keepdims=0),
228
- oh.make_node('Add', ['color_index0', 'one'], ['color_index']),
229
- oh.make_node('OneHot', ['color_index', 'depth', 'hot_values'], ['color_hot_2d'], axis=1),
230
- oh.make_node('Unsqueeze', ['color_hot_2d', 'spatial_axes'], ['color_hot']),
231
- oh.make_node('Gather', ['mask_bank', 'count_index'], ['count_mask'], axis=0),
232
- oh.make_node('Mul', ['color_hot', 'count_mask'], ['small_output']),
233
- oh.make_node('Pad', ['small_output', 'pads', 'pad_value'], ['output']),
234
- ]
235
-
236
- x = oh.make_tensor_value_info('input', TensorProto.FLOAT, [1, 10, 30, 30])
237
- y = oh.make_tensor_value_info('output', TensorProto.FLOAT, [1, 10, 30, 30])
238
- g = oh.make_graph(nodes, 'g', [x], [y], initializer=inits)
239
- return oh.make_model(g, ir_version=8, opset_imports=[oh.make_opsetid('', 16)])
240
-
241
-
242
- def s_maxpool_3x3_downsample(td):
243
- """Task 130: Crop 9x9, MaxPool 3x3 stride 3 -> 3x3 output.
244
- Skip channels 0 and 5 for the pool, reconstruct bg from absence.
245
- """
246
- exs = get_exs(td)
247
- if len(exs) < 2:
248
- return None
249
- sp = fixed_shapes(td)
250
- if sp is None:
251
- return None
252
- (IH, IW), (OH, OW) = sp
253
- if IH != 9 or IW != 9 or OH != 3 or OW != 3:
254
- return None
255
-
256
- v4 = np.zeros((10, 8, 1, 1), dtype=np.float32)
257
- orig_colors = [1, 2, 3, 4, 6, 7, 8, 9]
258
- for in_ch, out_color in enumerate(orig_colors):
259
- v4[out_color, in_ch, 0, 0] = 1.0
260
-
261
- v2 = np.zeros((1, 10, 1, 1), dtype=np.float32)
262
- v2[0, 0, 0, 0] = 1.0
263
-
264
- inits = [
265
- onh.from_array(np.arange(9, dtype=np.int64), 'v0'),
266
- onh.from_array(np.array([1, 2, 3, 4, 6, 7, 8, 9], dtype=np.int64), 'v1'),
267
- onh.from_array(v2, 'v2'),
268
- onh.from_array(np.array([1.0], dtype=np.float32), 'v3'),
269
- onh.from_array(v4, 'v4'),
270
- ]
271
-
272
- nodes = [
273
- oh.make_node('Gather', ['input', 'v0'], ['v5'], axis=2),
274
- oh.make_node('Gather', ['v5', 'v0'], ['v6'], axis=3),
275
- oh.make_node('MaxPool', ['v6'], ['v7'], kernel_shape=[3, 3], strides=[3, 3]),
276
- oh.make_node('Gather', ['v7', 'v1'], ['v8'], axis=1),
277
- oh.make_node('ReduceMax', ['v8'], ['v9'], axes=[1], keepdims=1),
278
- oh.make_node('Sub', ['v3', 'v9'], ['v10']),
279
- oh.make_node('Conv', ['v8', 'v4'], ['v11'], kernel_shape=[1, 1], pads=[0, 0, 0, 0]),
280
- oh.make_node('Mul', ['v10', 'v2'], ['v12']),
281
- oh.make_node('Add', ['v11', 'v12'], ['v13']),
282
- oh.make_node('Pad', ['v13'], ['output'], pads=[0, 0, 0, 0, 0, 0, 27, 27], value=0.0),
283
- ]
284
-
285
- x = oh.make_tensor_value_info('input', TensorProto.FLOAT, [1, 10, 30, 30])
286
- y = oh.make_tensor_value_info('output', TensorProto.FLOAT, [1, 10, 30, 30])
287
- g = oh.make_graph(nodes, 'g', [x], [y], initializer=inits)
288
- return oh.make_model(g, ir_version=8, opset_imports=[oh.make_opsetid('', 10)])
289
-
290
-
291
- def s_tile_mask_color2(td):
292
- """Task 315: Tile 3x3 grid -> 9x9, masked by where color 2 appears.
293
-
294
- Uses Gather-based 3x nearest-neighbor upscale (NOT Resize — onnx_tool crashes on Resize).
295
- Architecture: Slice(3x3) -> Tile(3x3) -> extract ch2 -> Gather(upscale) ->
296
- Slice(ch1-9) -> Mul(mask) -> ReduceMax -> Sub -> Concat -> Pad
297
- """
298
- exs = get_exs(td)
299
- if len(exs) < 2:
300
- return None
301
- sp = fixed_shapes(td)
302
- if sp is None:
303
- return None
304
- (IH, IW), (OH, OW) = sp
305
- if IH != 3 or IW != 3 or OH != 9 or OW != 9:
306
- return None
307
-
308
- # Upscale indices: each pixel repeated 3 times
309
- up3 = np.array([0, 0, 0, 1, 1, 1, 2, 2, 2], dtype=np.int64)
310
-
311
- inits = [
312
- onh.from_array(np.ones((1, 1, 9, 9), dtype=np.float32), 'ones_9'),
313
- onh.from_array(np.array([1], dtype=np.int64), 'ax1'),
314
- onh.from_array(np.array([2, 3], dtype=np.int64), 'ax23'),
315
- onh.from_array(np.array([0, 0], dtype=np.int64), 's00'),
316
- onh.from_array(np.array([3, 3], dtype=np.int64), 's33'),
317
- onh.from_array(np.array([2], dtype=np.int64), 's2'),
318
- onh.from_array(np.array([3], dtype=np.int64), 's3'),
319
- onh.from_array(np.array([10], dtype=np.int64), 's10'),
320
- onh.from_array(np.array([1, 1, 3, 3], dtype=np.int64), 'tile33'),
321
- onh.from_array(up3, 'up3'),
322
- ]
323
-
324
- nodes = [
325
- oh.make_node('Slice', ['input', 's00', 's33', 'ax23'], ['inp3']),
326
- oh.make_node('Tile', ['inp3', 'tile33'], ['tiled9']),
327
- oh.make_node('Slice', ['inp3', 's2', 's3', 'ax1'], ['c2_3']),
328
- # Gather-based 3x nearest-neighbor upscale (replaces Resize)
329
- oh.make_node('Gather', ['c2_3', 'up3'], ['c2_up_h'], axis=2),
330
- oh.make_node('Gather', ['c2_up_h', 'up3'], ['mask9'], axis=3),
331
- oh.make_node('Slice', ['tiled9', 'ax1', 's10', 'ax1'], ['tiled_c1_9']),
332
- oh.make_node('Mul', ['tiled_c1_9', 'mask9'], ['colored_c1_9']),
333
- oh.make_node('ReduceMax', ['colored_c1_9'], ['col_pres'], axes=[1], keepdims=1),
334
- oh.make_node('Sub', ['ones_9', 'col_pres'], ['c0_9']),
335
- oh.make_node('Concat', ['c0_9', 'colored_c1_9'], ['out_9'], axis=1),
336
- oh.make_node('Pad', ['out_9'], ['output'], pads=[0, 0, 0, 0, 0, 0, 21, 21], value=0.0),
337
- ]
338
-
339
- x = oh.make_tensor_value_info('input', TensorProto.FLOAT, [1, 10, 30, 30])
340
- y = oh.make_tensor_value_info('output', TensorProto.FLOAT, [1, 10, 30, 30])
341
- g = oh.make_graph(nodes, 'g', [x], [y], initializer=inits)
342
- return oh.make_model(g, ir_version=8, opset_imports=[oh.make_opsetid('', 10)])
343
-
344
-
345
- def s_matmul_projection(td):
346
- """Task 296: Project flattened 5x7 non-bg channels through a fixed matrix to get 3x3 output."""
347
- exs = get_exs(td)
348
- if len(exs) < 2:
349
- return None
350
- sp = fixed_shapes(td)
351
- if sp is None:
352
- return None
353
- (IH, IW), (OH, OW) = sp
354
- if IH != 5 or IW != 7 or OH != 3 or OW != 3:
355
- return None
356
-
357
- projection = np.array([
358
- [1,0,0,0,0,0,0,0,0], [0,1,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0],
359
- [0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0], [0,1,0,0,0,0,0,0,0],
360
- [0,0,1,0,0,0,0,0,0], [0,0,0,1,0,0,0,0,0], [0,0,0,0,1,0,0,0,0],
361
- [0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0],
362
- [0,0,0,0,1,0,0,0,0], [0,0,0,0,0,1,0,0,0], [0,0,0,0,0,0,0,0,0],
363
- [0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0],
364
- [0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0],
365
- [0,0,0,1,0,0,0,0,0], [0,0,0,0,1,0,0,0,0], [0,0,0,0,0,0,0,0,0],
366
- [0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0], [0,0,0,0,1,0,0,0,0],
367
- [0,0,0,0,0,1,0,0,0], [0,0,0,0,0,0,1,0,0], [0,0,0,0,0,0,0,1,0],
368
- [0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0],
369
- [0,0,0,0,0,0,0,1,0], [0,0,0,0,0,0,0,0,1],
370
- ], dtype=np.float32)
371
-
372
- inits = [
373
- onh.from_array(np.array([1, 0, 0], dtype=np.int64), 'starts'),
374
- onh.from_array(np.array([10, 5, 7], dtype=np.int64), 'ends'),
375
- onh.from_array(np.array([1, 2, 3], dtype=np.int64), 'axes'),
376
- onh.from_array(np.array([1, 1, 1], dtype=np.int64), 'steps'),
377
- onh.from_array(np.array([1, 9, 35], dtype=np.int64), 'flat_shape'),
378
- onh.from_array(projection, 'projection'),
379
- onh.from_array(np.float32(0.0), 'zero'),
380
- onh.from_array(np.array([1, 9, 3, 3], dtype=np.int64), 'color_shape'),
381
- onh.from_array(np.array([1], dtype=np.int64), 'channel_axis'),
382
- onh.from_array(np.ones((1, 1, 3, 3), dtype=np.float32), 'ones3'),
383
- onh.from_array(np.array([0, 0, 0, 0, 0, 0, 27, 27], dtype=np.int64), 'pads'),
384
- onh.from_array(np.float32(0.0), 'pad_value'),
385
- ]
386
-
387
- nodes = [
388
- oh.make_node('Slice', ['input', 'starts', 'ends', 'axes', 'steps'], ['patch']),
389
- oh.make_node('Reshape', ['patch', 'flat_shape'], ['flat']),
390
- oh.make_node('MatMul', ['flat', 'projection'], ['folded_counts']),
391
- oh.make_node('Greater', ['folded_counts', 'zero'], ['folded_bool']),
392
- oh.make_node('Reshape', ['folded_bool', 'color_shape'], ['color_output_pre_bool']),
393
- oh.make_node('Cast', ['color_output_pre_bool'], ['color_output'], to=TensorProto.FLOAT),
394
- oh.make_node('ReduceSum', ['color_output', 'channel_axis'], ['occupancy'], keepdims=1),
395
- oh.make_node('Sub', ['ones3', 'occupancy'], ['zero_channel']),
396
- oh.make_node('Concat', ['zero_channel', 'color_output'], ['small_output'], axis=1),
397
- oh.make_node('Pad', ['small_output', 'pads', 'pad_value'], ['output']),
398
- ]
399
-
400
- x = oh.make_tensor_value_info('input', TensorProto.FLOAT, [1, 10, 30, 30])
401
- y = oh.make_tensor_value_info('output', TensorProto.FLOAT, [1, 10, 30, 30])
402
- g = oh.make_graph(nodes, 'g', [x], [y], initializer=inits)
403
- return oh.make_model(g, ir_version=8, opset_imports=[oh.make_opsetid('', 16)])
404
-
405
-
406
- def s_count_colors_pattern_bank(td):
407
- """Task 61: Count how many of colors 4-9 are present -> lookup pattern from bank.
408
- Input: 18x18 grid. Output: 18x18 modular multiplication table pattern.
409
- """
410
- exs = get_exs(td)
411
- if len(exs) < 2:
412
- return None
413
- sp = fixed_shapes(td)
414
- if sp is None:
415
- return None
416
- (IH, IW), (OH, OW) = sp
417
- if IH != 18 or IW != 18 or OH != 18 or OW != 18:
418
- return None
419
-
420
- label_bank = np.zeros((6, 18, 18), dtype=np.int64)
421
- for n in range(6):
422
- period = n + 4
423
- for i in range(18):
424
- for j in range(18):
425
- label_bank[n, i, j] = (i * j) % period + 1
426
-
427
- inits = [
428
- onh.from_array(np.array([4, 0, 0], dtype=np.int64), 'starts'),
429
- onh.from_array(np.array([10, 18, 18], dtype=np.int64), 'ends'),
430
- onh.from_array(np.array([1, 2, 3], dtype=np.int64), 'axes'),
431
- onh.from_array(np.array([1, 1, 1], dtype=np.int64), 'steps'),
432
- onh.from_array(np.array([2, 3], dtype=np.int64), 'spatial_axes'),
433
- onh.from_array(np.float32(0.0), 'zero'),
434
- onh.from_array(np.array([1], dtype=np.int64), 'color_axis'),
435
- onh.from_array(label_bank, 'label_bank'),
436
- onh.from_array(np.array(10, dtype=np.int64), 'depth'),
437
- onh.from_array(np.array([0.0, 1.0], dtype=np.float32), 'onehot_values'),
438
- onh.from_array(np.array([0, 0, 0, 0, 0, 0, 12, 12], dtype=np.int64), 'pads'),
439
- onh.from_array(np.float32(0.0), 'pad_value'),
440
- ]
441
-
442
- nodes = [
443
- oh.make_node('Slice', ['input', 'starts', 'ends', 'axes', 'steps'], ['colored']),
444
- oh.make_node('ReduceSum', ['colored', 'spatial_axes'], ['color_counts'], keepdims=0),
445
- oh.make_node('Greater', ['color_counts', 'zero'], ['present_bool']),
446
- oh.make_node('Cast', ['present_bool'], ['present_f'], to=TensorProto.FLOAT),
447
- oh.make_node('ReduceSum', ['present_f', 'color_axis'], ['n_colors_f'], keepdims=0),
448
- oh.make_node('Cast', ['n_colors_f'], ['n_colors_i'], to=TensorProto.INT64),
449
- oh.make_node('Sub', ['n_colors_i', 'color_axis'], ['bank_idx']),
450
- oh.make_node('Gather', ['label_bank', 'bank_idx'], ['labels_2d'], axis=0),
451
- oh.make_node('OneHot', ['labels_2d', 'depth', 'onehot_values'], ['small_output'], axis=1),
452
- oh.make_node('Pad', ['small_output', 'pads', 'pad_value'], ['output']),
453
- ]
454
-
455
- x = oh.make_tensor_value_info('input', TensorProto.FLOAT, [1, 10, 30, 30])
456
- y = oh.make_tensor_value_info('output', TensorProto.FLOAT, [1, 10, 30, 30])
457
- g = oh.make_graph(nodes, 'g', [x], [y], initializer=inits)
458
- return oh.make_model(g, ir_version=8, opset_imports=[oh.make_opsetid('', 16)])
 
1
+ /app/wave8_upload.py