Skip to content
This repository was archived by the owner on Feb 11, 2023. It is now read-only.

Commit

Permalink
add Streamlit demo (#31)
Browse files Browse the repository at this point in the history
* streamlit demo segm
* fix Pillow ver.
* add Makefile
* move Docs CI - CircleCI > GHA
* update line length
  • Loading branch information
Borda authored May 25, 2021
1 parent ed07413 commit 54a8cf4
Show file tree
Hide file tree
Showing 19 changed files with 237 additions and 112 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/ci-experiment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on: # Trigger the workflow on push or pull request, but only for the master bra
branches: [master]

jobs:
pytest:

bash-expt:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -37,11 +37,6 @@ jobs:
restore-keys: |
${{ runner.os }}-pip-py${{ matrix.python-version }}-
#- name: Set py2.7 dependencies
# if: matrix.python-version == 2.7
# run: |
# cp -r requirements-py27.txt requirements.txt

- name: install ImSegm
run: |
python --version
Expand Down
85 changes: 85 additions & 0 deletions .github/workflows/docs-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: "Docs check"
# https://github.com/marketplace/actions/sphinx-build

on:
- pull_request

jobs:

test-docs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@v2
with:
python-version: 3.7

# Note: This uses an internal pip API and may not always work
# https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install -y cmake pandoc
pip --version
pip install -r requirements.txt
pip install -r docs/requirements.txt
python setup.py build_ext --inplace
pip list
shell: bash

- name: Test Documentation
run: |
# First run the same pipeline as Read-The-Docs
cd docs
make doctest
make-docs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@v2
with:
python-version: 3.7

# Note: This uses an internal pip API and may not always work
# https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake pandoc latexmk
sudo apt-get install -y texlive-latex-extra dvipng texlive-pictures
pip --version
pip install -r requirements.txt
pip install -r docs/requirements.txt
python setup.py build_ext --inplace
pip list
shell: bash

- name: Make Documentation
run: |
cd docs
make clean
make html --debug --jobs 2 SPHINXOPTS="-W"
make latexpdf
- name: Upload built docs
uses: actions/upload-artifact@v2
with:
name: docs-results-${{ runner.os }}-${{ matrix.python-version }}
path: docs/build/html/
if: success()
5 changes: 3 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ recursive-exclude __pycache__ *.pyc *.pyo *.orig

# Include the README
include *.md
exclude Makefile
exclude streamlit*.py

# Include the license file
include LICENSE

# Include the Requirements
include requirements.txt
include requirements-py27.txt
include require-py27.txt

# Include package
recursive-include imsegm *.py *.pyx
Expand All @@ -24,7 +26,6 @@ exclude *.yml
# Exclude testing
exclude pytest.*
recursive-exclude tests *
exclude tests

# Exclude experiments
exclude */*.sh
Expand Down
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.PHONY: test clean docs

clean:
# clean all temp runs
rm -rf .pytest_cache
rm -rf ./docs/build
rm -rf ./docs/source/*.md
rm -rf ./docs/source/api
rm -rf ./docs/source/notebooks

test: clean
pip install --quiet -r requirements.txt
pip install --quiet -r tests/requirements.txt

# run tests with coverage
python -m coverage run --source imsegm -m pytest imsegm tests -v
python -m coverage report

docs: clean
pip install --quiet -r docs/requirements.txt
python setup.py build_ext --inplace
python -m sphinx -b html -W --keep-going docs/source docs/build
47 changes: 2 additions & 45 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ references:
coverage report
python setup.py check --metadata --strict
formatting: &formatting
run:
name: Formatting
command: |
pip install flake8 -q
flake8 .
build_project: &build_project
run:
name: Building project
Expand All @@ -42,18 +35,11 @@ references:
python setup.py build_ext --inplace
pwd ; ls -l imsegm
install_project: &install_project
run:
name: Insatlling project
command: |
python setup.py install --user
rm -rf imsegm
make_docs: &make_docs
run:
name: Make Documentation
command: |
# sudo apt-get install pandoc
sudo apt-get install pandoc
pyenv global 3.7.3
python --version
pip install -r requirements.txt
Expand All @@ -65,12 +51,6 @@ references:
make latexpdf
jobs:
Formatting:
docker:
- image: circleci/python:3.6
steps:
- checkout
- *formatting

Py3-Tests:
docker:
Expand Down Expand Up @@ -98,26 +78,6 @@ jobs:
- store_artifacts:
path: test-reports

Py3-Experiments:
docker:
- image: circleci/python:3.6
steps: &steps_expt
- checkout
# INSTALLATION
- *install_pips
#- run: git lfs pull
- *install_project

- run: mkdir libs && mkdir output && mkdir results
# ANNOTATION section
- run: bash handling_annotations/test_annotations.sh
# SEGMENTATION section
- run: bash experiments_segmentation/test_segmentations.sh
# CENTER DETECT. section
- run: bash experiments_ovary_centres/test_ovary_centers.sh
# REGION GROWING section
- run: bash experiments_ovary_detect/test_ovary_detect.sh

Build-Docs:
docker:
- image: readthedocs/build:latest
Expand All @@ -137,8 +97,5 @@ workflows:
version: 2
build:
jobs:
- Formatting
- Py3-Tests
#- Py2-Experiments
#- Py3-Experiments
- Build-Docs
# - Build-Docs
6 changes: 3 additions & 3 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sphinx>=2.0, <3.0
recommonmark # fails with badges
m2r # fails with multi-line text
nbsphinx
myst-parser
nbsphinx>=0.8.5
pandoc
docutils<0.15 # higher version breaks py2
docutils
ipython
20 changes: 11 additions & 9 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@
'sphinx.ext.napoleon',
'sphinx.ext.autosummary',
# 'sphinxcontrib.rsvgconverter'
'recommonmark',
# 'm2r',
'myst_parser',
'nbsphinx',
]

Expand All @@ -106,6 +105,8 @@
nbsphinx_execute = 'never'
nbsphinx_allow_errors = True

myst_update_mathjax = False

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
Expand Down Expand Up @@ -336,10 +337,11 @@ def find_source():

autodoc_member_order = 'groupwise'
autoclass_content = 'both'
autodoc_default_flags = [
'members',
'undoc-members',
'show-inheritance',
'private-members',
# 'special-members', 'inherited-members'
]
autodoc_default_options = {
'members': True,
'undoc-members': True,
'private-members': True,
'methods': True,
'exclude-members': '_abc_impl',
'show-inheritance': True,
}
3 changes: 1 addition & 2 deletions experiments_ovary_centres/run_center_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ def load_center_evaluate(idx_row, df_annot, path_annot, path_visu=None, col_pref
return dict_row

assert all(c in df_annot.columns for c in tl_visu.COLUMNS_POSITION_EGG_ANNOT), \
'some required columns %r are missing for %s' % \
(tl_visu.COLUMNS_POSITION_EGG_ANNOT, df_annot.columns)
'some required columns %r are missing for %s' % (tl_visu.COLUMNS_POSITION_EGG_ANNOT, df_annot.columns)
mask_eggs = estimate_eggs_from_info(df_annot.loc[idx], img.shape[:2])

try:
Expand Down
3 changes: 1 addition & 2 deletions experiments_ovary_centres/run_center_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ def main(params):
params = run_train.arg_parse_params(DEFAULT_PARAMS)

params['path_classif'] = params['path_centers']
assert os.path.isfile(params['path_classif']), \
'missing classifier: %s' % params['path_classif']
assert os.path.isfile(params['path_classif']), 'missing classifier: %s' % params['path_classif']

main(params)

Expand Down
3 changes: 1 addition & 2 deletions experiments_segmentation/run_segm_slic_model_graphcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ def export_visual(idx_name, img, segm, debug_visual=None, path_out=None, path_vi
fig.savefig(path_fig)
plt.close(fig)

if path_visu is not None and os.path.isdir(path_visu) \
and debug_visual is not None:
if path_visu is not None and os.path.isdir(path_visu) and debug_visual is not None:
path_fig = os.path.join(path_visu, str(idx_name) + '_debug.png')
logging.debug('exporting (debug) visualization: %s', path_fig)
fig = tl_visu.figure_segm_graphcut_debug(debug_visual)
Expand Down
3 changes: 1 addition & 2 deletions handling_annotations/run_segm_annot_relabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ def relabel_folder_images(path_images, path_out, labels_old, labels_new, nb_work
:param [int] labels_new: list of new labels
:param int nb_workers:
"""
assert os.path.isdir(os.path.dirname(path_images)), \
'missing folder: %s' % path_images
assert os.path.isdir(os.path.dirname(path_images)), 'missing folder: %s' % path_images
assert os.path.isdir(path_out), 'missing ouput folder: %s' % path_out

path_imgs = sorted(glob.glob(path_images))
Expand Down
12 changes: 5 additions & 7 deletions imsegm/graph_cuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ def compute_spatial_dist(centres, edges, relative=False):
array([ 1.12, 1.57, 1.34, 1.34, 0.5 , 0.63, 0.5 ])
"""
assert np.max(edges) < len(centres), \
'max vertex %i exceed size of centres %i'\
% (np.max(edges), len(centres))
'max vertex %i exceed size of centres %i' % (np.max(edges), len(centres))
ndim = np.max([len(c) for c in centres if c is not None])
# replace empy segments by a empty vector
for i, c in enumerate(centres):
Expand Down Expand Up @@ -510,8 +509,7 @@ def create_pairwise_matrix(gc_regul, nb_classes):
"""
if isinstance(gc_regul, np.ndarray):
assert gc_regul.shape[0] == gc_regul.shape[1] == nb_classes, \
'GC regul matrix %r should match match number of classes (%i)' \
% (gc_regul.shape, nb_classes)
'GC regul matrix %r should match match number of classes (%i)' % (gc_regul.shape, nb_classes)
# sub_min = np.tile(np.min(gc_regul, axis=0), (gc_regul.shape[0], 1))
pairwise = gc_regul - np.min(gc_regul)
elif isinstance(gc_regul, list):
Expand Down Expand Up @@ -566,9 +564,9 @@ def insert_gc_debug_images(debug_visual, segments, graph_labels, unary_cost, edg
debug_visual['imgs_unary_cost'] = draw_graphcut_unary_cost_segments(segments, unary_cost)
img = debug_visual.get('slic_mean', None)
list_centres = superpixel_centers(segments)
debug_visual['img_graph_edges'] = \
draw_graphcut_weighted_edges(segments, list_centres, edges,
edge_weights, img_bg=img)
debug_visual['img_graph_edges'] = draw_graphcut_weighted_edges(
segments, list_centres, edges, edge_weights, img_bg=img
)
debug_visual['img_graph_segm'] = draw_color_labeling(segments, graph_labels)


Expand Down
Loading

0 comments on commit 54a8cf4

Please sign in to comment.