Skip to content

Commit

Permalink
Merge pull request #303 from clEsperanto/test
Browse files Browse the repository at this point in the history
Test inf-sup with morphological snakes
  • Loading branch information
haesleinhuepf authored Apr 30, 2023
2 parents 0ca2926 + 8c00111 commit 685becd
Show file tree
Hide file tree
Showing 118 changed files with 11,748 additions and 892 deletions.
73 changes: 56 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ The preliminary API reference is available [here](https://clesperanto.github.io/
Furthermore, parts of the [reference](https://clij.github.io/clij2-docs/reference__pyclesperanto) are also available within the CLIJ2 documentation.

## Installation
* Get a conda/python environment, e.g. via [mini-conda](https://docs.conda.io/en/latest/miniconda.html). If you never used python/conda environments before, please follow the instructions [here](https://biapol.github.io/blog/johannes_mueller/anaconda_getting_started/) first.
* Get a conda/python environment, e.g. via [mamba-forge](https://github.com/conda-forge/miniforge#mambaforge).
* If you never used python/conda environments before, please follow [these instructions](https://biapol.github.io/blog/mara_lampert/getting_started_with_mambaforge_and_python/readme.html) first.

```
conda create --name cle_39 python=3.9
conda activate cle_39
```

* Install pyclesperanto-prototype using conda:
* Install pyclesperanto-prototype using [mamba / conda](https://focalplane.biologists.com/2022/12/08/managing-scientific-python-environments-using-conda-mamba-and-friends/):

```
conda install -c conda-forge pyclesperanto-prototype
mamba install -c conda-forge pyclesperanto-prototype
```

OR using pip:
Expand All @@ -50,24 +51,53 @@ OR using pip:
pip install pyclesperanto-prototype
```

Mac-users please also install this:
## Troubleshooting: Graphics cards drivers

In case error messages contains "ImportError: DLL load failed while importing cl: The specified procedure could not be found" [see also](https://github.com/clEsperanto/pyclesperanto_prototype/issues/55) or "clGetPlatformIDs failed: PLATFORM_NOT_FOUND_KHR", please install recent drivers for your graphics card and/or OpenCL device. Select the right driver source depending on your hardware from this list:

* [AMD drivers](https://www.amd.com/en/support)
* [NVidia drivers](https://www.nvidia.com/download/index.aspx)
* [Intel GPU drivers](https://www.intel.com/content/www/us/en/download/726609/intel-arc-graphics-windows-dch-driver.html)
* [Microsoft Windows OpenCL support](https://www.microsoft.com/en-us/p/opencl-and-opengl-compatibility-pack/9nqpsl29bfff)

Sometimes, mac-users need to install this:

mamba install -c conda-forge ocl_icd_wrapper_apple

Sometimes, linux users need to install this:

mamba install -c conda-forge ocl-icd-system

## Computing on Central Processing units (CPUs)

If no OpenCL-compatible GPU is available, pyclesperanto-prototype can make use of CPUs instead.
Just install [oclgrind](https://github.com/jrprice/Oclgrind)
or [pocl](http://portablecl.org/), e.g. using mamba / conda. Oclgrind is recommended for Windows systems, PoCL for Linux. MacOS typically comes with OpenCL support for CPUs.

```
mamba install oclgrind -c conda-forge
```

OR

```
mamba install pocl -c conda-forge
```

Owners of compatible Intel Xeon CPUs can also install a driver to use them for computing:
* [Intel CPU OpenCL drivers](https://www.intel.com/content/www/us/en/developer/articles/tool/opencl-drivers.html#latest_CPU_runtime)

conda install -c conda-forge ocl_icd_wrapper_apple

Linux users please also install this:

conda install -c conda-forge ocl-icd-system

## Example code
A basic image procressing workflow loads blobs.gif and counts the number of gold particles:
A basic image processing workflow loads blobs.gif and counts the number of objects:

```python
import pyclesperanto_prototype as cle

from skimage.io import imread, imsave

# initialize GPU
device = cle.select_device("GTX")
# initialize / select GPU with "TX" in their name
device = cle.select_device("TX")
print("Used GPU: ", device)

# load data
Expand All @@ -79,11 +109,9 @@ blurred = cle.gaussian_blur(inverted, sigma_x=1, sigma_y=1)
binary = cle.threshold_otsu(blurred)
labeled = cle.connected_components_labeling_box(binary)

# The maxmium intensity in a label image corresponds to the number of objects
num_labels = cle.maximum_of_all_pixels(labeled)

# print out result
print("Num objects in the image: " + str(num_labels))
# The maximium intensity in a label image corresponds to the number of objects
num_labels = labeled.max()
print(f"Number of objects in the image: {num_labels}")

# save image to disc
imsave("result.tif", labeled)
Expand Down Expand Up @@ -198,6 +226,17 @@ imsave("result.tif", labeled)
</td></tr>


<tr><td>

<img src="https://github.com/clEsperanto/pyclesperanto_prototype/raw/master/docs/images/intensities_along_lines.png" width="300"/>

</td><td>

[Measure intensity along lines](http://github.com/clEsperanto/pyclesperanto_prototype/tree/master/demo/measurement/intensities_along_lines.ipynb)

</td></tr>


<tr><td>

<img src="https://github.com/clEsperanto/pyclesperanto_prototype/raw/master/docs/images/screenshot_crop_and_paste_images.png" width="300"/>
Expand Down
262 changes: 262 additions & 0 deletions benchmarks/apple_m1_voronoi_otsu_labeling.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "e535dc08-1602-4ad0-9b79-db9a8a4b607f",
"metadata": {},
"source": [
"# Pyclesperanto on Apple M1 CPUs/GPUs\n",
"This notebook serves exploring and basic benchmarking of CPUs and GPUs in an Apple M1 laptop"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "4bb88b1a-2e9a-463f-9b3f-095d7766e9b8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['Apple M1 Max', 'Apple M1 Max']"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"import napari_segment_blobs_and_things_with_membranes as nsbatwm\n",
"import timeit\n",
"import pyclesperanto_prototype as cle\n",
"cle.available_device_names()"
]
},
{
"cell_type": "markdown",
"id": "105c5a7f-6b94-44bc-a4a5-b1bbbfa6577a",
"metadata": {},
"source": [
"## Defining test data\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d96117ce-5312-477d-a646-04db49204dce",
"metadata": {},
"outputs": [],
"source": [
"image = np.random.random((2048, 2048))\n",
"\n",
"sigma_spot_detection = 1\n",
"sigma_outline = 1"
]
},
{
"cell_type": "markdown",
"id": "c64a6c88-5eaa-43e6-95e0-d7170c6ae9a8",
"metadata": {},
"source": [
"## M1 CPU"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4f9a4565-fe00-4f52-a7d6-92e6592ca11c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Apple M1 Max on Platform: Apple (2 refs)>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"device = cle.select_device(dev_type='cpu')\n",
"device"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "527744b1-a87a-41c6-9fec-876cf373f6c2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"device.device.type"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "9dedb68c-4894-41ca-9aca-e62c45fae3ca",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"614 ms ± 6.92 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
"source": [
"%timeit nsbatwm.voronoi_otsu_labeling(image, spot_sigma=sigma_spot_detection, outline_sigma=sigma_outline)\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "3e082fb5-b05d-4c43-9df2-148b4dd856f7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"530 ms ± 5.04 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
"source": [
"%timeit cle.voronoi_otsu_labeling(image, spot_sigma=sigma_spot_detection, outline_sigma=sigma_outline)\n"
]
},
{
"cell_type": "markdown",
"id": "fc839892-799a-478a-8630-e08799abb7dd",
"metadata": {},
"source": [
"## M1 GPU"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "596a9fd6-6c16-4ac1-baf2-c1632927281a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Apple M1 Max on Platform: Apple (2 refs)>"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"device = cle.select_device(dev_type='gpu')\n",
"device"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "9b6c2628-a583-43c2-8efb-0ff258f88e45",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"device.device.type"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "be410bc8-2e74-4a15-9ce9-60c80e3caf4c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"609 ms ± 3.63 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
"source": [
"%timeit nsbatwm.voronoi_otsu_labeling(image, spot_sigma=sigma_spot_detection, outline_sigma=sigma_outline)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "6d655aed-44f2-42c4-ae10-fb22f8c31232",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"609 ms ± 4.32 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
"source": [
"%timeit nsbatwm.voronoi_otsu_labeling(image, spot_sigma=sigma_spot_detection, outline_sigma=sigma_outline)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aa036230-428c-495c-a933-0beaf600915c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 685becd

Please sign in to comment.