Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It/keras3 pytorch #396

Merged
merged 56 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f23c402
replace tensorflow Tensor with keras tensor
sfmig Feb 7, 2024
d508b9f
add case for TF prep in prep_model_weights
sfmig Feb 7, 2024
559c9ab
add different backends to pyproject.toml
sfmig Feb 7, 2024
d3cb209
add backend configuration to cellfinder init file. tests passing with…
sfmig Feb 7, 2024
c8e0ac8
define extra dependencies for cellfinder with different backends. run…
sfmig Feb 8, 2024
313b988
run tox using TF and JAX backend
sfmig Feb 8, 2024
681925e
install TF in brainmapper environment before running tests in CI
sfmig Feb 8, 2024
0ff4546
add backends check to cellfinder init file
sfmig Feb 8, 2024
6ec3c33
clean up comments
sfmig Feb 8, 2024
f4857e1
fix tf-nightly import check
sfmig Feb 8, 2024
b32fab4
specify TF backend in include guard check
sfmig Feb 8, 2024
8bfa0d9
clarify comment
sfmig Feb 8, 2024
576340b
remove 'backend' from dependencies specifications
sfmig Feb 9, 2024
89339fa
Apply suggestions from code review
sfmig Feb 9, 2024
01394af
PyTorch runs utilizing multiple cores
IgorTatarnikov Feb 14, 2024
22db8f4
PyTorch fix with default models
IgorTatarnikov Apr 5, 2024
64bde71
Tests run on every push for now
IgorTatarnikov Apr 5, 2024
585e7da
Merge branch 'cellfinder-to-keras-3' into it/keras3-pytorch
IgorTatarnikov Apr 5, 2024
2934f35
Run test on torch backend only
IgorTatarnikov Apr 5, 2024
014b549
Fixed guard test to set torch as KERAS_BACKEND
IgorTatarnikov Apr 5, 2024
315dbc4
KERAS_BACKEND env variable set directly in test_include_guard.yaml
IgorTatarnikov Apr 5, 2024
4590106
Run test on python 3.11
IgorTatarnikov Apr 5, 2024
0ddb2e0
Remove tf-nightly from __init__ version check
IgorTatarnikov Apr 5, 2024
d4fed06
Merge branch 'main' into it/keras3-pytorch
IgorTatarnikov Apr 5, 2024
fe7b798
Added 3.11 to legacy tox config
IgorTatarnikov Apr 5, 2024
dcb315c
Changed legacy tox config for real this time
IgorTatarnikov Apr 5, 2024
8e77b68
Don't set the wrong max_processing value
IgorTatarnikov Apr 15, 2024
30b72f1
Torch is now set as the default backend
IgorTatarnikov Apr 16, 2024
550a126
Merge branch 'main' into it/keras3-pytorch
IgorTatarnikov Apr 16, 2024
1de446c
Tests only run with torch, updated comments
IgorTatarnikov Apr 16, 2024
f676f32
Merge branch 'cellfinder-to-keras-3' into it/keras3-pytorch
IgorTatarnikov Apr 16, 2024
e4bd665
Unpinned torch version
IgorTatarnikov Apr 16, 2024
f578095
Merge branch 'it/keras3-pytorch' of https://github.com/brainglobe/cel…
IgorTatarnikov Apr 16, 2024
560909f
Add codecov token (#403)
K-Meech Apr 18, 2024
e6a887f
Allow turning off classification or detection in GUI (#402)
matham Apr 22, 2024
b1b285c
Support single z-stack tif file for input (#397)
matham May 1, 2024
0fd0a5e
Remove modular asv benchmarks (#406)
sfmig May 1, 2024
6b529dc
Adapt CI so it covers both new and old Macs, and installs required ad…
alessandrofelder May 1, 2024
a283056
Optimize cell detection (#398) (#407)
alessandrofelder May 3, 2024
eeffd78
[pre-commit.ci] pre-commit autoupdate (#412)
pre-commit-ci[bot] May 7, 2024
8de63bd
Apply suggestions from code review
IgorTatarnikov May 8, 2024
860942c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 8, 2024
5f4882e
Simplify model download (#414)
adamltyson May 9, 2024
906f4d6
Remove jax and tf tests
IgorTatarnikov May 9, 2024
7e40ffc
Standardise the data types for inputs to all be float32
IgorTatarnikov May 9, 2024
933e5dd
Force torch to use CPU on arm based macOS during tests
IgorTatarnikov May 9, 2024
ada5f77
Added PYTORCH_MPS_HIGH_WATERMARK_RATION env variable
IgorTatarnikov May 9, 2024
546f223
Set env variables in test setup
IgorTatarnikov May 9, 2024
0546a56
Try to set the default device to cpu in the test itself
IgorTatarnikov May 9, 2024
8eb5ee3
Add device call to Conv3D to force cpu
IgorTatarnikov May 9, 2024
b995bb3
Revert changes, request one cpu left free
IgorTatarnikov May 9, 2024
78d1588
Revers the numb cores, don't use arm based mac runner
IgorTatarnikov May 9, 2024
663b69a
Merge branch 'main' into it/keras3-pytorch
IgorTatarnikov May 9, 2024
806f52b
Merged main, removed torch flags on cellfinder install for guards and…
IgorTatarnikov May 9, 2024
a38257b
Lowercase Torch
IgorTatarnikov May 9, 2024
5a1f0a8
Change cache directory
IgorTatarnikov May 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 17 additions & 12 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ jobs:
matrix:
# Run all supported Python versions on linux
os: [ubuntu-latest]
python-version: ["3.9", "3.10"]
# Include one macos run
python-version: ["3.9", "3.10", "3.11"]
# Include one windows, one macos run (intel based macOS 13 runner)
include:
- os: macos-latest
- os: macos-13
python-version: "3.10"
- os: windows-latest
python-version: "3.10"
Expand All @@ -54,8 +54,8 @@ jobs:
- name: Cache Keras model
uses: actions/cache@v3
with:
path: "~/.cellfinder"
key: models-${{ hashFiles('~/.cellfinder/**') }}
path: "~/.brainglobe"
key: models-${{ hashFiles('~/.brainglobe/**') }}
# Setup pyqt libraries
- name: Setup qtpy libraries
uses: tlambert03/setup-qt-libs@v1
Expand All @@ -65,11 +65,13 @@ jobs:
- uses: neuroinformatics-unit/actions/test@v2
with:
python-version: ${{ matrix.python-version }}
secret-codecov-token: ${{ secrets.CODECOV_TOKEN }}
use-xvfb: true

test_numba_disabled:
needs: [linting, manifest]
name: Run tests with numba disabled
timeout-minutes: 60
runs-on: ubuntu-latest
env:
NUMBA_DISABLE_JIT: "1"
Expand All @@ -78,8 +80,8 @@ jobs:
- name: Cache Keras model
uses: actions/cache@v3
with:
path: "~/.cellfinder"
key: models-${{ hashFiles('~/.cellfinder/**') }}
path: "~/.brainglobe"
key: models-${{ hashFiles('~/.brainglobe/**') }}
# Setup pyqt libraries
- name: Setup qtpy libraries
uses: tlambert03/setup-qt-libs@v1
Expand All @@ -89,22 +91,24 @@ jobs:
- uses: neuroinformatics-unit/actions/test@v2
with:
python-version: "3.10"
secret-codecov-token: ${{ secrets.CODECOV_TOKEN }}
codecov-flags: "numba"

# Run brainglobe-workflows brainmapper-CLI tests to check for
# breakages
test_brainmapper_cli:
needs: [linting, manifest]
name: Run brainmapper tests to check for breakages
timeout-minutes: 60
runs-on: ubuntu-latest
env:
KERAS_BACKEND: jax
KERAS_BACKEND: torch
steps:
- name: Cache Keras model
uses: actions/cache@v3
with:
path: "~/.cellfinder"
key: models-${{ hashFiles('~/.cellfinder/**') }}
path: "~/.brainglobe"
key: models-${{ hashFiles('~/.brainglobe/**') }}

- name: Checkout brainglobe-workflows
uses: actions/checkout@v3
Expand All @@ -119,8 +123,9 @@ jobs:
- name: Install test dependencies
run: |
python -m pip install --upgrade pip wheel
# Install cellfinder from the latest SHA on this branch (Keras with JAX backend)
python -m pip install "cellfinder[jax] @ git+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA"
# Install cellfinder from the latest SHA on this branch
python -m pip install "cellfinder @ git+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA"

# Install checked out copy of brainglobe-workflows
python -m pip install .[dev]

Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/test_include_guard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ jobs:
with:
python-version: '3.10'
sfmig marked this conversation as resolved.
Show resolved Hide resolved

- name: Install cellfinder via pip, specifying tensorflow as keras' backend
run: python -m pip install -e ".[tf]"
- name: Install cellfinder via pip
run: python -m pip install -e "."

- name: Test (working) import
uses: jannekem/run-python-script-action@v1
env:
KERAS_BACKEND: torch
with:
fail-on-error: true
script: |
Expand Down
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ mprofile*.dat

*.DS_Store

# asv
.asv
benchmarks/results
benchmarks/html
benchmarks/env

# OS
.DS_Store
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-docstring-first
- id: check-executables-have-shebangs
Expand All @@ -16,10 +16,10 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.5
rev: v0.4.3
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 24.3.0
rev: 24.4.2
hooks:
- id: black
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exclude tox.ini
graft cellfinder
include cellfinder/napari/napari.yaml

prune benchmarks
prune examples
prune resources
prune tests
prune benchmarks
51 changes: 12 additions & 39 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
# Benchmarking with asv
[Install asv](https://asv.readthedocs.io/en/stable/installing.html) by running:
```
pip install asv
```

`asv` works roughly as follows:
1. It creates a virtual environment (as defined in the config)
2. It installs the software package version of a specific commit (or of a local commit)
3. It times the benchmarking tests and saves the results to json files
4. The json files are 'published' into an html dir
5. The html dir can be visualised in a static website

## Running benchmarks
To run benchmarks on a specific commit:
```
$ asv run 88fbbc33^!
```

To run them up to a specific commit:
```
$ asv run 88fbbc33
```

To run them on a range of commits:
```
$ asv run 827f322b..729abcf3
```

To collate the benchmarks' results into a viewable website:
```
$ asv publish
```
This will create a tree of files in the `html` directory, but this cannot be viewed directly from the local filesystem, so we need to put them in a static site. `asv publish` also detects statistically significant decreases of performance, the results can be inspected in the 'Regression' tab of the static site.

To visualise the results in a static site:
```
$ asv preview
```
# Benchmarks
`detect_and_classify.py` contains a simple script that runs
detection and classification with the small test dataset.

## Memory
[memory_profiler](https://github.com/pythonprofilers/memory_profiler)
can be used to profile memory useage. Install, and then run
`mprof run --include-children --multiprocess detect_and_classify.py`. It is **very**
important to use these two flags to capture memory usage by the additional
processes that cellfinder.core uses.

To show the results of the latest profile run, run `mprof plot`.
188 changes: 0 additions & 188 deletions benchmarks/asv.conf.json

This file was deleted.

Empty file removed benchmarks/benchmarks/__init__.py
Empty file.