Commit ed3d7d300041737ee347d01c05259801adfa8fdd

Authored by David Mayerich
1 parent eccf10ff

updated NWT file format

python/classify.py
@@ -171,6 +171,7 @@ def envi_batch_predict(E, C, batch=10000): @@ -171,6 +171,7 @@ def envi_batch_predict(E, C, batch=10000):
171 plt.ion() 171 plt.ion()
172 bar = progressbar.ProgressBar(max_value=numpy.count_nonzero(E.mask)) 172 bar = progressbar.ProgressBar(max_value=numpy.count_nonzero(E.mask))
173 while not Fv == []: 173 while not Fv == []:
  174 + Fv = numpy.nan_to_num(Fv) #remove infinite values
174 if i == 0: 175 if i == 0:
175 Tv = C.predict(Fv.transpose()) 176 Tv = C.predict(Fv.transpose())
176 else: 177 else:
@@ -181,6 +182,7 @@ def envi_batch_predict(E, C, batch=10000): @@ -181,6 +182,7 @@ def envi_batch_predict(E, C, batch=10000):
181 RGB = class2color(Cv) 182 RGB = class2color(Cv)
182 plt.imshow(RGB) 183 plt.imshow(RGB)
183 plt.pause(0.05) 184 plt.pause(0.05)
184 - Fv = E.loadbatch(batch) 185 + Fv = E.loadbatch(batch)
185 i = i + 1 186 i = i + 1
186 - bar.update(len(Tv))  
187 \ No newline at end of file 187 \ No newline at end of file
  188 + bar.update(len(Tv))
  189 + return RGB
188 \ No newline at end of file 190 \ No newline at end of file
@@ -187,8 +187,10 @@ class envi: @@ -187,8 +187,10 @@ class envi:
187 self.open(filename, headername) 187 self.open(filename, headername)
188 if mask == []: 188 if mask == []:
189 self.mask = numpy.ones((self.header.lines, self.header.samples), dtype=numpy.bool) 189 self.mask = numpy.ones((self.header.lines, self.header.samples), dtype=numpy.bool)
190 - else: 190 + elif type(mask) == numpy.ndarray:
191 self.mask = mask 191 self.mask = mask
  192 + else:
  193 + print("ERROR: unrecognized mask format - expecting a boolean array")
192 self.idx = 0 #initialize the batch IDX to 0 for batch reading 194 self.idx = 0 #initialize the batch IDX to 0 for batch reading
193 195
194 def open(self, filename, headername = ""): 196 def open(self, filename, headername = ""):
@@ -287,7 +289,8 @@ class envi: @@ -287,7 +289,8 @@ class envi:
287 #input: envi file object, stack of class masks C x Y x X 289 #input: envi file object, stack of class masks C x Y x X
288 #output: feature matrix (features x pixels), target matrix (1 x pixels) 290 #output: feature matrix (features x pixels), target matrix (1 x pixels)
289 #example: generate_training(("class_coll.bmp", "class_epith.bmp"), (1, 2)) 291 #example: generate_training(("class_coll.bmp", "class_epith.bmp"), (1, 2))
290 - def loadtrain(self, classimages): 292 + # verify verify that there are no NaN or Inf values
  293 + def loadtrain(self, classimages, verify=True):
291 294
292 # get number of classes 295 # get number of classes
293 C = classimages.shape[0] 296 C = classimages.shape[0]
@@ -300,8 +303,8 @@ class envi: @@ -300,8 +303,8 @@ class envi:
300 t = numpy.ones((f.shape[1])) * (c+1) #generate a target array 303 t = numpy.ones((f.shape[1])) * (c+1) #generate a target array
301 F.append(f) 304 F.append(f)
302 T.append(t) 305 T.append(t)
303 -  
304 - return numpy.concatenate(F, 1).transpose(), numpy.concatenate(T) 306 +
  307 + return numpy.nan_to_num(numpy.concatenate(F, 1).transpose()), numpy.concatenate(T)
305 308
306 #read a batch of data based on the mask 309 #read a batch of data based on the mask
307 def loadbatch(self, npixels): 310 def loadbatch(self, npixels):
stim/biomodels/nwt_format.pptx
No preview for this file type