Skip to content

Commit

Permalink
changing how size works to try to fix mac pyinstaller version
Browse files Browse the repository at this point in the history
  • Loading branch information
carsen-stringer committed Oct 1, 2020
1 parent faec4f6 commit 2e88684
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions cellpose/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,13 +657,13 @@ def get_channels(self):

def calibrate_size(self):
self.initialize_model()
diams, _ = self.model.sz.eval([self.stack[self.currentZ].copy()], invert=self.invert.isChecked(),
diams, _ = self.model.sz.eval(self.stack[self.currentZ].copy(), invert=self.invert.isChecked(),
channels=self.get_channels(), progress=self.progress)
diams = np.maximum(5.0, diams)
print('estimated diameter of cells using %s model = %0.1f pixels'%
(self.current_model, diams))
self.Diameter.setText('%0.1f'%diams[0])
self.diameter = diams[0]
self.Diameter.setText('%0.1f'%diams)
self.diameter = diams
self.compute_scale()
self.progress.setValue(100)

Expand Down
16 changes: 9 additions & 7 deletions cellpose/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,22 @@ def eval(self, x, batch_size=8, channels=None, invert=False, normalize=True, dia
diams = diameter * np.ones(nimg, np.float32)
else:
diams = diameter
rescale = self.diam_mean / diams.copy()
rescale = self.diam_mean / diams
else:
if rescale is not None and (not isinstance(rescale, list) or len(rescale)==1):
rescale = rescale * np.ones(nimg, np.float32)
if self.pretrained_size is not None and rescale is None and not do_3D:
tic = time.time()
diams, _ = self.sz.eval(x, channels=channels, invert=invert, batch_size=batch_size, augment=augment, tile=tile)
rescale = self.diam_mean / diams.copy()
rescale = self.diam_mean / diams
print('estimated cell diameters for %d image(s) in %0.2f sec'%(nimg, time.time()-tic))
else:
if rescale is None:
if do_3D:
rescale = np.ones(1)
else:
rescale = np.ones(nimg, np.float32)
diams = self.diam_mean / rescale.copy()
diams = self.diam_mean / rescale

tic = time.time()
masks, flows, styles = self.cp.eval(x, batch_size=batch_size, invert=invert, rescale=rescale, anisotropy=anisotropy,
Expand Down Expand Up @@ -1347,15 +1347,14 @@ def eval(self, imgs=None, styles=None, channels=None, normalize=True, invert=Fal
"""
if styles is None and imgs is None:
raise ValueError('no image or features given')

nimg = len(imgs)

if progress is not None:
progress.setValue(10)

if imgs is not None:
x, nolist = convert_images(imgs.copy(), channels, False, normalize, invert)

nimg = len(x)

if styles is None:
styles = self.cp.eval(x, channels=channels, net_avg=False, augment=augment, tile=tile, compute_masks=False)[-1]
if progress is not None:
Expand Down Expand Up @@ -1385,7 +1384,10 @@ def eval(self, imgs=None, styles=None, channels=None, normalize=True, invert=Fal
else:
diam = diam_style
print('no images provided, using diameters estimated from styles alone')
return diam, diam_style
if nolist:
return diam[0], diam_style[0]
else:
return diam, diam_style

def _size_estimation(self, style):
""" linear regression from style to size
Expand Down

0 comments on commit 2e88684

Please sign in to comment.