Skip to content

Commit

Permalink
Merge pull request #129 from MouseLand/move_resize
Browse files Browse the repository at this point in the history
Move resize
  • Loading branch information
carsen-stringer committed Sep 27, 2020
2 parents 9c520e4 + f84f870 commit 1d0f006
Show file tree
Hide file tree
Showing 14 changed files with 435 additions and 483 deletions.
73 changes: 73 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
language: python
jobs:
include:
- name: Python 3.7.1 on Linux
dist: xenial
services:
- xvfb
python: 3.7
before_install:
- wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O
miniconda.sh
- bash ./miniconda.sh -b
- export PATH=~/miniconda3/bin:$PATH
- conda update --yes conda
- export MPLBACKEND=Agg
- name: Python 3.7.1 on Linux Bionic
dist: bionic
services:
- xvfb
python: 3.7
before_install:
- wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O
miniconda.sh
- bash ./miniconda.sh -b
- export PATH=~/miniconda3/bin:$PATH
- conda update --yes conda
- export MPLBACKEND=Agg
- name: Python 3.7.7 on macOS
os: osx
osx_image: xcode12
language: shell
before_install:
- wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
-O miniconda.sh
- bash ./miniconda.sh -b
- export PATH=~/miniconda3/bin:$PATH
- conda update --yes conda
- export MPLBACKEND=Agg
- name: Python 3.7.7 on Windows
os: windows
language: shell
before_install:
- choco install python --version 3.7.7
- export MINICONDA=/c/miniconda
- MINICONDA_WIN=$(cygpath --windows $MINICONDA)
- choco install openssl.light
- choco install miniconda3 --params="'/AddToPath:0 /D:$MINICONDA_WIN'"
- PATH=$(echo "$PATH" | sed -e 's|:/c/ProgramData/chocolatey/bin||')
- PATH=$(echo "$PATH" | sed -e 's|:/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin||')
- source $MINICONDA/Scripts/activate
- source $MINICONDA/etc/profile.d/conda.sh
allow_failures:
- os: osx
- os: windows
install:
- conda env create -f environment.yml
- source activate cellpose
- pip install .
- pip install matplotlib
- pip install coveralls
script:
- coverage run --source=cellpose --omit=cellpose/gui.py,cellpose/guiparts.py,cellpose/menus.py,cellpose/__main__.py
setup.py test
after_success: coveralls
deploy:
skip_cleanup: true
skip_existing: true
provider: pypi
user: __token__
password:
secure: uoXsDSxaiQISL++Ppo1hKgIHL2pE6WDweG6g5XmaXbnZJVk6YV4K4inlk4VPMYi7DXVo2HG6Gwv044+oLOVAH4leJIHJm+aKtSeE2/Dt+FVfUdA8xOYkAdFHBaPLGOrag1run0vEbacrP6ffjlVz4Ri/2IL816XK3/59MWjxU5/mrhDIW48hkwQoJmNzm0aXUNXik0OM/FaPuQQ7++ESpaFZVs8XF149f7upflnBwf7Uct7XrtKgeM1xZSNwJsaY4xAIljb+hnFiXI8PyeQmehXio/M2RicC9JyELkNWQsCgDKDSfZMw+YpS2qkIWQ72DvE6vFiKdpMplugkPxKaY0amxyrR4YdhhRLANQK8eSQaeug5YZv+uDUzUtzgDBx6fM0OZAla1xRC3izEQyulmO7hbSupMVaUUAfOJnOf/4j19wz9GMIc1rxOKGgLLsYPqgf5Vnv4vUp9Ga9mJDZeT/EnWMoMO2nASf5VmcN4n7W0EIwAPKUyhDZ0/sep8Iq8nM1uic736UlsG+NDByiEiZvYywxAfxHStceaxkn/o2uCXVMnrLm5idyOaTdn6U94RJlMKCYtWytTquiRp9pOt60f3eBoOXLx2n6QSBoQjjTLWrziMSc2nHeTd0geGuUM3agbNMd+6hGom1j0ZiDrLeSRzISYEmksB3MprH4PxrU=
on:
tags: true
85 changes: 8 additions & 77 deletions cellpose/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,6 @@
GUI_IMPORT = False
raise

def get_image_files(folder, mask_filter, imf=None):
mask_filters = ['_cp_masks', '_cp_output', '_flows', mask_filter]
image_names = []
if imf is None:
imf = ''
image_names.extend(glob.glob(folder + '/*%s.png'%imf))
image_names.extend(glob.glob(folder + '/*%s.jpg'%imf))
image_names.extend(glob.glob(folder + '/*%s.jpeg'%imf))
image_names.extend(glob.glob(folder + '/*%s.tif'%imf))
image_names.extend(glob.glob(folder + '/*%s.tiff'%imf))
image_names = natsorted(image_names)
imn = []
for im in image_names:
imfile = os.path.splitext(im)[0]
igood = all([(len(imfile) > len(mask_filter) and imfile[-len(mask_filter):] != mask_filter) or len(imfile) < len(mask_filter)
for mask_filter in mask_filters])
if len(imf)>0:
igood &= imfile[-len(imf):]==imf
if igood:
imn.append(im)
image_names = imn

return image_names

def get_label_files(image_names, mask_filter, imf=None):
nimg = len(image_names)
label_names0 = [os.path.splitext(image_names[n])[0] for n in range(nimg)]

if imf is not None and len(imf) > 0:
label_names = [label_names0[n][:-len(imf)] for n in range(nimg)]
else:
label_names = label_names0

# check for flows
if os.path.exists(label_names0[0] + '_flows.tif'):
flow_names = [label_names0[n] + '_flows.tif' for n in range(nimg)]
else:
flow_names = [label_names[n] + '_flows.tif' for n in range(nimg)]
if not all([os.path.exists(flow) for flow in flow_names]):
flow_names = None

# check for masks
if os.path.exists(label_names[0] + mask_filter + '.tif'):
label_names = [label_names[n] + mask_filter + '.tif' for n in range(nimg)]
elif os.path.exists(label_names[0] + mask_filter + '.png'):
label_names = [label_names[n] + mask_filter + '.png' for n in range(nimg)]
else:
raise ValueError('labels not provided with correct --mask_filter')
if not all([os.path.exists(label) for label in label_names]):
raise ValueError('labels not provided for all images in train and/or test set')

return label_names, flow_names


def main():
parser = argparse.ArgumentParser(description='cellpose parameters')
parser.add_argument('--check_mkl', action='store_true', help='check if mkl working')
Expand Down Expand Up @@ -161,10 +107,7 @@ def main():
else:
imf = None

image_names = get_image_files(args.dir, args.mask_filter, imf=imf)
nimg = len(image_names)
images = [io.imread(image_names[n]) for n in range(nimg)]



if args.use_gpu:
use_gpu = utils.use_gpu()
Expand All @@ -183,6 +126,10 @@ def main():
print('model path does not exist, using cyto model')
args.pretrained_model = 'cyto'

image_names = io.get_image_files(args.dir, args.mask_filter, imf=imf)
nimg = len(image_names)
images = [io.imread(image_names[n]) for n in range(nimg)]

if args.pretrained_model=='cyto' or args.pretrained_model=='nuclei':
model = models.Cellpose(device=device, model_type=args.pretrained_model)

Expand Down Expand Up @@ -243,25 +190,9 @@ def main():
if args.all_channels:
channels = None

# training data
label_names, flow_names = get_label_files(image_names, args.mask_filter, imf=imf)
nimg = len(image_names)
labels = [io.imread(label_names[n]) for n in range(nimg)]
if flow_names is not None and not args.unet:
labels = [np.concatenate((labels[n][np.newaxis,:,:], io.imread(flow_names[n])), axis=0)
for n in range(nimg)]

# testing data
test_images, test_labels, image_names_test = None, None, None
if len(args.test_dir) > 0:
image_names_test = get_image_files(args.test_dir, args.mask_filter, imf=imf)
label_names_test, flow_names_test = get_label_files(image_names_test, args.mask_filter, imf=imf)
nimg = len(image_names_test)
test_images = [io.imread(image_names_test[n]) for n in range(nimg)]
test_labels = [io.imread(label_names_test[n]) for n in range(nimg)]
if flow_names_test is not None and not args.unet:
test_labels = [np.concatenate((test_labels[n][np.newaxis,:,:], io.imread(flow_names_test[n])), axis=0)
for n in range(nimg)]
test_dir = None if len(args.test_dir)==0 else args.test_dir
output = io.load_train_test_data(args.dir, test_dir, imf, args.mask_filter, args.unet)
images, labels, image_names, test_images, test_labels, image_names_test = output

# model path
if not os.path.exists(cpmodel_path):
Expand Down
207 changes: 0 additions & 207 deletions cellpose/collect_datasets.py

This file was deleted.

0 comments on commit 1d0f006

Please sign in to comment.