Exemple #1
0
func (phi *ConvEach) Apply(x *rimg64.Multi) (*rimg64.Multi, error) {
	channels := x.Channels * len(phi.Filters.Filters)
	field := image.Pt(phi.Filters.Width, phi.Filters.Height)
	size := slide.ValidSize(x.Size(), field)
	y := rimg64.NewMulti(size.X, size.Y, channels)
	var n int
	for i := 0; i < x.Channels; i++ {
		// Convolve each channel of the input with the bank.
		yi, err := slide.CorrBankBLAS(x.Channel(i), phi.Filters)
		if err != nil {
			return nil, err
		}
		for j := 0; j < yi.Channels; j++ {
			// Copy the channels into the output.
			y.SetChannel(n, yi.Channel(j))
			n++
		}
	}
	return y, nil
}
Exemple #2
0
func TestCorrBankBLAS_vsNaive(t *testing.T) {
	const (
		m      = 40
		n      = 30
		w      = 100
		h      = 80
		numOut = 6
		eps    = 1e-9
	)
	f := randImage(w, h)
	g := randBank(w, h, numOut)
	naive, err := slide.CorrBankNaive(f, g)
	if err != nil {
		t.Fatal(err)
	}
	blas, err := slide.CorrBankBLAS(f, g)
	if err != nil {
		t.Fatal(err)
	}
	if err := errIfNotEqMulti(naive, blas, eps); err != nil {
		t.Fatal(err)
	}
}