Commit ed3d7d300041737ee347d01c05259801adfa8fdd
1 parent
eccf10ff
updated NWT file format
Showing
3 changed files
with
11 additions
and
6 deletions
Show diff stats
python/classify.py
... | ... | @@ -171,6 +171,7 @@ def envi_batch_predict(E, C, batch=10000): |
171 | 171 | plt.ion() |
172 | 172 | bar = progressbar.ProgressBar(max_value=numpy.count_nonzero(E.mask)) |
173 | 173 | while not Fv == []: |
174 | + Fv = numpy.nan_to_num(Fv) #remove infinite values | |
174 | 175 | if i == 0: |
175 | 176 | Tv = C.predict(Fv.transpose()) |
176 | 177 | else: |
... | ... | @@ -181,6 +182,7 @@ def envi_batch_predict(E, C, batch=10000): |
181 | 182 | RGB = class2color(Cv) |
182 | 183 | plt.imshow(RGB) |
183 | 184 | plt.pause(0.05) |
184 | - Fv = E.loadbatch(batch) | |
185 | + Fv = E.loadbatch(batch) | |
185 | 186 | i = i + 1 |
186 | - bar.update(len(Tv)) | |
187 | 187 | \ No newline at end of file |
188 | + bar.update(len(Tv)) | |
189 | + return RGB | |
188 | 190 | \ No newline at end of file | ... | ... |
python/envi.py
... | ... | @@ -187,8 +187,10 @@ class envi: |
187 | 187 | self.open(filename, headername) |
188 | 188 | if mask == []: |
189 | 189 | self.mask = numpy.ones((self.header.lines, self.header.samples), dtype=numpy.bool) |
190 | - else: | |
190 | + elif type(mask) == numpy.ndarray: | |
191 | 191 | self.mask = mask |
192 | + else: | |
193 | + print("ERROR: unrecognized mask format - expecting a boolean array") | |
192 | 194 | self.idx = 0 #initialize the batch IDX to 0 for batch reading |
193 | 195 | |
194 | 196 | def open(self, filename, headername = ""): |
... | ... | @@ -287,7 +289,8 @@ class envi: |
287 | 289 | #input: envi file object, stack of class masks C x Y x X |
288 | 290 | #output: feature matrix (features x pixels), target matrix (1 x pixels) |
289 | 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 | 295 | # get number of classes |
293 | 296 | C = classimages.shape[0] |
... | ... | @@ -300,8 +303,8 @@ class envi: |
300 | 303 | t = numpy.ones((f.shape[1])) * (c+1) #generate a target array |
301 | 304 | F.append(f) |
302 | 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 | 309 | #read a batch of data based on the mask |
307 | 310 | def loadbatch(self, npixels): | ... | ... |
stim/biomodels/nwt_format.pptx
No preview for this file type