Skip to content

Commit

Permalink
Merge branch 'deisseroth-lab-performance'
Browse files Browse the repository at this point in the history
  • Loading branch information
carsen-stringer committed Aug 20, 2020
2 parents b64d37c + 65708a7 commit 10783af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
6 changes: 3 additions & 3 deletions cellpose/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from numba import njit, float32, int32, vectorize
from . import utils, metrics

@njit('(float64[:], int32[:], int32[:], int32, int32, int32, int32)')
@njit('(float64[:], int32[:], int32[:], int32, int32, int32, int32)', nogil=True)
def _extend_centers(T,y,x,ymed,xmed,Lx, niter):
""" run diffusion from center of mask (ymed, xmed) on mask pixels (y, x)
Expand Down Expand Up @@ -166,7 +166,7 @@ def masks_to_flows(masks):

return mu, mu_c

@njit('(float32[:,:,:,:],float32[:,:,:,:], int32[:,:], int32)')
@njit('(float32[:,:,:,:],float32[:,:,:,:], int32[:,:], int32)', nogil=True)
def steps3D(p, dP, inds, niter):
""" run dynamics of pixels to recover masks in 3D
Expand Down Expand Up @@ -207,7 +207,7 @@ def steps3D(p, dP, inds, niter):
p[2,z,y,x] = min(shape[2]-1, max(0, p[2,z,y,x] - dP[2,p0,p1,p2]))
return p

@njit('(float32[:,:,:], float32[:,:,:], int32[:,:], int32)')
@njit('(float32[:,:,:], float32[:,:,:], int32[:,:], int32)', nogil=True)
def steps2D(p, dP, inds, niter):
""" run dynamics of pixels to recover masks in 2D
Expand Down
10 changes: 2 additions & 8 deletions cellpose/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, sys, time, shutil, tempfile, datetime, pathlib, gc
import os, sys, time, shutil, tempfile, datetime, pathlib
import numpy as np
from tqdm import trange, tqdm
from urllib.parse import urlparse
Expand Down Expand Up @@ -536,8 +536,7 @@ def _run_net(self, imgs, rsz=1.0, augment=True, tile=True, bsize=224):
1D array summarizing the style of the image,
if tiled it is averaged over tiles
"""

"""
shape = imgs.shape
# rescale image for flow computation
if not isinstance(rsz, list):
Expand Down Expand Up @@ -663,8 +662,6 @@ def _run_tiled(self, imgi, augment=True, bsize=224):
stylei = stylea[i*ntiles:(i+1)*ntiles].sum(axis=0)
stylei /= (stylei**2).sum()**0.5
styles.append(stylei)
del IMGa
gc.collect()
return yf, np.array(styles)
else:
IMG, ysub, xsub, Ly, Lx = transforms.make_tiles(imgi, bsize=bsize, augment=augment)
Expand All @@ -690,9 +687,6 @@ def _run_tiled(self, imgi, augment=True, bsize=224):
yf = transforms.average_tiles(y, ysub, xsub, Ly, Lx)
yf = yf[:,:imgi.shape[1],:imgi.shape[2]]
styles /= (styles**2).sum()**0.5

del IMG
gc.collect()
return yf, styles

def train(self, train_data, train_labels, test_data=None, test_labels=None, channels=None,
Expand Down

0 comments on commit 10783af

Please sign in to comment.