Example #1
0
	def getTemplates(self):
		""" Chip out the templates """
		for maps in self.info:
			# Determine if it's an H1 or an H0 template
			if maps['class'] == 'H1':
				P, freqs, bins = self.train.H1Sample(maps['file'],params=self.params)
			else:
				P, freqs, bins = self.train.H0Sample(maps['file'],params=self.params)

			# Get the image and demean it
			m, n = P.shape
			P = metrics.slidingWindowV(P,maxM=m)
			x0, xn, y0, yn = maps['x0'], maps['xn'], maps['y0'], maps['yn']
			tmpl = P[x0:xn,y0:yn].astype('Float32')

			# Normalize the image and turn into a binary mask
			m_, s_ = np.mean(tmpl), np.std(tmpl)
			min_ = tmpl.min()
			tmpl[ tmpl < m_ + 0.5*s_] = min_ 
			tmpl[ tmpl > min_ ] = 1
			tmpl[tmpl < 0] = 0

			# Add meta-data to the list
			self.templates.append(tmpl)
			m, n = tmpl.shape
			self.limits.append([bins[y0], bins[yn], freqs[x0], freqs[xn]])
Example #2
0
    def getTemplates(self):
        """ Chip out the templates """
        for maps in self.info:
            # Determine if it's an H1 or an H0 template
            if maps['class'] == 'H1':
                P, freqs, bins = self.train.H1Sample(maps['file'],
                                                     params=self.params)
            else:
                P, freqs, bins = self.train.H0Sample(maps['file'],
                                                     params=self.params)

            # Get the image and demean it
            m, n = P.shape
            P = metrics.slidingWindowV(P, maxM=m)
            x0, xn, y0, yn = maps['x0'], maps['xn'], maps['y0'], maps['yn']
            tmpl = P[x0:xn, y0:yn].astype('Float32')

            # Normalize the image and turn into a binary mask
            m_, s_ = np.mean(tmpl), np.std(tmpl)
            min_ = tmpl.min()
            tmpl[tmpl < m_ + 0.5 * s_] = min_
            tmpl[tmpl > min_] = 1
            tmpl[tmpl < 0] = 0

            # Add meta-data to the list
            self.templates.append(tmpl)
            m, n = tmpl.shape
            self.limits.append([bins[y0], bins[yn], freqs[x0], freqs[xn]])
import metrics
import fileio
import numpy
from matplotlib import mlab, pyplot as plt
import pandas

df = pandas.DataFrame(
    numpy.zeros(30000 * 5901).reshape(30000, 5901), columns=(["label"] + map(lambda a: str(a), range(100 * 59)))
)

labels = pandas.read_csv("../data/train.csv")

for i in range(30000):
    img = fileio.ReadAIFF("../data/train/train{}.aiff".format(i + 1))
    P, freqs, bins = mlab.specgram(img, NFFT=256, Fs=2000, noverlap=192)
    Q = metrics.slidingWindowV(P, inner=3, maxM=40)
    W = metrics.slidingWindowH(P, inner=3, outer=32, maxM=60)
    s = numpy.vstack((Q, W))
    df.ix[i] = numpy.append(labels["label"][i], s.reshape(100 * 59))
    if i % 100 == 0:
        print i
df.to_csv("total.csv", index=False)
Example #4
0
def slidingWindowV(img):
    w = metrics.slidingWindowV(img, inner=3, maxM=40)
    print w.shape
    return w