Skip to content

Commit

Permalink
generate the gabor specs in loop showing more combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
rohrlich committed Feb 18, 2022
1 parent 441591e commit 686a7c1
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions examples/processspeech/processspeech.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,40 +141,43 @@ func (sp *SndProcess) Config() {
sp.Segment = -1
sp.MoreSegments = true

sp.GaborSpecs = nil // in case there are some specs already
spec := agabor.Filter{WaveLen: 2.0, Orientation: 0, SigmaWidth: 0.6, SigmaLength: 0.2, PhaseOffset: 0, CircleEdge: true}
sp.GaborSpecs = append(sp.GaborSpecs, spec)
spec = agabor.Filter{WaveLen: 2.0, Orientation: 0, SigmaWidth: 0.6, SigmaLength: 0.2, PhaseOffset: 1.5708, CircleEdge: true}
sp.GaborSpecs = append(sp.GaborSpecs, spec)
spec = agabor.Filter{WaveLen: 2.0, Orientation: 45, SigmaWidth: 0.3, SigmaLength: 0.6, PhaseOffset: 0, CircleEdge: true}
sp.GaborSpecs = append(sp.GaborSpecs, spec)
spec = agabor.Filter{WaveLen: 2.0, Orientation: 90, SigmaWidth: 0.3, SigmaLength: 0.6, PhaseOffset: 0, CircleEdge: true}
sp.GaborSpecs = append(sp.GaborSpecs, spec)
spec = agabor.Filter{WaveLen: 2.0, Orientation: 135, SigmaWidth: 0.3, SigmaLength: 0.6, PhaseOffset: 0, CircleEdge: true}
sp.GaborSpecs = append(sp.GaborSpecs, spec)
// and a circular one - orientation, phase and sigmaLength will be ignored if specified
spec = agabor.Filter{WaveLen: 2.0, SigmaWidth: 0.5, Circular: true}
sp.GaborSpecs = append(sp.GaborSpecs, spec)

// filter size is assumed to be consistent and taken from first in the spec list
sp.GaborFilters.SizeX = 7
sp.GaborFilters.SizeY = 7
sp.GaborFilters.SizeX = 15
sp.GaborFilters.SizeY = 15
sp.GaborFilters.StrideX = 3
sp.GaborFilters.StrideY = 3
sp.GaborFilters.Gain = 2
sp.GaborFilters.Distribute = false // the 0 orientation filters will both be centered
x := sp.GaborFilters.SizeX
y := sp.GaborFilters.SizeY
n := len(sp.GaborSpecs)
sp.GaborFilters.Filters.SetShape([]int{n, y, x}, nil, nil)

// for orientation 0 (horiz) length is height as you view the filter
sp.GaborSpecs = nil // in case there are some specs already

i := 0
var w float32
var l float32
orient := []float32{0, 45, 90, 135}
wavelen := []float32{2.0}
phase := []float32{0, 1.5708}

for _, or := range orient {
for _, wl := range wavelen {
for _, ph := range phase {
for i, w, l = 0, 0.25, 0.25; i < 2; i, w, l = i+1, w+w*2, l+l*2 {
spec := agabor.Filter{WaveLen: wl, Orientation: or, SigmaWidth: w, SigmaLength: l, PhaseOffset: ph, CircleEdge: true}
sp.GaborSpecs = append(sp.GaborSpecs, spec)
}
}
}
}

sp.GaborFilters.Filters.SetShape([]int{len(sp.GaborSpecs), sp.GaborFilters.SizeY, sp.GaborFilters.SizeX}, nil, nil)
agabor.ToTensor(sp.GaborSpecs, &sp.GaborFilters)
sp.GaborFilters.ToTable(sp.GaborFilters, &sp.GaborTab) // note: view only, testing

tmp := sp.Params.SegmentSteps - sp.GaborFilters.SizeX
tsrX := tmp/sp.GaborFilters.StrideX + 1
tmp = sp.Mel.FBank.NFilters - sp.GaborFilters.SizeY
tsrY := tmp/sp.GaborFilters.StrideY + 1
sp.GaborTsr.SetShape([]int{sp.Sound.Channels(), tsrY, tsrX, 2, n}, nil, nil)
sp.GaborTsr.SetShape([]int{sp.Sound.Channels(), tsrY, tsrX, 2, len(sp.GaborSpecs)}, nil, nil)
sp.GaborTsr.SetMetaData("odd-row", "true")
sp.GaborTsr.SetMetaData("grid-fill", ".9")

Expand Down

0 comments on commit 686a7c1

Please sign in to comment.