def compute_cprob(self): rerun = False if self.cellprob != self.probslider.value(): rerun = True self.cellprob = self.probslider.value() if self.threshold != self.threshslider.value() / 10.: rerun = True self.threshold = self.threshslider.value() / 10. if not rerun: return if self.threshold == 3.0 or self.NZ > 1: thresh = None print( 'computing masks with cell prob=%0.3f, no flow error threshold' % (self.cellprob)) else: thresh = self.threshold print( 'computing masks with cell prob=%0.3f, flow error threshold=%0.3f' % (self.cellprob, thresh)) maski = dynamics.get_masks(self.flows[3].copy(), iscell=(self.flows[4][-1] > self.cellprob), flows=self.flows[4][:-1], threshold=thresh) if self.NZ == 1: maski = dynamics.fill_holes(maski) self.masksOn = True self.outlinesOn = True self.MCheckBox.setChecked(True) self.OCheckBox.setChecked(True) if maski.ndim < 3: maski = maski[np.newaxis, ...] print('%d cells found' % (len(np.unique(maski)[1:]))) io._masks_to_gui(self, maski, outlines=None) self.show()
def compute_model(self): self.progress.setValue(0) if 1: self.clear_all() self.flows = [[], [], []] self.initialize_model() print('using model %s' % self.current_model) self.progress.setValue(10) do_3D = False if self.NZ > 1: do_3D = True data = self.stack.copy() else: data = [self.stack[0].copy()] channels = self.get_channels() self.diameter = float(self.Diameter.text()) try: masks, flows, _, _ = self.model.eval( data, channels=channels, diameter=self.diameter, invert=self.invert.isChecked(), do_3D=do_3D, progress=self.progress) except Exception as e: print('NET ERROR: %s' % e) self.progress.setValue(0) return self.progress.setValue(75) if not do_3D: masks = masks[0][np.newaxis, :, :] flows = flows[0] self.flows[0] = flows[0] self.flows[1] = (np.clip(utils.normalize99(flows[2]), 0, 1) * 255).astype(np.uint8) if not do_3D: self.flows[2] = np.zeros(flows[1][0].shape, dtype=np.uint8) self.flows = [ self.flows[n][np.newaxis, ...] for n in range(len(self.flows)) ] else: self.flows[2] = (flows[1][0] / 10 * 127 + 127).astype(np.uint8) print('%d cells found with unet' % (len(np.unique(masks)[1:]))) self.progress.setValue(80) z = 0 self.masksOn = True self.outlinesOn = True self.MCheckBox.setChecked(True) self.OCheckBox.setChecked(True) io._masks_to_gui(self, masks, outlines=None) self.progress.setValue(100) self.toggle_server(off=True) else: #except Exception as e: print('ERROR: %s' % e)