Doubled-angle orientation order pooling / custom_orientation_lines.py

Failed on benchmark

Raw ⬇ ZIP
 1"""Structurally matched custom track: classify unoriented line orientation."""
 2import numpy as np
 3META = {"name":"oriented_line_quotient", "domain":"vision_orientation", "description":"Small grayscale/RGB images containing apolar lines; classify their half-circle orientation bin."}
 4
 5def get_dataset(seed, n_train, n_test):
 6    def make(n, s):
 7        rng=np.random.RandomState(s); H=W=16
 8        x=np.zeros((n,3,H,W),np.float32); y=np.empty(n,np.int64)
 9        yy,xx=np.mgrid[0:H,0:W].astype(np.float32); cx=cy=7.5
10        for i in range(n):
11            a=rng.uniform(0,np.pi); u=np.array([np.cos(a),np.sin(a)])
12            # distance to an unoriented line through the center
13            d=-(xx-cx)*u[1]+(yy-cy)*u[0]
14            along=(xx-cx)*u[0]+(yy-cy)*u[1]
15            img=np.exp(-(d*d)/1.1)*np.exp(-(along*along)/90.0)
16            img += rng.normal(0,.035,(H,W)).astype(np.float32)
17            img=np.clip(img,0,1)
18            x[i]=img[None,:,:]
19            x[i,1]=img; x[i,2]=img
20            y[i]=int((a/np.pi*4)%4)
21        return x,y
22    xtr,ytr=make(n_train,seed); xte,yte=make(n_test,seed+5000)
23    return {"xtr":xtr,"ytr":ytr,"xte":xte,"yte":yte,"task":"classification","metric":"err","out_dim":4}