Skip to content

Commit 4ffe9ff

Browse files
authored
BIOP/v0.2.2
add a tf2onnx environment to convert stardist TF model to OpenCV that are compatible with QuPath
2 parents 9079485 + ea17fe7 commit 4ffe9ff

4 files changed

Lines changed: 93 additions & 0 deletions

File tree

docker/Dockerfile-ms

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ARG INKSCAPE_VERSION=0.1.4
1818
ARG OMNI_VERSION=1.0.7-dev2
1919
ARG BRAINRENDER_VERSION=0.0.7
2020
ARG YOLO_VERSION=8.3.119
21+
ARG TF2ONNX_VERSION=1.9.2
2122

2223
FROM ${ALIAS}biop-qupath:${QUPATH_VERSION} AS qupath-image
2324
FROM ${ALIAS}biop-ilastik:${ILASTIK_VERSION} AS ilastik-image
@@ -33,6 +34,7 @@ FROM ${ALIAS}biop-inkscape:${INKSCAPE_VERSION} AS inkscape-image
3334
FROM ${ALIAS}biop-omni:${OMNI_VERSION} AS omnipose-image
3435
FROM ${ALIAS}biop-brainrender:${BRAINRENDER_VERSION} AS brainrender-image
3536
FROM ${ALIAS}biop-yolo:${YOLO_VERSION} AS yolo-image
37+
FROM ${ALIAS}biop-tf2onnx:${TF2ONNX_VERSION} AS tf2onnx-image
3638

3739
FROM ${ALIAS}biop-vnc-base:${BASE_IMAGE} AS base
3840

@@ -121,6 +123,10 @@ COPY --from=brainrender-image /home/biop/.brainglobe/ /home/biop/.brainglobe/
121123
# Install yolo
122124
COPY --from=yolo-image /opt/conda/envs/yolo /opt/conda/envs/yolo
123125

126+
##################################################################
127+
# Install tf2onnx
128+
COPY --from=tf2onnx-image /opt/conda/envs/tf2onnx /opt/conda/envs/tf2onnx
129+
124130
#################################################################
125131
# Jupyter kernels
126132
#

docker/tf2onnx/Dockerfile-tf2onnx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ARG ALIAS=biop/
2+
ARG STARDIST_VERSION=0.8.5
3+
FROM ${ALIAS}biop-stardist:${STARDIST_VERSION}
4+
5+
USER root
6+
7+
COPY tf2onnx/tf2onnx.txt /tmp/tf2onnx.txt
8+
RUN conda create -y -n tf2onnx python=3.7 \
9+
&& source activate tf2onnx \
10+
&& pip install -r /tmp/tf2onnx.txt
11+
12+
RUN chmod -R a+rwX /home/biop/ \
13+
&& chown -R biop:biop /home/biop/
14+
15+
#################################################################
16+
# Container start
17+
USER biop
18+
WORKDIR /home/biop
19+
ENTRYPOINT ["/usr/local/bin/jupyter"]
20+
CMD ["lab", "--allow-root", "--ip=*", "--port=8888", "--no-browser", "--NotebookApp.token=''", "--NotebookApp.allow_origin='*'", "--notebook-dir=/home/biop"]

docker/tf2onnx/readme-tf2onnx.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Latest Version
2+
3+
## build
4+
```
5+
docker build -f tf2onnx/Dockerfile-tf2onnx -t biop-tf2onnx:1.9.2 . --no-cache
6+
7+
```
8+
## start to test (see below)
9+
```
10+
docker run -it --rm -p 8888:8888 --gpus device=0 --mount src=D:/,target=/home/biop/local,type=bind biop-tf2onnx:1.9.2
11+
```
12+
13+
## after testing pass, tag
14+
```
15+
docker tag biop-tf2onnx:1.9.2 biop/biop-tf2onnx:1.9.2
16+
```
17+
18+
## push on dockerhub
19+
```
20+
docker push biop/biop-tf2onnx:1.9.2
21+
```
22+
23+
# Test(s)
24+
25+
## tf2onnx on blob
26+
- train a stardist model
27+
- export using model.export_TF("model_name")
28+
- unzip the model_name.zip to a folder model_name (this folder will contain a "tensorflow_model.pb" file)
29+
30+
- convert the model using tf2onnx, in the terminal :
31+
```
32+
source activate tf2onnx
33+
python -m tf2onnx.convert --saved-model "/path/to/folder/model_name" --output_frozen_graph "/path/to/output/model_name_converted.pb"
34+
```
35+
36+
model_name_converted.pb is the converted model, you can use it in your QuPath script!.

docker/tf2onnx/tf2onnx.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
absl-py==0.14.1
2+
astor==0.8.1
3+
cached-property==1.5.2
4+
certifi==2021.5.30
5+
charset-normalizer==2.0.6
6+
flatbuffers==1.12
7+
gast==0.2.2
8+
google-pasta==0.2.0
9+
grpcio==1.41.0
10+
h5py==3.4.0
11+
idna==3.2
12+
importlib-metadata==4.8.1
13+
Keras-Applications==1.0.8
14+
Keras-Preprocessing==1.1.2
15+
Markdown==3.3.4
16+
numpy==1.21.2
17+
onnx==1.10.1
18+
opt-einsum==3.3.0
19+
protobuf==3.18.0
20+
requests==2.26.0
21+
six==1.16.0
22+
tensorboard==1.15.0
23+
tensorflow==1.15.0
24+
tensorflow-estimator==1.15.1
25+
termcolor==1.1.0
26+
tf2onnx==1.9.2
27+
typing-extensions==3.10.0.2
28+
urllib3==1.26.7
29+
Werkzeug==2.0.1
30+
wrapt==1.13.1
31+
zipp==3.6.0

0 commit comments

Comments
 (0)