From ed3d7d300041737ee347d01c05259801adfa8fdd Mon Sep 17 00:00:00 2001 From: David Mayerich Date: Wed, 9 Aug 2017 17:35:09 -0500 Subject: [PATCH] updated NWT file format --- python/classify.py | 6 ++++-- python/envi.py | 11 +++++++---- stim/biomodels/nwt_format.pptx | Bin 95513 -> 0 bytes 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/python/classify.py b/python/classify.py index a1f672c..f3b2d6b 100644 --- a/python/classify.py +++ b/python/classify.py @@ -171,6 +171,7 @@ def envi_batch_predict(E, C, batch=10000): plt.ion() bar = progressbar.ProgressBar(max_value=numpy.count_nonzero(E.mask)) while not Fv == []: + Fv = numpy.nan_to_num(Fv) #remove infinite values if i == 0: Tv = C.predict(Fv.transpose()) else: @@ -181,6 +182,7 @@ def envi_batch_predict(E, C, batch=10000): RGB = class2color(Cv) plt.imshow(RGB) plt.pause(0.05) - Fv = E.loadbatch(batch) + Fv = E.loadbatch(batch) i = i + 1 - bar.update(len(Tv)) \ No newline at end of file + bar.update(len(Tv)) + return RGB \ No newline at end of file diff --git a/python/envi.py b/python/envi.py index e624d60..47dbefa 100644 --- a/python/envi.py +++ b/python/envi.py @@ -187,8 +187,10 @@ class envi: self.open(filename, headername) if mask == []: self.mask = numpy.ones((self.header.lines, self.header.samples), dtype=numpy.bool) - else: + elif type(mask) == numpy.ndarray: self.mask = mask + else: + print("ERROR: unrecognized mask format - expecting a boolean array") self.idx = 0 #initialize the batch IDX to 0 for batch reading def open(self, filename, headername = ""): @@ -287,7 +289,8 @@ class envi: #input: envi file object, stack of class masks C x Y x X #output: feature matrix (features x pixels), target matrix (1 x pixels) #example: generate_training(("class_coll.bmp", "class_epith.bmp"), (1, 2)) - def loadtrain(self, classimages): + # verify verify that there are no NaN or Inf values + def loadtrain(self, classimages, verify=True): # get number of classes C = classimages.shape[0] @@ -300,8 +303,8 @@ class envi: t = numpy.ones((f.shape[1])) * (c+1) #generate a target array F.append(f) T.append(t) - - return numpy.concatenate(F, 1).transpose(), numpy.concatenate(T) + + return numpy.nan_to_num(numpy.concatenate(F, 1).transpose()), numpy.concatenate(T) #read a batch of data based on the mask def loadbatch(self, npixels): diff --git a/stim/biomodels/nwt_format.pptx b/stim/biomodels/nwt_format.pptx index 6f3e0da..8433105 100644 Binary files a/stim/biomodels/nwt_format.pptx and b/stim/biomodels/nwt_format.pptx differ -- libgit2 0.21.4