kidcoconut commited on
Commit
9a53203
1 Parent(s): a51ed2e

ready for deploy to hugspace v0.1.5

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .dockerignore +0 -21
  2. .gitattributes +0 -46
  3. Dockerfile +5 -1
  4. Dockerfile.hug +0 -28
  5. Dockerfile.local +0 -86
  6. app.py +0 -23
  7. bin/images/logo_omdena_saudi.png +0 -0
  8. bin/models/__init__.py +0 -0
  9. bin/models/deeplabv3_r50_full_train_dataset_80-20_split_10epochs_no-norm_vhflip30/version +0 -1
  10. bin/models/model.pth +0 -3
  11. config.toml +0 -3
  12. data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0105_svsvt_chunks_10240_13312.tiff +0 -3
  13. data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0105_svswt_chunks_38912_5632.tiff +0 -3
  14. data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0140_svsvt_chunks_45056_8192.tiff +0 -3
  15. data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0141_svsvt_chunks_39936_26624.tiff +0 -3
  16. data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0141_svswt_chunks_46080_46080.tiff +0 -3
  17. data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0142_svswt_chunks_41472_21504.tiff +0 -3
  18. data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0145_svsvt_chunks_5632_28672.tiff +0 -3
  19. data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0161_svsvt_chunks_37888_35840.tiff +0 -3
  20. data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0161_svsvt_chunks_44032_38912.tiff +0 -3
  21. data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0161_svswt_chunks_46080_19456.tiff +0 -3
  22. lib/__init__.py +0 -0
  23. lib/fctTile.py +0 -1
  24. lib/fctWsi.py +0 -1
  25. lib/models/__init__.py +0 -0
  26. lib/models/mdl_autoenc.py +0 -55
  27. lib/models/mdl_kmeans.py +0 -155
  28. lib/models/mdl_logR.py +0 -41
  29. lib/models/mdl_svm.py +0 -40
  30. lib/models/mdl_utils.py +0 -256
  31. lib/models/mdl_xgb.py +0 -66
  32. lib/utils.py +0 -38
  33. main.py +0 -92
  34. packages.txt +0 -3
  35. requirements.txt +0 -87
  36. routes/__init__.py +0 -0
  37. routes/api/__init__.py +0 -0
  38. routes/api/rte_api.py +0 -79
  39. routes/api/rte_tiles.py +0 -198
  40. routes/api/rte_wsi.py +0 -56
  41. routes/qa/__init__.py +0 -0
  42. routes/qa/rte_qa.py +0 -17
  43. scripts/docker/util_docker_preRun.sh +0 -32
  44. scripts/docker/util_local_buildDockerDemo.sh +0 -86
  45. scripts/docker/util_local_runDockerDemo.sh +0 -33
  46. scripts/huggingface/util_local_deploy_toHugSpace.sh +39 -0
  47. scripts/huggingface/util_local_readyDeploy_toHugSpace_streamlit.sh +0 -93
  48. scripts/models/util_joinModel.sh +0 -45
  49. scripts/models/util_splitModel.sh +0 -44
  50. scripts/streamlitFastApi/util_local_runStreamlitFastApi.sh +0 -27
.dockerignore DELETED
@@ -1,21 +0,0 @@
1
-
2
-
3
- #--- ignore select binary files/folders
4
- bin/images/sample*
5
- #---bin/models/*.pth
6
- bin/models/*.zip
7
- bin/models/deeplabv3*vhflip30/*.pth
8
- bin/testing
9
- _ignore
10
- .vscode
11
- cicd_workflows
12
-
13
- #--- ignore all local data files; preserve/recreate folder structure
14
- data/demo_tiles/*.tiff
15
- data/tiles
16
- data/wsi
17
-
18
- #--- ignore all doc files
19
- docs
20
- notebooks
21
- preso
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.gitattributes DELETED
@@ -1,46 +0,0 @@
1
- #--- Note: omdena github does not allow git lfs. Disable.
2
- #--- Note: huggingface does not allow _any_ binaries; git lfs has to be used
3
- #bin/models/*.pth filter=lfs diff=lfs merge=lfs -text
4
- #bin/models/deeplab*vhflip30/model_a* filter=lfs diff=lfs merge=lfs -text
5
- #bin/images/* filter=lfs diff=lfs merge=lfs -text
6
- #data/demo_tiles/raw/* filter=lfs diff=lfs merge=lfs -text
7
- *.7z filter=lfs diff=lfs merge=lfs -text
8
- *.arrow filter=lfs diff=lfs merge=lfs -text
9
- *.bin filter=lfs diff=lfs merge=lfs -text
10
- *.bz2 filter=lfs diff=lfs merge=lfs -text
11
- *.ckpt filter=lfs diff=lfs merge=lfs -text
12
- *.ftz filter=lfs diff=lfs merge=lfs -text
13
- *.gz filter=lfs diff=lfs merge=lfs -text
14
- *.h5 filter=lfs diff=lfs merge=lfs -text
15
- *.joblib filter=lfs diff=lfs merge=lfs -text
16
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
17
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
18
- *.model filter=lfs diff=lfs merge=lfs -text
19
- *.msgpack filter=lfs diff=lfs merge=lfs -text
20
- *.npy filter=lfs diff=lfs merge=lfs -text
21
- *.npz filter=lfs diff=lfs merge=lfs -text
22
- *.onnx filter=lfs diff=lfs merge=lfs -text
23
- *.ot filter=lfs diff=lfs merge=lfs -text
24
- *.parquet filter=lfs diff=lfs merge=lfs -text
25
- *.pb filter=lfs diff=lfs merge=lfs -text
26
- *.pickle filter=lfs diff=lfs merge=lfs -text
27
- *.pkl filter=lfs diff=lfs merge=lfs -text
28
- *.pt filter=lfs diff=lfs merge=lfs -text
29
- *.pth filter=lfs diff=lfs merge=lfs -text
30
- *.rar filter=lfs diff=lfs merge=lfs -text
31
- *.safetensors filter=lfs diff=lfs merge=lfs -text
32
- *.tar.* filter=lfs diff=lfs merge=lfs -text
33
- *.tar filter=lfs diff=lfs merge=lfs -text
34
- *.tflite filter=lfs diff=lfs merge=lfs -text
35
- *.tgz filter=lfs diff=lfs merge=lfs -text
36
- *.wasm filter=lfs diff=lfs merge=lfs -text
37
- *.xz filter=lfs diff=lfs merge=lfs -text
38
- *.zip filter=lfs diff=lfs merge=lfs -text
39
- *.zst filter=lfs diff=lfs merge=lfs -text
40
- *tfevents* filter=lfs diff=lfs merge=lfs -text
41
- *.tiff filter=lfs diff=lfs merge=lfs -text
42
- data/demo_tiles/raw/*.tiff filter=lfs diff=lfs merge=lfs -text
43
- bin/models/deeplabv3*vhflip30/model_a* filter=lfs diff=lfs merge=lfs -text
44
- *model_a* filter=lfs diff=lfs merge=lfs -text
45
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
46
- bin/models/model.pth filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Dockerfile CHANGED
@@ -21,4 +21,8 @@ EXPOSE 39500
21
  # docker run -it -p 49400:39400 -p 49500:39500 --name ctr_stmOmdenaHcc_demo kidcoconut73/img_stm_omdenasaudi_hcc:demo
22
 
23
  #--- start an existing container
24
- # docker start -it ctr_stmOmdenaHcc_demo
 
 
 
 
 
21
  # docker run -it -p 49400:39400 -p 49500:39500 --name ctr_stmOmdenaHcc_demo kidcoconut73/img_stm_omdenasaudi_hcc:demo
22
 
23
  #--- start an existing container
24
+ # docker start -it ctr_stmOmdenaHcc_demo
25
+
26
+ #--- deploy to huggingspace
27
+ # overwrite Dockerfile; cp Dockerfile.hug Dockerfile
28
+ # push to Huggingspace;
Dockerfile.hug DELETED
@@ -1,28 +0,0 @@
1
- #--- build the image from dockerHub
2
- FROM kidcoconut73/img_stm_omdenasaudi_hcc:0.1.4
3
- #FROM kidcoconut73/img_stm_omdenasaudi_hcc:demo
4
-
5
-
6
- #--- for streamlit; external 49400; internal 39400
7
- #--- for fastapi; external 49500; internal 39500
8
- #--- for huggingface; assume 1:1 mapping between internal and external ports; and only one port can truly be exposed
9
- EXPOSE 39400
10
- EXPOSE 39500
11
-
12
- #--- build/rebuild the image from an alt Dockerfile
13
- # docker build -t foo/bar -f /path/to/Dockerfile /path/to/
14
- # docker build -t img_stm_omdenasaudi_hcc:0.1.4 -f Dockerfile.hub ./
15
-
16
- #--- create a container from an image (without running it)
17
- # docker create -it -p 49400:39400 -p 49500:39500 --name ctr_stmOmdenaHcc_demo kidcoconut73/img_stm_omdenasaudi_hcc:demo
18
-
19
- #--- to run the container (interactive) from the image; specific port mapping (-p) vs any available port mapping (-P)
20
- # docker run -it -p 49400:39400 -p 49500:39500 --name ctr_stmOmdenaHcc_demo img_stm_omdenasaudi_hcc:0.1.4
21
- # docker run -it -p 49400:39400 -p 49500:39500 --name ctr_stmOmdenaHcc_demo kidcoconut73/img_stm_omdenasaudi_hcc:demo
22
-
23
- #--- start an existing container
24
- # docker start -it ctr_stmOmdenaHcc_demo
25
-
26
- #--- deploy to huggingspace
27
- # overwrite Dockerfile; cp Dockerfile.hug Dockerfile
28
- # push to Huggingspace;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Dockerfile.local DELETED
@@ -1,86 +0,0 @@
1
- #--- PREREQS:
2
- # - create a local folder dedicated to WSI image mgmt: (docker pwd)/data
3
- # - populate the folder with raw data, wsi and tiles
4
- # - docker run --name <name> -v <local folder>
5
-
6
- #--- utilize a light linux distro for python apps
7
- FROM python:3.10.9-slim-bullseye
8
-
9
- RUN pip install --no-cache-dir --upgrade pip
10
- RUN apt-get update -y && apt-get install -y ffmpeg libsm6 libxext6
11
-
12
- # Set up a new user named "user" with user ID 1000
13
- # Switch to the "user" user
14
- RUN useradd -m -u 1000 user
15
- USER user
16
-
17
- # Set home to the user's home directory
18
- ENV HOME=/home/user \
19
- PATH=/home/user/.local/bin:$PATH
20
-
21
- #--- set docker image working directory to /app
22
- WORKDIR $HOME/app
23
-
24
- # Try and run pip command after setting the user with `USER user` to avoid permission issues with Python
25
- #RUN pip install --no-cache-dir --upgrade pip
26
-
27
-
28
- #--- copy only the requirements.txt file
29
- #--- set docker image working directory to /app
30
- #--- Not: this is reorg'd in an attempt to reduce the rebuilding of layers
31
- COPY --chown=user ./requirements.txt $HOME/app/requirements.txt
32
- COPY --chown=user ./packages.txt $HOME/app/packages.txt
33
-
34
- #--- install all lib dependencies into the image
35
- #RUN pip3 install -r $HOME/app/requirements.txt
36
- RUN pip install --no-cache-dir --upgrade -r $HOME/app/requirements.txt
37
- #RUN apt-get update -y && apt-get install -y ffmpeg libsm6 libxext6
38
-
39
- #--- copy all files from the local pwd to the docker image /app folder
40
- #--- .dockerignore: ensure no local data folders or files (images) are copied into the docker image/container
41
- COPY --chown=user . $HOME/app
42
-
43
- #--- for streamlit; external 49400; internal 39400
44
- # localExec: (from root folder) streamlit run app.py --server.port=39400 --server.maxUploadSize=2000
45
- EXPOSE 49400
46
- #CMD ["streamlit", "run", "app.py", "--server.port=39400", "--server.maxUploadSize=2000"]
47
-
48
- #--- for fastapi; external 49500; internal 39500
49
- # localExec: (from root folder) uvicorn main:app --reload --workers 1 --host 0.0.0.0 --port 39500
50
- EXPOSE 49500
51
- #CMD ["uvicorn", "main:app", "--reload", "--host=0.0.0.0", "--port=39500"]
52
-
53
- #--- start streamlit and fastapi from a helper utility script
54
- #CMD ./util_startLocal_streamlitFastApi.sh
55
- CMD $HOME/app/scripts/docker/util_docker_preRun.sh
56
-
57
-
58
- #--- to build/rebuild the image; make sure you stop and remove the container if you are replacing/upgrading; or change the version tag# from 0.1
59
- # docker build -t img_stm_omdenasaudi_hcc:0.1 .
60
- # docker build -t img_stm_omdenasaudi_hcc:0.1.3 .
61
-
62
- #--- build/rebuild the image from an alt Dockerfile
63
- # docker build -t foo/bar -f /path/to/Dockerfile /path/to/
64
- # docker build -t img_stm_omdenasaudi_hcc:0.1.4 -f Dockerfile.hub ./
65
-
66
- #--- to tag the image prior to push to DockerHub; docker login and then register user/image:tag
67
- #--- to push this image to DockerHub, example based on the repo: kidcoconut73/img_stm_omdenasaudi_hcc
68
- # docker tag img_stm_omdenasaudi_hcc:0.1 kidcoconut73/img_stm_omdenasaudi_hcc:demo
69
- # docker tag img_stm_omdenasaudi_hcc:0.1 kidcoconut73/img_stm_omdenasaudi_hcc:0.1
70
- # docker push kidcoconut73/img_stm_omdenasaudi_hcc:demo
71
-
72
- #--- to run the container from the image; specific port mapping (-p) vs any available port mapping (-P)
73
- # docker run -p 49400:39400 -p 49500:39500 --name ctr_stmOmdenaSaudiHcc -v ./data:/app/data img_stm_omdenasaudi_hcc:0.1
74
- # docker run -p 49400:39400 -p 49500:39500 --name ctr_stmOmdenaSaudiHcc img_stm_omdenasaudi_hcc:0.1
75
- # docker run -P --name ctr_stmOmdenaHcc img_stm_omdenasaudi_hcc:0.1 #--- open all ports defined by Docker EXPOSE
76
-
77
- #--- to run the container in interactive mode (local debug)
78
- # docker run -it -p 49400:39400 -p 49500:39500 --name ctr_stmOmdenaSaudiHcc_013 img_stm_omdenasaudi_hcc:0.1.3
79
-
80
- #--- ISSUE: uvicorn bug does not allow ctl-C break of fastapi through terminal
81
- #--- WORKAROUND: you have to run a docker or docker compose kill cmd; eg docker kill <ctr_name>
82
-
83
-
84
- #--- Docker build log
85
- # from python:3.10.9-slim-bullseye size: 4.21gb time: >yyys
86
- # from python:3.10.9-slim-bullseye size: 4.21gb time: >3500s :0.13 expose streamlit 49400
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py DELETED
@@ -1,23 +0,0 @@
1
- '''
2
- toExecute: (from root app folder) ... streamlit run app.py
3
- '''
4
- import streamlit as st
5
- import uix.lit_sidebar as litSideBar
6
-
7
-
8
- #--- streamlit: specify title and logo
9
- st.set_page_config(
10
- page_title='Omdena Saudi Arabia - Liver HCC Diagnosis with XAI',
11
- #page_icon='https://cdn.freebiesupply.com/logos/thumbs/1x/nvidia-logo.png',
12
- layout="wide")
13
- st.header('\
14
- Detecting Liver Cancer from Histopathology WSI \
15
- using Deep Learning and Explainability (XAI)\
16
- ')
17
- st.markdown('#### Dr. Shaista Hussain (Saudi Arabia Chapter Lead)')
18
- st.markdown("##### Iain McKone (Deployment Lead) [LinkedIn](%s)" % "https://linkedin.com/in/iainmckone")
19
- st.markdown('---')
20
-
21
-
22
- #--- streamlit: add a sidebar
23
- litSideBar.init()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bin/images/logo_omdena_saudi.png DELETED
Binary file (14.1 kB)
 
bin/models/__init__.py DELETED
File without changes
bin/models/deeplabv3_r50_full_train_dataset_80-20_split_10epochs_no-norm_vhflip30/version DELETED
@@ -1 +0,0 @@
1
- 3
 
 
bin/models/model.pth DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:9029cfef04ad8f66b1b59f7417ec0f2eb6721198fb8a31f32dea75d87e1168a8
3
- size 168385213
 
 
 
 
config.toml DELETED
@@ -1,3 +0,0 @@
1
- [server]
2
-
3
- maxUploadSize = 2000 #--- increased from default 200MB to 2000MB
 
 
 
 
data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0105_svsvt_chunks_10240_13312.tiff DELETED

Git LFS Details

  • SHA256: f7f1ead30f809502867630618dc072714d204c3ad191662f5837f70d083dbf76
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0105_svswt_chunks_38912_5632.tiff DELETED

Git LFS Details

  • SHA256: 1c4d4c9a4c03c433098076160a3a9a6142242336475b113d1b423449f56c4736
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0140_svsvt_chunks_45056_8192.tiff DELETED

Git LFS Details

  • SHA256: 4283367c661dc21d397cb42c0ed07c7d0668bed4a531c159be46f8e3283b99fe
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0141_svsvt_chunks_39936_26624.tiff DELETED

Git LFS Details

  • SHA256: 32beafb1e6da830177c68d41d3595346cf6d005b59518c9ff76338465a09f76a
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0141_svswt_chunks_46080_46080.tiff DELETED

Git LFS Details

  • SHA256: 384304ab2e113ef190b025a7706913f2dd305591aa262cb90fbdde4635c90bcc
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0142_svswt_chunks_41472_21504.tiff DELETED

Git LFS Details

  • SHA256: 57e67d534e0bce3f305fca0037b3e5b069dab0dd5b7100b259ae47c21d410345
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0145_svsvt_chunks_5632_28672.tiff DELETED

Git LFS Details

  • SHA256: 31d1a4b039f036a019f2a11e0f3c0002f9c83125b32c8a868aab4c5a996ce1ff
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0161_svsvt_chunks_37888_35840.tiff DELETED

Git LFS Details

  • SHA256: 02e14838208a8afa44c5d7a94a19e95b5ba348e4f243e2445cab00d2d0fe202c
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0161_svsvt_chunks_44032_38912.tiff DELETED

Git LFS Details

  • SHA256: 6a004d358b77bcb115e7a7178e5cea2d11539076069fe557075a07913520db62
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
data/demo_tiles/raw/sample/Dataset_PAIP2019_Omdena_Validation_Image_01_01_0161_svswt_chunks_46080_19456.tiff DELETED

Git LFS Details

  • SHA256: 7450a97f433fda64a85e21883f9b53c9f38f36be18ead29aaac1ee03d6d096ff
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
lib/__init__.py DELETED
File without changes
lib/fctTile.py DELETED
@@ -1 +0,0 @@
1
- #--- factory class for tile operations
 
 
lib/fctWsi.py DELETED
@@ -1 +0,0 @@
1
- #--- factory class for wsi operations
 
 
lib/models/__init__.py DELETED
File without changes
lib/models/mdl_autoenc.py DELETED
@@ -1,55 +0,0 @@
1
- import pandas as pd
2
- import numpy as np
3
- from sklearn.decomposition import PCA
4
- import lib.utils as libPaths
5
- import pickle
6
-
7
-
8
- m_kstrFile = __file__
9
- m_kstrDataPath = libPaths.pth_data
10
- m_kstrBinModelPath = libPaths.pth_binModels
11
- m_kstrPcaModelPath = m_kstrBinModelPath + 'pca_unsuperv_colab.pkl'
12
- m_kstrEncModelPath = m_kstrBinModelPath + 'enc_keras_seq/'
13
-
14
-
15
- #--- Supervised: autoencoder - Principal Component Analysis
16
- def load_encFromKeras():
17
- from tensorflow import keras
18
- mdlAnoms = keras.models.load_model(m_kstrEncModelPath)
19
- return mdlAnoms
20
-
21
-
22
- def load_pcaFromPkl():
23
- with open(m_kstrPcaModelPath, 'rb') as filPkl:
24
- # load using pickle de-serializer
25
- mdlAnoms = pickle.load(filPkl)
26
- return mdlAnoms
27
-
28
-
29
- def save_encToKeras(mdlAnoms):
30
- mdlAnoms.save(m_kstrEncModelPath)
31
-
32
-
33
-
34
- def predict(pdfScaled):
35
-
36
- #--- Pre: Transforming train and test dataframes based on PCA
37
- mdlPCA = load_pcaFromPkl() #--- this is a pre-fit model based on training
38
- npaPca = mdlPCA.transform(pdfScaled)
39
- print("INFO (" + m_kstrFile + ".predict) npaPca.shape: ", npaPca.shape)
40
-
41
-
42
- #--- predict on unseen data
43
- mdlEnc = load_encFromKeras()
44
- npaPredict = mdlEnc.predict(npaPca[:,:29])
45
- print("INFO (" + m_kstrFile + ".predict) npaPredict.shape: ", npaPredict.shape)
46
- #--- expected: 297, 29?
47
- return npaPredict
48
-
49
-
50
- """
51
- def train(pdfTrainData):
52
- mdlAnoms = PCA() #---- TODO: this is Keras Sequential
53
- mdlAnoms.fit(pdfTrainData.values)
54
- save_encToKeras(mdlAnoms)
55
- return mdlAnoms """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/models/mdl_kmeans.py DELETED
@@ -1,155 +0,0 @@
1
- from sklearn.cluster import KMeans
2
- import lib.utils as libPaths
3
- import pickle
4
- import pandas as pd
5
-
6
-
7
- m_kstrFile = __file__
8
- m_kstrDataPath = libPaths.pth_data
9
- m_kstrBinModelPath = libPaths.pth_binModels
10
-
11
- #m_kstrPcaModelPath = m_kstrBinModelPath + 'pca_kmeans_unsuperv_colab.pkl'
12
- #m_kstrPcaModelPath = m_kstrBinModelPath + 'pca_kmeans_unsuperv_colab_v1.2.1.pkl'
13
- m_kstrPcaModelPath_111 = m_kstrBinModelPath + 'claims_pca_v1.1.1_27cols.pkl' #--- ERROR: __randomstate_ctor() takes from 0 to 1 positional arguments but 2 were given
14
- m_kstrPcaModelPath_121 = m_kstrBinModelPath + 'claims_pca_v1.2.1_27cols.pkl'
15
- m_kstrPcaModelPath_claims_py3816_sk111hp = m_kstrBinModelPath + 'claims_pca_py3816_sk111hp_27cols.pkl'
16
- m_kstrPcaModelPath = m_kstrPcaModelPath_claims_py3816_sk111hp
17
-
18
- #m_kstrKmeansModelPath = m_kstrBinModelPath + 'kmeans_unsuperv_colab.pkl'
19
- #m_kstrKmeansModelPath = m_kstrBinModelPath + 'kmn_unsuperv_colab_v1.2.1.pkl'
20
- m_kstrModelPath_111 = m_kstrBinModelPath + 'claims_kmn_v1.1.1_22cols.pkl' #--- ERROR: __randomstate_ctor() takes from 0 to 1 positional arguments but 2 were given
21
- m_kstrModelPath_121 = m_kstrBinModelPath + 'claims_kmn_v1.2.1_22cols.pkl'
22
- m_kstrModelPath_claims_py3816_sk111hp = m_kstrBinModelPath + 'claims_kmn_py3816_sk111hp_22cols.pkl'
23
- m_kstrKmeansModelPath = m_kstrModelPath_claims_py3816_sk111hp
24
-
25
- m_blnTraceOn = True
26
-
27
-
28
- #--- unsupervised: Logistic Regession
29
- def load_pcaFromPkl():
30
- with open(m_kstrPcaModelPath, 'rb') as filPkl:
31
- mdlAnoms = pickle.load(filPkl)
32
- return mdlAnoms
33
-
34
-
35
- #--- unsupervised: KMeans
36
- def load_kmeansFromPkl():
37
- with open(m_kstrKmeansModelPath, 'rb') as filPkl:
38
- mdlAnoms = pickle.load(filPkl)
39
- return mdlAnoms
40
-
41
-
42
- def save_pcaToPkl(mdlAnoms):
43
- with open(m_kstrPcaModelPath, 'wb') as filPkl:
44
- pickle.dump(mdlAnoms, filPkl)
45
- return mdlAnoms
46
-
47
-
48
- def save_kmeansToPkl(mdlAnoms):
49
- with open(m_kstrKmeansModelPath, 'wb') as filPkl:
50
- pickle.dump(mdlAnoms, filPkl)
51
- return mdlAnoms
52
-
53
-
54
-
55
- #--- determine which points can be labelled against which clusters
56
- def predict(pdfScaled):
57
- #--- load a persisted fit kmeans model
58
- #--- predict will assign labels onto a similarly scaled data frame
59
-
60
-
61
- #--- Note: reverse chron through the code ...
62
- #--- 4. KMeans was fit on X-reduced (22 cols)
63
- #--- 3. X_reduced was a reduced column set of X-scaled (27 -> 22; Dropped 5 cols: DeadOrNot; and hotEncoded Gender and Race)
64
- #--- 2. x_scaled was transformed through stdScaler
65
- #--- 1. StdScaler was fit on X to produce X-scaled (X has 27 cols)
66
- pdfReduced = pdfScaled[['InscClaimAmtReimbursed', 'DeductibleAmtPaid',
67
- 'AdmittedDays', 'RenalDiseaseIndicator', 'NoOfMonths_PartACov',
68
- 'NoOfMonths_PartBCov', 'ChronicCond_Alzheimer',
69
- 'ChronicCond_Heartfailure', 'ChronicCond_KidneyDisease',
70
- 'ChronicCond_Cancer', 'ChronicCond_ObstrPulmonary',
71
- 'ChronicCond_Depression', 'ChronicCond_Diabetes',
72
- 'ChronicCond_IschemicHeart', 'ChronicCond_Osteoporasis',
73
- 'ChronicCond_rheumatoidarthritis', 'ChronicCond_stroke',
74
- 'IPAnnualReimbursementAmt', 'IPAnnualDeductibleAmt',
75
- 'OPAnnualReimbursementAmt', 'OPAnnualDeductibleAmt', 'Age']]
76
-
77
- #--- prefit Kmeans clustering - was fit on trained pdfReduced
78
- #--- Note: if we want to understand how kmeans performs on test/prod data, we need to predict
79
- mdlKMeans = load_kmeansFromPkl()
80
- #ndaPredict = mdlKMeans.predict(pdfScaled) #20230208: ValueError: X has 27 features, but KMeans is expecting 22 features as input.
81
- ndaPredict = mdlKMeans.predict(pdfReduced) #ValueError: X has 22 features, but KMeans is expecting 27 features as input.
82
- return ndaPredict
83
-
84
-
85
- #--- feat eng
86
- def do_featEng(pdfLoaded, blnIsTrain=False, hasGroupByProviderCols=True):
87
- print("INFO (mdl_kmeans.doFeatEng): blnIsTrain, ", blnIsTrain)
88
-
89
- #--- columns_to_remove
90
- aryColsToDrop = ['BeneID', 'ClaimID', 'ClaimStartDt','ClaimEndDt','AttendingPhysician',
91
- 'OperatingPhysician', 'OtherPhysician', 'ClmDiagnosisCode_1',
92
- 'ClmDiagnosisCode_2', 'ClmDiagnosisCode_3', 'ClmDiagnosisCode_4',
93
- 'ClmDiagnosisCode_5', 'ClmDiagnosisCode_6', 'ClmDiagnosisCode_7',
94
- 'ClmDiagnosisCode_8', 'ClmDiagnosisCode_9', 'ClmDiagnosisCode_10',
95
- 'ClmProcedureCode_1', 'ClmProcedureCode_2', 'ClmProcedureCode_3',
96
- 'ClmProcedureCode_4', 'ClmProcedureCode_5', 'ClmProcedureCode_6',
97
- 'ClmAdmitDiagnosisCode', 'AdmissionDt',
98
- 'DischargeDt', 'DiagnosisGroupCode','DOB', 'DOD',
99
- 'State', 'County']
100
- pdfFeatEng = pdfLoaded.drop(columns=aryColsToDrop, axis=1)
101
-
102
- #--- flag categorical cols
103
- pdfFeatEng.Gender = pdfFeatEng.Gender.astype('category')
104
- pdfFeatEng.Race = pdfFeatEng.Race.astype('category')
105
-
106
- #--- one-hot-encoding
107
- pdfFeatEng = pd.get_dummies(pdfFeatEng, columns=['Gender', 'Race'], drop_first=True)
108
- if (blnIsTrain):
109
- #--- one-hot encode the potential fraud column (for training data only)
110
- try:
111
- #print("INFO (claims.doFeatEng): one-hot encoding potential fraud")
112
- pdfFeatEng.loc[pdfFeatEng['PotentialFraud'] == 'Yes', 'PotentialFraud'] = 1
113
- pdfFeatEng.loc[pdfFeatEng['PotentialFraud'] == 'No', 'PotentialFraud'] = 0
114
- except KeyError:
115
- #--- likely column not found; invalid fxn call
116
- print("ERROR (claims.doFeatEng): Potential Fraud col not found")
117
-
118
- pdfFeatEng.loc[pdfFeatEng['RenalDiseaseIndicator'] == 'Y', 'RenalDiseaseIndicator'] = 1
119
- pdfFeatEng['DeductibleAmtPaid'].fillna(0, inplace=True)
120
- pdfFeatEng['AdmittedDays'].fillna(0, inplace=True)
121
-
122
- #--- check for correlated cols
123
-
124
- #--- add new features to assist with predictions
125
- if (hasGroupByProviderCols):
126
- pdfFeatEng['InscClaimReimbursement_ProviderAvg'] = pdfFeatEng.groupby(['Provider'])['InscClaimAmtReimbursed'].transform('mean')
127
- pdfFeatEng['DeductibleAmtPaid_ProviderAvg'] = pdfFeatEng.groupby(['Provider'])['DeductibleAmtPaid'].transform('mean')
128
-
129
- pdfFeatEng['IPAnnualReimbursementAmt_ProviderAvg'] = pdfFeatEng.groupby(['Provider'])['IPAnnualReimbursementAmt'].transform('mean')
130
- pdfFeatEng['IPAnnualDeductibleAmt_ProviderAvg'] = pdfFeatEng.groupby(['Provider'])['IPAnnualDeductibleAmt'].transform('mean')
131
-
132
- pdfFeatEng['OPAnnualReimbursementAmt_ProviderAvg'] = pdfFeatEng.groupby(['Provider'])['OPAnnualReimbursementAmt'].transform('mean')
133
- pdfFeatEng['OPAnnualDeductibleAmt_ProviderAvg'] = pdfFeatEng.groupby(['Provider'])['OPAnnualDeductibleAmt'].transform('mean')
134
- return pdfFeatEng
135
-
136
-
137
- def fit(pdfScaled):
138
- #--- determine the centroids of the kmeans clusters
139
- #--- refit kmeans clustering according to the pre-scaled data provided
140
- #--- note: this all assumes that the nature of the data and the number of clusters remain unchanged
141
- m_klngNumClusters = 3
142
- if (m_blnTraceOn): print("TRACE (" + m_kstrFile + ".fit) instantiate KMeans ...")
143
- mdlKMeans = KMeans(n_clusters=m_klngNumClusters, max_iter=50, random_state=2022) #--- #clusters was learned from training
144
-
145
- if (m_blnTraceOn): print("TRACE (" + m_kstrFile + ".fit) fitting data (scaled) ...")
146
- mdlKMeans.fit(pdfScaled) #--- fit on test/prod data
147
-
148
- return mdlKMeans #--- this ibject will give us all results based on kmeans
149
-
150
-
151
- def train(pdfTrainData):
152
- mdlAnoms = KMeans(n_clusters=3, max_iter=50, random_state=2022)
153
- mdlAnoms.fit(pdfTrainData.values)
154
- save_kmeansToPkl(mdlAnoms)
155
- return mdlAnoms
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/models/mdl_logR.py DELETED
@@ -1,41 +0,0 @@
1
- from sklearn.linear_model import LogisticRegressionCV
2
- import lib.utils as libPaths
3
- import pickle
4
-
5
-
6
- m_kstrFile = __file__
7
- m_kstrDataPath = libPaths.pth_data
8
- m_kstrBinModelPath = libPaths.pth_binModels
9
- m_kstrModelPath = m_kstrBinModelPath + 'lgr_model_colab.pkl'
10
-
11
-
12
- #--- Supervised: Logistic Regession
13
- def load_fromPkl():
14
- with open(m_kstrModelPath, 'rb') as filPkl:
15
- mdlAnoms = pickle.load(filPkl)
16
- return mdlAnoms
17
-
18
-
19
-
20
- def save_toPkl(mdlAnoms):
21
- with open(m_kstrModelPath, 'wb') as filPkl:
22
- pickle.dump(mdlAnoms, filPkl)
23
- return mdlAnoms
24
-
25
-
26
-
27
- def predict(npaData):
28
- #--- input: numpy.ndarray of feature eng, and scaled data
29
- mdlAnoms = load_fromPkl()
30
- npaPredict = mdlAnoms.predict(npaData)
31
-
32
- print("INFO (npaPredict.shape): ", npaPredict.shape)
33
- return npaPredict
34
-
35
-
36
-
37
- def train(pdfTrainData):
38
- mdlAnoms = LogisticRegressionCV()
39
- mdlAnoms.fit(pdfTrainData.values)
40
- save_toPkl(mdlAnoms)
41
- return mdlAnoms
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/models/mdl_svm.py DELETED
@@ -1,40 +0,0 @@
1
- from sklearn.svm import LinearSVC
2
- import lib.utils as libPaths
3
- import pickle
4
-
5
-
6
- m_kstrFile = __file__
7
- m_kstrDataPath = libPaths.pth_data
8
- m_kstrBinModelPath = libPaths.pth_binModels
9
- m_kstrModelPath = m_kstrBinModelPath + 'svm_model_colab.pkl'
10
-
11
-
12
- #--- Supervised: Support Vector Machines
13
- def load_fromPkl():
14
- with open(m_kstrModelPath, 'rb') as filPkl:
15
- mdlAnoms = pickle.load(filPkl)
16
- return mdlAnoms
17
-
18
-
19
-
20
- def save_toPkl(mdlAnoms):
21
- with open(m_kstrModelPath, 'wb') as filPkl:
22
- pickle.dump(mdlAnoms, filPkl)
23
- return mdlAnoms
24
-
25
-
26
-
27
- def predict(npaData):
28
- #--- input: numpy.ndarray of feature eng, and scaled data
29
- mdlAnoms = load_fromPkl()
30
- npaPredict = mdlAnoms.predict(npaData)
31
- print("INFO (" + m_kstrFile + ".predict) npaPredict.shape: ", npaPredict.shape)
32
- return npaPredict
33
-
34
-
35
-
36
- def train(pdfTrainData):
37
- mdlAnoms = LinearSVC()
38
- mdlAnoms.fit(pdfTrainData.values)
39
- save_toPkl(mdlAnoms)
40
- return mdlAnoms
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/models/mdl_utils.py DELETED
@@ -1,256 +0,0 @@
1
- import pandas as pd
2
- import pickle
3
- import lib.utils as libPaths
4
-
5
- m_blnTraceOn = False
6
-
7
- #--- load, merge data from file
8
- m_kstrDataPath = libPaths.pth_data
9
- m_kstrModelPath = libPaths.pth_model
10
- m_kstrBinModelPath = libPaths.pth_binModels
11
-
12
- #m_kstrScalerPath_claims = m_kstrBinModelPath + 'stdClaims_scaler_colab.pkl' #--- does not work for scaling claims data; from v1.0.2; using 1.1.1
13
- #m_kstrScalerPath_claims2 = m_kstrBinModelPath + 'std_scaler_unsuperv_colab.pkl' #--- does not work; expects 32 features
14
- #m_kstrScalerPath_claims = m_kstrBinModelPath + 'stdClaims_scaler_colab_v1.2.1.pkl'
15
- m_kstrScalerPath_claims111 = m_kstrBinModelPath + 'claims_stdScaler_v1.1.1_27cols.pkl'
16
- m_kstrScalerPath_claims121 = m_kstrBinModelPath + 'claims_stdScaler_v1.2.1_27cols.pkl'
17
- m_kstrScalerPath_claims_py3816_sk111hp = m_kstrBinModelPath + 'claims_stdScl_py3816_sk111hp_27cols.pkl'
18
- m_kstrScalerPath_claims = m_kstrScalerPath_claims_py3816_sk111hp
19
-
20
- m_kstrScalerPath_providers111 = m_kstrBinModelPath + 'prov_stdScaler_v1.1.1_32cols.pkl'
21
- m_kstrScalerPath_providers121 = m_kstrBinModelPath + 'prov_stdScaler_v1.2.1_32cols.pkl'
22
- m_kstrScalerPath_prov_py3816_sk111 = m_kstrBinModelPath + 'prov_stdScl_py3816_sk111_32cols.pkl'
23
- m_kstrScalerPath_prov_py3816_sk111hp = m_kstrBinModelPath + 'prov_stdScl_py3816_sk111hp_32cols.pkl'
24
- m_kstrScalerPath_prov = m_kstrScalerPath_prov_py3816_sk111hp
25
-
26
- m_kstrScalerPath_providers_superv = m_kstrBinModelPath + 'gbc_scaler.pkl'
27
- m_kstrScalerPath_providers_train = m_kstrBinModelPath + "stdProvider_scaler.pkl"
28
-
29
-
30
-
31
- def doProviders_stdScaler(pdfFeatEng, blnIsTrain=False, hasGroupByProviderCols=True):
32
- print("INFO (claims.do_stdScaler): blnIsTrain, ", blnIsTrain)
33
-
34
- #--- Note: prediction runs on X_val
35
- '''
36
- #--- WARN: The default value of numeric_only in DataFrameGroupBy.sum is deprecated.
37
- # In a future version, numeric_only will default to False. Either specify
38
- # numeric_only or select only columns which should be valid for the function.
39
- '''
40
-
41
- #--- WARN: this code groups all data by provider; any predictions will also be by provider
42
- pdfGroupBy = pdfFeatEng
43
- if (hasGroupByProviderCols):
44
- pdfGroupBy = pdfFeatEng.groupby(['Provider'], as_index=False).agg('sum')
45
-
46
- X = pdfGroupBy
47
-
48
- try:
49
- X = X.drop(columns=['Provider'], axis=1) #--- cannot scale; text
50
- except KeyError:
51
- #--- likely column not found; invalid fxn call
52
- print("ERROR (mdlUtils.doProviders_stdScaler): Provider col not found")
53
-
54
- try:
55
- X = X.drop(columns=['PotentialFraud'], axis=1)
56
- except KeyError:
57
- #--- likely column not found; invalid fxn call
58
- if (blnIsTrain): print("ERROR (mdlUtils.doProviders_stdScaler): Potential Fraud col not found")
59
-
60
-
61
- #--- apply std scaler
62
- #--- WARN: scaling is also grouped by provider
63
- if (m_blnTraceOn): print("INFO (mdlUtils.doProviders_stdScaler) cols: ", X.columns) #--- 32cols
64
- X_std = fitProviders_txfStdScaler(X, blnIsTrain)
65
- return X_std
66
-
67
-
68
-
69
- def doClaims_stdScaler(pdfFeatEng, blnIsTrain=False):
70
- print("INFO (mdlUtils.doClaims_stdScaler): blnIsTrain, ", blnIsTrain)
71
-
72
- #--- Note: prediction runs on X_val
73
- '''
74
- #--- WARN: The default value of numeric_only in DataFrameGroupBy.sum is deprecated.
75
- # In a future version, numeric_only will default to False. Either specify
76
- # numeric_only or select only columns which should be valid for the function.
77
- '''
78
-
79
- #--- WARN: this code groups all data by provider; any predictions will also be by provider
80
- X = pdfFeatEng
81
-
82
- try:
83
- X = X.drop(columns=['Provider'], axis=1) #--- cannot scale; text
84
- except KeyError:
85
- #--- likely column not found; invalid fxn call
86
- print("ERROR (mdlUtils.do_stdScaler): Provider col not found")
87
-
88
- try:
89
- X = X.drop(columns=['PotentialFraud'], axis=1)
90
- except KeyError:
91
- #--- likely column not found; invalid fxn call
92
- if (blnIsTrain): print("ERROR (mdlUtils.do_stdScaler): Potential Fraud col not found")
93
-
94
-
95
- #--- apply std scaler
96
- #--- WARN: scaling is also grouped by provider
97
- #print("INFO (mdlUtils.doClaims_stdScaler) cols: ", X.columns)
98
- X_std = fitClaims_txfStdScaler(X, blnIsTrain)
99
- return X_std
100
-
101
-
102
-
103
- def doProviders_stdScaler_toPdf(npaScaled):
104
- #--- NOTE: the list of cols came from doProvider_stdScaler; print(X.columns)
105
- aryCols = ['InscClaimAmtReimbursed', 'DeductibleAmtPaid', 'AdmittedDays',
106
- 'NoOfMonths_PartACov', 'NoOfMonths_PartBCov', 'ChronicCond_Alzheimer',
107
- 'ChronicCond_Heartfailure', 'ChronicCond_KidneyDisease',
108
- 'ChronicCond_Cancer', 'ChronicCond_ObstrPulmonary',
109
- 'ChronicCond_Depression', 'ChronicCond_Diabetes',
110
- 'ChronicCond_IschemicHeart', 'ChronicCond_Osteoporasis',
111
- 'ChronicCond_rheumatoidarthritis', 'ChronicCond_stroke',
112
- 'IPAnnualReimbursementAmt', 'IPAnnualDeductibleAmt',
113
- 'OPAnnualReimbursementAmt', 'OPAnnualDeductibleAmt', 'Age', 'DeadOrNot',
114
- 'Gender_2', 'Race_2', 'Race_3', 'Race_5',
115
- 'ClaimReimbursement_ProviderAvg',
116
- 'ClaimReimbursement_AttendingPhysician',
117
- 'ClaimReimbursement_OperatingPhysician',
118
- 'DeductibleAmtPaid_ProviderAvg', 'DeductibleAmtPaid_AttendingPhysician',
119
- 'DeductibleAmtPaid_OperatingPhysician']
120
-
121
- #npaScaled = do_stdScaler(pdfFeatEng)
122
- pdfScaled = pd.DataFrame(npaScaled, columns=aryCols)
123
- return pdfScaled
124
-
125
-
126
-
127
- def doClaims_stdScaler_toPdf(npaScaled):
128
- #--- NOTE: the list of cols came from doClaims_stdScaler; print(X.columns)
129
- aryCols = ['InscClaimAmtReimbursed', 'DeductibleAmtPaid', 'AdmittedDays',
130
- 'RenalDiseaseIndicator', 'NoOfMonths_PartACov', 'NoOfMonths_PartBCov', 'ChronicCond_Alzheimer',
131
- 'ChronicCond_Heartfailure', 'ChronicCond_KidneyDisease',
132
- 'ChronicCond_Cancer', 'ChronicCond_ObstrPulmonary',
133
- 'ChronicCond_Depression', 'ChronicCond_Diabetes',
134
- 'ChronicCond_IschemicHeart', 'ChronicCond_Osteoporasis',
135
- 'ChronicCond_rheumatoidarthritis', 'ChronicCond_stroke',
136
- 'IPAnnualReimbursementAmt', 'IPAnnualDeductibleAmt',
137
- 'OPAnnualReimbursementAmt', 'OPAnnualDeductibleAmt', 'Age', 'DeadOrNot',
138
- 'Gender_2', 'Race_2', 'Race_3', 'Race_5']
139
-
140
- #npaScaled = do_stdScaler(pdfFeatEng)
141
- pdfScaled = pd.DataFrame(npaScaled, columns=aryCols)
142
- return pdfScaled
143
-
144
-
145
-
146
-
147
- def fitClaims_stdScaler(pdfData, blnIsTrain=False):
148
- #--- apply scaler
149
- #--- WARN: scaling is not grouped by provider
150
- from sklearn.preprocessing import StandardScaler
151
-
152
- #--- note: this is a numpy.ndarray
153
- #--- we need to fit the scaler, and then save as a pkl file
154
- #strScalerPath = m_kstrScalerPath_claims
155
- strScalerPath = m_kstrScalerPath_claims
156
- # strScalerPath = m_kstrBinModelPath + "stdClaims_scaler_colab.pkl"
157
- if (m_blnTraceOn): print("INFO (lib.model.fitClaims_stdScalar): ", strScalerPath)
158
- if (blnIsTrain):
159
- scaler = StandardScaler()
160
- sclFit = scaler.fit(pdfData)
161
- #--- if we train locally; write out to gbc_scalar.pkl
162
- #--- we do not want to overwrite the colab version used for test
163
- strScalerPath = m_kstrBinModelPath + "stdClaims_scaler.pkl"
164
- if (m_blnTraceOn): print("INFO (lib.model.fit_stdScalar) Using local pkl for Train: ", strScalerPath)
165
- with open(strScalerPath, 'wb') as filPkl:
166
- pickle.dump(sclFit, filPkl)
167
- else:
168
- #--- we need to load the pkl file
169
- import sklearn
170
- if (m_blnTraceOn): print("INFO (lib.model.fit_stdScalar) Using colab pkl for Test: ", strScalerPath)
171
- with open(strScalerPath, 'rb') as filPkl:
172
- sclFit = pickle.load(filPkl)
173
- if (m_blnTraceOn): print("TRACE (libModel.fitClaims_stdScalar) sclFit.type: ", type(sclFit))
174
-
175
- #--- testing
176
- scaler = StandardScaler()
177
- if (m_blnTraceOn): print("TRACE (libModel.fitClaims_stdScalar) StdScaler.version: ", scaler.__getstate__()['_sklearn_version'])
178
- if (m_blnTraceOn): print("TRACE (libModel.fitClaims_stdScalar) sclFit.version: " , sclFit.__getstate__()['_sklearn_version'])
179
- if (m_blnTraceOn): print("TRACE (libModel.fitClaims_stdScalar) sklearn.version: " , sklearn.__version__)
180
- return sclFit
181
-
182
-
183
-
184
- def fitProviders_stdScaler(pdfData, blnIsTrain=False):
185
- #--- apply scaler
186
- #--- WARN: scaling is also grouped by provider
187
- from sklearn.preprocessing import StandardScaler
188
-
189
- #--- note: this is a numpy.ndarray
190
- #--- we need to fit the scaler, and then save as a pkl file
191
- #strScalerPath = m_kstrScalerPath_providers
192
- #strScalerPath = m_kstrScalerPath_providers_train
193
- strScalerPath = m_kstrScalerPath_prov
194
- print("INFO (libModel.fitProviders_stdScalar): ", strScalerPath)
195
- if (blnIsTrain):
196
- scaler = StandardScaler()
197
- sclFit = scaler.fit(pdfData)
198
- #--- if we train locally; write out to gbc_scalar.pkl
199
- #--- we do not want to overwrite the colab version used for test
200
- strScalerPath = m_kstrScalerPath_providers_train #--- works for provider training
201
- if (m_blnTraceOn): print("TRACE (libModel.fitProviders_stdScalar) Using local pkl for Train: ", strScalerPath)
202
- with open(strScalerPath, 'wb') as filPkl:
203
- pickle.dump(sclFit, filPkl)
204
- else:
205
- #--- we need to load the pkl file
206
- if (m_blnTraceOn): print("TRACE (libModel.fitProviders_stdScalar) Using colab pkl for Test: ", strScalerPath)
207
- with open(strScalerPath, 'rb') as filPkl:
208
- sclFit = pickle.load(filPkl)
209
- if (m_blnTraceOn): print("TRACE (libModel.fitProviders_stdScalar) sclFit.type: ", type(sclFit))
210
- return sclFit
211
-
212
-
213
-
214
- def fitProviders_stdScalerSuperv(pdfData, blnIsTrain=False):
215
- #--- apply scaler
216
- #--- WARN: scaling is also grouped by provider
217
- from sklearn.preprocessing import StandardScaler
218
-
219
- #--- note: this is a numpy.ndarray
220
- #--- we need to fit the scaler, and then save as a pkl file
221
- strScalerPath = m_kstrScalerPath_prov
222
- if (m_blnTraceOn): print("TRACE (libModel.fitProviders_stdScalar): ", strScalerPath)
223
- if (blnIsTrain):
224
- scaler = StandardScaler()
225
- sclFit = scaler.fit(pdfData)
226
- #--- if we train locally; write out to gbc_scalar.pkl
227
- #--- we do not want to overwrite the colab version used for test
228
- strScalerPath = m_kstrBinModelPath + "stdProvider_scaler.pkl"
229
- if (m_blnTraceOn): print("TRACE (libModel.fitProviders_stdScalar) Using local pkl for Train: ", strScalerPath)
230
- with open(strScalerPath, 'wb') as filPkl:
231
- pickle.dump(sclFit, filPkl)
232
- else:
233
- #--- we need to load the pkl file
234
- if (m_blnTraceOn): print("TRACE (libModel.fitProviders_stdScalar) Using colab pkl for Test: ", strScalerPath)
235
- with open(strScalerPath, 'rb') as filPkl:
236
- sclFit = pickle.load(filPkl)
237
- if (m_blnTraceOn): print("TRACE (libModel.fitProviders_stdScalar) sclFit.type: ", type(sclFit))
238
- return sclFit
239
-
240
-
241
-
242
- def fitProviders_txfStdScaler(pdfData, blnIsTrain=False):
243
- from sklearn.preprocessing import StandardScaler
244
- sclFit = fitProviders_stdScaler(pdfData, blnIsTrain)
245
- X_std = sclFit.transform(pdfData)
246
- return X_std
247
-
248
-
249
-
250
- def fitClaims_txfStdScaler(pdfData, blnIsTrain=False):
251
- from sklearn.preprocessing import StandardScaler
252
- sclFit = fitClaims_stdScaler(pdfData, blnIsTrain)
253
-
254
-
255
- X_std = sclFit.transform(pdfData)
256
- return X_std
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/models/mdl_xgb.py DELETED
@@ -1,66 +0,0 @@
1
- import pandas as pd
2
- from sklearn.ensemble import GradientBoostingClassifier
3
- import lib.utils as libPaths
4
- import pickle
5
- import sys
6
-
7
-
8
- m_kstrFile = __file__
9
- m_kstrDataPath = libPaths.pth_data
10
- m_kstrBinModelPath = libPaths.pth_binModels
11
- m_kstrModelPath_gbc = m_kstrBinModelPath + 'gbc_model_colab.pkl'
12
- m_kstrModelPath_prov111 = m_kstrBinModelPath + 'prov_gbc_v1.1.1_32cols.pkl' #--- ERROR: __randomstate_ctor() takes from 0 to 1 positional arguments but 2 were given
13
- m_kstrModelPath_prov121 = m_kstrBinModelPath + 'prov_gbc_v1.2.1_32cols.pkl'
14
- m_kstrModelPath_prov_py3816_sk111hp = m_kstrBinModelPath + 'prov_gbc_py3816_sk111hp_32cols.pkl'
15
- m_kstrModelPath = m_kstrModelPath_prov_py3816_sk111hp
16
-
17
- m_blnTraceOn = True
18
-
19
-
20
-
21
- #--- Supervised: xg boost; gradient boosting classifier
22
- def load_fromPkl():
23
- try:
24
- with open(m_kstrModelPath, 'rb') as filPkl:
25
- mdlAnoms = pickle.load(filPkl)
26
- return mdlAnoms
27
-
28
- except:
29
- e = sys.exc_info()
30
- print("ERROR (mdl_xgb.load_fromPkl_genError): ", e)
31
-
32
-
33
-
34
- def save_toPkl(mdlAnoms):
35
- with open(m_kstrModelPath, 'wb') as filPkl:
36
- pickle.dump(mdlAnoms, filPkl)
37
- return mdlAnoms
38
-
39
-
40
-
41
- def predict(npaData):
42
-
43
- try:
44
- #--- input: numpy.ndarray of feature eng, and scaled data
45
- mdlAnoms = load_fromPkl()
46
- if (m_blnTraceOn): print("TRACE (mdl_xgb.predict): data loaded ... ")
47
- npaPredict = mdlAnoms.predict(npaData)
48
-
49
- except:
50
- e = sys.exc_info()
51
- print("ERROR (mdl_xgb.predict_genError1): ", e)
52
-
53
-
54
- #--- AttributeError: 'GradientBoostingClassifier' object has no attribute '_loss'
55
- #--- version of scikit-learn? Monika: ?.?.? ; Iain: 1.2.0
56
-
57
- #print("INFO (type.npaPredict): ", type(npaPredict))
58
- #if (m_blnTraceOn): print("TRACE (mdl_xgb.predict) npaPredict.shape: ", npaPredict.shape)
59
- return npaPredict
60
-
61
-
62
- def train(pdfTrainData):
63
- mdlAnoms = GradientBoostingClassifier()
64
- mdlAnoms.fit(pdfTrainData.values)
65
- save_toPkl(mdlAnoms)
66
- return mdlAnoms
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/utils.py DELETED
@@ -1,38 +0,0 @@
1
- #--- notes:
2
- # - this file is loaded by fastapi and streamlit, so keep it independant of those libs
3
- # - all path are relative to the appl working folder: the parent of the lib folder; ie ..\.. to this file
4
-
5
- from pathlib import Path
6
-
7
- pth_pwd = Path(__file__).resolve().parent #--- should be \lib
8
- pth_appRoot = pth_pwd.parent #--- ..
9
-
10
- pth_root = str(pth_appRoot) + "/"
11
-
12
- pth_bin = pth_root + "bin/"
13
- pth_data = pth_root + "data/"
14
- pth_lib = pth_root + "lib/"
15
- pth_routes = pth_root + "routes/"
16
- pth_templ = pth_root + "templ/"
17
- pth_uix = pth_root + "uix/"
18
-
19
- #--- bin paths
20
- pth_binImages = pth_bin + "images/"
21
- pth_binModels = pth_bin + "models/"
22
-
23
- #--- data paths
24
- pth_dtaApp = pth_data #--- working folders for app data; for docker, should be mapped to local host mount
25
- pth_dtaDemoTiles = pth_data + "demo_tiles/" #--- dedicated area for demo data
26
- pth_dtaTiles = pth_data + "tiles/"
27
- pth_dtaWsi = pth_data + "wsi/"
28
- pth_dtaTileSamples = pth_dtaDemoTiles + "raw/sample/"
29
-
30
- #--- lib paths
31
- pth_libModels = pth_lib + "models/"
32
-
33
- #--- route paths
34
- pth_rteApi = pth_routes + "api/"
35
- pth_rteQa = pth_routes + "qa/"
36
-
37
- m_klngMaxRecords = 100
38
- m_klngSampleSize = 25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
main.py DELETED
@@ -1,92 +0,0 @@
1
- '''
2
- purpose: fastAPI routing
3
- '''
4
-
5
- from fastapi import FastAPI
6
- from fastapi.responses import HTMLResponse
7
- from fastapi import APIRouter, Request, Response
8
- from fastapi.templating import Jinja2Templates
9
- import uvicorn
10
-
11
- #--- import custom libraries
12
- import lib.utils as libUtils
13
-
14
-
15
- #--- imported route handlers
16
- from routes.api.rte_api import rteApi
17
- from routes.api.rte_wsi import rteWsi
18
- from routes.api.rte_tiles import rteTiles
19
-
20
-
21
- #--- fastAPI self doc descriptors
22
- description = """
23
- Omdena Saudi Arabia: Liver Cancer HCC Diagnosis with XAI
24
-
25
- <insert purpose>
26
-
27
- ## key business benefit #1
28
- ## key business benefit #2
29
- ## key business benefit #3
30
-
31
- You will be able to:
32
- * key feature #1
33
- * key feature #2
34
- * key feature #3
35
- """
36
-
37
- app = FastAPI(
38
- title="App: Omdena Saudi Arabia - Liver Cancer HCC Diagnosis with XAI",
39
- description=description,
40
- version="0.0.1",
41
- terms_of_service="http://example.com/terms/",
42
- contact={
43
- "name": "Iain McKone",
44
- "email": "iain.mckone@gmail.com",
45
- },
46
- license_info={
47
- "name": "Apache 2.0",
48
- "url": "https://www.apache.org/licenses/LICENSE-2.0.html",
49
- },
50
- )
51
-
52
-
53
- #--- configure route handlers
54
- app.include_router(rteWsi, prefix="/api/wsi")
55
- app.include_router(rteTiles, prefix="/api/tiles")
56
- app.include_router(rteApi, prefix="/api")
57
-
58
- #app.include_router(rteQa, prefix="/qa")
59
-
60
-
61
- m_kstrPath_templ = libUtils.pth_templ
62
- m_templRef = Jinja2Templates(directory=str(m_kstrPath_templ))
63
-
64
-
65
- def get_jinja2Templ(request: Request, pdfResults, strParamTitle, lngNumRecords, blnIsTrain=False, blnIsSample=False):
66
- lngNumRecords = min(lngNumRecords, libUtils.m_klngMaxRecords)
67
- if (blnIsTrain): strParamTitle = strParamTitle + " - Training Data"
68
- if (not blnIsTrain): strParamTitle = strParamTitle + " - Test Data"
69
- if (blnIsSample): lngNumRecords = libUtils.m_klngSampleSize
70
- strParamTitle = strParamTitle + " - max " + str(lngNumRecords) + " rows"
71
-
72
- kstrTempl = 'templ_showDataframe.html'
73
- jsonContext = {'request': request,
74
- 'paramTitle': strParamTitle,
75
- 'paramDataframe': pdfResults.sample(lngNumRecords).to_html(classes='table table-striped')
76
- }
77
- result = m_templRef.TemplateResponse(kstrTempl, jsonContext)
78
- return result
79
-
80
-
81
- #--- get main ui/ux entry point
82
- @app.get('/')
83
- def index():
84
- return {
85
- "message": "Landing page: Omdena Saudi Arabia - Liver HCC Diagnosis with XAI"
86
- }
87
-
88
-
89
-
90
- if __name__ == '__main__':
91
- uvicorn.run("main:app", host="0.0.0.0", port=49300, reload=True)
92
- #CMD ["uvicorn", "main:app", "--host=0.0.0.0", "--reload"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
packages.txt DELETED
@@ -1,3 +0,0 @@
1
- ffmpeg
2
- libsm6
3
- libxext6
 
 
 
 
requirements.txt DELETED
@@ -1,87 +0,0 @@
1
- #--- 20240625: attempt to set the minimum version based on a working v0.1.2
2
- #--- 20230530: commented out all secondary packages as they were causing the huggingfaceSpace to fail
3
-
4
- altair<=5.0.1
5
- anyio<=3.7.1
6
- attrs<=23.1.0
7
- #backports.zoneinfo==0.2.1
8
-
9
- #blinker==1.6.2
10
- #cachetools==5.3.0
11
- #certifi==2023.5.7
12
- #charset-normalizer==3.1.0
13
- #click==8.1.3
14
-
15
- #decorator==5.1.1
16
- #entrypoints==0.4
17
-
18
- fastapi<=0.95.2
19
-
20
- #gitdb==4.0.10
21
- #git-lfs
22
-
23
- #GitPython==3.1.31
24
- grad-cam<=1.4.8
25
- #h11==0.14.0
26
- #idna==3.4
27
- #importlib-metadata==6.6.0
28
- #importlib-resources==5.12.0
29
- #ipython-genutils==0.2.0
30
-
31
- Jinja2<=3.1.2
32
- joblib<=1.2.0
33
- jsonschema<=4.17.3
34
-
35
- #markdown-it-py==2.2.0
36
- #MarkupSafe==2.1.2
37
-
38
- matplotlib<=3.7.2
39
-
40
- #mdurl==0.1.2
41
-
42
- numpy<=1.24.3
43
- #packaging==23.1
44
-
45
- pandas<=1.5.3
46
- #Pillow==9.5.0
47
- pip<=22.3.1
48
- #pkgutil_resolve_name==1.3.10
49
-
50
- plotly<=5.14.1
51
- #protobuf==4.23.3
52
- #pyarrow==12.0.1
53
- #pydantic==1.10.11
54
- #pydeck==0.8.1b0
55
- #Pygments==2.15.1
56
- #Pympler==1.0.1
57
- #pyrsistent==0.19.3
58
- #python-dateutil==2.8.2
59
- #pytz==2023.3
60
- #PyYAML==6.0
61
- #requests==2.31.0
62
- #rich==13.4.2
63
-
64
- scikit-learn==1.1.1
65
- #scipy<=1.11.1
66
- #six<=1.16.0
67
- #smmap==5.0.0
68
- #sniffio==1.3.0
69
- #starlette==0.27.0
70
- streamlit==1.24.0
71
-
72
- #tenacity==8.2.2
73
- #threadpoolctl==3.1.0
74
- #toml==0.10.2
75
- #toolz==0.12.0
76
-
77
- torch<=2.0.1
78
- torchvision<=0.15.2
79
- #tornado==6.3.2
80
-
81
- #typing_extensions==4.6.2
82
- #tzlocal==5.0.1
83
- #urllib3==2.0.2
84
- uvicorn<=0.22.0
85
- #validators==0.20.0
86
- #watchdog==3.0.0
87
- #zipp==3.15.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
routes/__init__.py DELETED
File without changes
routes/api/__init__.py DELETED
File without changes
routes/api/rte_api.py DELETED
@@ -1,79 +0,0 @@
1
- from fastapi import APIRouter, Request, Response
2
- from fastapi.responses import JSONResponse
3
-
4
- import pandas as pd
5
- import json
6
-
7
- #import lib.claims as libClaims
8
- #from lib.models import mdl_utils, mdl_xgb
9
-
10
-
11
- rteApi = APIRouter()
12
-
13
-
14
- #---
15
- @rteApi.get('/')
16
- def api_entry():
17
- return {
18
- "message": "api routing - welcome to Omdena Saudi HCC api"
19
- }
20
-
21
-
22
-
23
- '''
24
- #--- >>> SAMPLE CODE BELOW
25
- #--- return json for claims data (merged)
26
- #--- note: current is kaggle, but future could include from yyyymm filter
27
- @rteApi.get('/claims', response_class = JSONResponse)
28
- def api_getClaims(request: Request, response: Response):
29
- pdfClaims = libClaims.load_claims()
30
- jsonSample = pdfClaims.head(50).to_json(orient="records", indent=4)
31
- result = json.loads(jsonSample)
32
- return result
33
-
34
-
35
- #--- return json for featEng
36
- @rteApi.get('/claims/doFeatEng/', response_class = JSONResponse)
37
- def tst_claims_featEng():
38
- pdfClaims = libClaims.load_claims()
39
- pdfFeatEng = libClaims.do_featEng(pdfClaims)
40
- jsonSample = pdfClaims.head(50).to_json(orient="records", indent=4)
41
- result = json.loads(jsonSample)
42
- return result
43
-
44
-
45
- @rteApi.get('/claims/doStdScaling/', response_class = JSONResponse)
46
- def tst_claims_stdScaling():
47
- pdfClaims = libClaims.load_claims()
48
- pdfFeatEng = libClaims.do_featEng(pdfClaims)
49
- pdfScaled = mdl_utils.doClaims_stdScaler_toPdf(pdfFeatEng)
50
-
51
- jsonSample = pdfClaims.head(50).to_json(orient="records", indent=4)
52
- result = json.loads(jsonSample)
53
- return result
54
-
55
-
56
- @rteApi.get('/claims/predict/superv', response_class = JSONResponse)
57
- @rteApi.get('/claims/predict/xgb', response_class = JSONResponse)
58
- def predict_xgb():
59
- #--- load test data
60
- pdfClaims = libClaims.load_claims()
61
- pdfFeatEng = libClaims.do_featEng(pdfClaims)
62
-
63
- npaScaled = mdl_utils.do_stdScaler(pdfFeatEng)
64
- pdfScaled = mdl_utils.do_stdScaler_toPdf(npaScaled)
65
-
66
- ndaPredict = mdl_xgb.predict(npaScaled)
67
- pdfPredict = pd.DataFrame(ndaPredict)
68
-
69
- #--- stitch the grouped data with the labels
70
- pdfResults = pdfScaled.copy()
71
- pdfResults.insert(0, "hasAnom?", pdfPredict[0])
72
-
73
- #--- filter to only those rows that are flagged with an anomaly
74
- pdfResults = pdfResults[pdfResults['hasAnom?'] > 0]
75
-
76
- jsonSample = pdfResults.head(50).to_json(orient="records", indent=4)
77
- result = json.loads(jsonSample)
78
- return result
79
- '''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
routes/api/rte_tiles.py DELETED
@@ -1,198 +0,0 @@
1
- from fastapi import APIRouter, Request, Response
2
- from fastapi.responses import HTMLResponse
3
- import numpy as np
4
- import cv2
5
- import os
6
-
7
-
8
- import main as libMain
9
- from lib import utils as libUtils
10
-
11
-
12
- m_kstrFile = __file__
13
- m_blnTraceOn = True
14
-
15
- m_kstrPath_templ = libUtils.pth_templ
16
-
17
-
18
- rteTiles = APIRouter()
19
-
20
-
21
- #---
22
- @rteTiles.get('/')
23
- def api_tiles():
24
- return {
25
- "message": "tiles api endpoint - welcome to the endpoint for tile image processing"
26
- }
27
-
28
-
29
- #---
30
- @rteTiles.get('/raw/upload')
31
- def api_tilesRawUpload():
32
- '''
33
- process an array of uploaded raw Tiles (from external app path)
34
- - cleanup all old raw images in /data/tiles/raw
35
- - save uploads to /data/tiles/raw
36
- - create tile class obj; capture file path, size, zoomMagnif, etc
37
- - create array of tile class objs
38
- - return(s) json
39
- - ack tile/raw uploads with info/attribs
40
- '''
41
- return {
42
- "message": "tilesRawUpload endpoint - file processing of raw tile images"
43
- }
44
-
45
-
46
- @rteTiles.get('/raw/norm')
47
- def api_tilesRawNormalize(strPthTile):
48
- '''
49
- process an array of uploaded raw Tiles (from internal app path)
50
- - cleanup all old norm images in /data/tiles/norm
51
- - process tile normalization ops
52
- - save norm tiles to /data/tiles/norm
53
- - create tile class obj; capture file path, size, zoomMagnif, etc
54
- - return(s) json
55
- - ack tile/norms with info/attribs
56
- '''
57
- #--- get file attributes
58
- strFilPath, strFilName = os.path.split(strPthTile)
59
- strPthRaw = strPthTile
60
-
61
- #--- load the tile as a binary object
62
- with open(strPthRaw,"rb") as filRaw:
63
- imgRaw = filRaw.read()
64
-
65
- #--- Resize Tiles to 256x256
66
- #--- Note: imgTile is a buffer object.
67
- aryNp = np.frombuffer(imgRaw, np.uint8)
68
- imgTemp = cv2.imdecode(aryNp, cv2.IMREAD_COLOR)
69
- imgResized = cv2.resize(imgTemp, (256, 256))
70
-
71
- #--- save the normalized file
72
- imgNorm = imgResized
73
- strPthNorm = "data/tiles/norm", strFilName
74
- with open(os.path.join(strPthNorm),"wb") as filNorm:
75
- filNorm.write(imgResized.buffer)
76
- return strPthNorm
77
- """ return {
78
- "message": "tileRawNorm endpoint - normalization of raw tile images"
79
- }
80
- """
81
-
82
- @rteTiles.get('/norm/upload')
83
- def api_tilesNormUpload():
84
- '''
85
- process an array of uploaded norm Tiles (from external app path)
86
- - cleanup all old norm images in /data/tiles/norm
87
- - save uploads to /data/tiles/norm
88
- - create tile class obj; capture file path, size, zoomMagnif, etc
89
- - create array of tile class objs
90
- - return(s) json
91
- - ack tile/norm uploads with info/attribs
92
- '''
93
- return {
94
- "message": "tilesNormUpload endpoint - file processing of norm tile images"
95
- }
96
-
97
-
98
- @rteTiles.get('/norm/preprocess')
99
- def api_tilesNormPreprocess():
100
- '''
101
- preprocess an array of uploaded norm Tiles (from internal app path)
102
- - perform remaining pre-processing of tiles prior to model prediction
103
- - cleanup all old preproc images in /data/tiles/preproc
104
- - save preproc tiles to /data/tiles/preproc
105
- - create tile class obj; capture file path, size, zoomMagnif, etc
106
- - return(s) json
107
- - ack tile/preproc with info/attribs
108
- '''
109
- return {
110
- "message": "tileNormPreprocess endpoint - preprocessing of normalized tile images"
111
- }
112
-
113
-
114
- @rteTiles.get('/preproc/upload')
115
- def api_tilesPreprocUpload():
116
- '''
117
- process an array of uploaded preprocessed Tiles (from external app path)
118
- - cleanup all old preproc images in /data/tiles/preproc
119
- - save uploads to /data/tiles/preproc
120
- - create tile class obj; capture file path, size, zoomMagnif, etc
121
- - create array of tile class objs
122
- - return(s) json
123
- - ack tile/preproc uploads with info/attribs
124
- '''
125
- return {
126
- "message": "tilesPreprocUpload endpoint - manage upload of preprocessed tile images, in prep for modelling/prdictions"
127
- }
128
-
129
-
130
- @rteTiles.get('/preproc/augment')
131
- def api_tilesPreprocAugment():
132
- '''
133
- process an array of uploaded preprocessed tiles (from internal app path)
134
- - cleanup all old augmented tiles in /data/tiles/augm
135
- - perform augments of tiles prior to model prediction (translation, rotation, transforms)
136
- - save augmented tiles to /data/tiles/augm
137
- - create tile class obj; capture file path, size, zoomMagnif, etc
138
- - return(s) json
139
- - ack tile/augm with info/attribs
140
- '''
141
- return {
142
- "message": "tilePreprocAugment endpoint - augment tile images"
143
- }
144
-
145
-
146
- @rteTiles.get('/augm/upload')
147
- def api_tilesAugmUpload():
148
- '''
149
- process an array of augmented tiles (from external app path)
150
- - cleanup all old augm images in /data/tiles/augm
151
- - save uploads to /data/tiles/augm
152
- - create tile class obj; capture file path, size, zoomMagnif, etc
153
- - create array of tile class objs
154
- - return(s) json
155
- - ack tile/augm uploads with info/attribs
156
- '''
157
- return {
158
- "message": "tilesAugmUpload endpoint - manage upload of augmented tile images, in prep for modelling/predictions"
159
- }
160
-
161
-
162
- #---
163
- @rteTiles.get('/raw/predict')
164
- def api_tileRawPredict():
165
- return {
166
- "message": "tile_rawPredict api endpoint - welcome to the endpoint for tile predictions"
167
- }
168
-
169
-
170
- #---
171
- @rteTiles.get('/norm/segment')
172
- def api_tileNormPredict():
173
- return {
174
- "message": "tile_normPredict api endpoint - welcome to the endpoint for tile predictions"
175
- }
176
-
177
- #---
178
- @rteTiles.get('/norm/predict')
179
- def api_tileNormPredict():
180
- return {
181
- "message": "tile_normPredict api endpoint - welcome to the endpoint for tile predictions"
182
- }
183
-
184
-
185
- #---
186
- @rteTiles.get('/preproc/predict')
187
- def api_tilePreprocPredict():
188
- return {
189
- "message": "tile_preprocPredict api endpoint - welcome to the endpoint for tile predictions"
190
- }
191
-
192
-
193
- #---
194
- @rteTiles.get('/augm/predict')
195
- def api_tileAugmPredict():
196
- return {
197
- "message": "tile_augmPredict api endpoint - welcome to the endpoint for tile predictions"
198
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
routes/api/rte_wsi.py DELETED
@@ -1,56 +0,0 @@
1
- from fastapi import APIRouter, Request, Response
2
- from fastapi.responses import HTMLResponse
3
-
4
-
5
- import main as libMain
6
- from lib import utils as libUtils
7
-
8
-
9
- m_kstrFile = __file__
10
- m_blnTraceOn = True
11
-
12
- m_kstrPath_templ = libUtils.pth_templ
13
-
14
-
15
- rteWsi = APIRouter()
16
-
17
-
18
- #---
19
- @rteWsi.get('/')
20
- def api_wsi():
21
- return {
22
- "message": "wsi api endpoint - welcome to the endpoint for wsi image processing"
23
- }
24
-
25
-
26
- #---
27
- @rteWsi.get('/upload')
28
- def api_wsiUpload():
29
- '''
30
- process a single uploaded WSI image (from external app path)
31
- - cleanup all old WSI images in /data/wsi/raw
32
- - save upload to /data/wsi/raw
33
- - create wsi class obj; capture file path, size, zoomMagnif, etc
34
- - return(s) json
35
- - ack wsi upload with info/attribs
36
- '''
37
- return {
38
- "message": "wsiUpload endpoint - file processing of one uploaded wsi image"
39
- }
40
-
41
-
42
- #---
43
- @rteWsi.get('/chunk')
44
- def api_wsiChunk():
45
- '''
46
- process a single WSI image (from internal app path)
47
- - create wsi class obj; capture file path, size, zoomMagnif, etc
48
- - kick off tile chunking process;
49
- - save tiles to /data/tiles/raw
50
- - return(s) json
51
- - ack wsi upload with info/attribs
52
- - ack of tiles created: total count; names, paths, attribs (dimensions)
53
- '''
54
- return {
55
- "message": "wsiLoad endpoint - for chunking of wsi image to one or more tiles"
56
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
routes/qa/__init__.py DELETED
File without changes
routes/qa/rte_qa.py DELETED
@@ -1,17 +0,0 @@
1
- from fastapi import APIRouter
2
-
3
-
4
- m_kstrFile = __file__
5
- m_blnTraceOn = True
6
-
7
-
8
- rteQa = APIRouter()
9
-
10
-
11
- @rteQa.get('/')
12
- @rteQa.get('/verif')
13
- @rteQa.get('/valid')
14
- def qa_entry():
15
- return {
16
- "message": "qa routing - welcome to Omdena Saudi HCC qa"
17
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
scripts/docker/util_docker_preRun.sh DELETED
@@ -1,32 +0,0 @@
1
- #!/bin/bash
2
-
3
- #--- Note: this file is designed to run locally as well as within docker to prep the environment
4
- #--- Entry: this script is assumed to run from the /app root folder
5
- #--- Usage: ./scripts/docker/util_docker_preRun.sh
6
-
7
- #--- for volume initialization; ensure folders are in place; assume: we are in the /app folder
8
-
9
-
10
- <<blockComment
11
- - the binary model is stored as split files named mdl_nn
12
- - this is done to ensure that the model can be stored within gitHub
13
- - the split model is recreated on docker container startup using the cat command
14
- blockComment
15
- echo -e "INFO(util_docker_preRun):\t Initializing ..."
16
-
17
- strpth_pwd=$(pwd)
18
- strpth_scriptLoc=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
19
- strpth_scrHome="${strpth_scriptLoc}/../"
20
- strpth_appHome="${strpth_scrHome}../"
21
- strpth_scrModels="${strpth_scrHome}models/"
22
-
23
- echo "strpth_appHome = ${strpth_appHome}"
24
-
25
- #--- recreate single model file from its parts, stored within a specific model version folder
26
- strpth_binModels="${strpth_appHome}bin/models/"
27
- echo "strpth_binModels = ${strpth_binModels}"
28
- #$("'${strpth_scrModels}util_joinModel.sh' '${strpth_binModels}deeplabv3*vhflip30/model_a*' '${strpth_binModels}model.pth'")
29
- #---eval "'${strpth_scrModels}/util_joinModel.sh' '${strpth_binModels}/deeplabv3*vhflip30/model_a*' '${strpth_binModels}/model.pth'"
30
-
31
- #--- run streamlit/fastapi
32
- eval "'${strpth_scrHome}/streamlitFastApi/util_local_runStreamlitFastApi.sh'"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
scripts/docker/util_local_buildDockerDemo.sh DELETED
@@ -1,86 +0,0 @@
1
- #!/bin/bash
2
-
3
- #--- Note: this file is designed to run locally to build the docker image
4
- #--- Entry: this script is assumed to run from the /app root folder
5
- #--- Usage: ./scripts/docker/util_local_buildDockerDemo.sh
6
- #--- Assume: any associated containers are not running
7
-
8
- <<blockComment
9
- util_local_buildDockerDemo -> img_stm_omdenasaudi_hcc:demo -> ctr_stm_omdenasaudi_hcc:demo
10
- blockComment
11
-
12
-
13
- #--- initialize/configuration
14
- echo "TRACE: Initializing ..."
15
- kstr_defDkrHubId="kidcoconut73"
16
- kstr_defDkrImageName="img_stm_omdenasaudi_hcc"
17
- kstr_defDkrTagVersion="0.1.3"
18
- kstr_defDkrTagStage="demo"
19
-
20
- strpth_pwd=$(pwd)
21
- strpth_scriptLoc=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
22
- strpth_scrHome="${strpth_scriptLoc}/../"
23
- strpth_appHome="${strpth_scrHome}/../"
24
-
25
- #--- declarations
26
- echo "TRACE: Declarations ..."
27
-
28
- #strUtl_scriptLoc="$(utl_getScriptLoc)"
29
- source ${strpth_scrHome}/util.sh
30
-
31
- #kstr_dkrImg="kidcoconut73/img_stm_omdenasaudi_hcc:demo"
32
- #kstr_dkrCtr="kidcoconut73/ctr_stm_omdenasaudi_hcc:demo"
33
- kstr_dkrHubImg="${kstr_defDkrHubId}/${kstr_defDkrImageName}:${kstr_defDkrTagStage}"
34
- kstr_dkrImg="${kstr_defDkrImageName}:${kstr_defDkrTagVersion}"
35
- kstr_dkrCtr="${kstr_dkrImg/img_/ctr_}" #--- bash replace one occurrence
36
-
37
-
38
-
39
- function utl_trace_config {
40
- #echo ""
41
- local kbln_enableLog=true
42
- utl_logInfo $kbln_enableLog 0 "(utl_trace_config) ... echo configuration"
43
-
44
- utl_trace_var "strpth_pwd" $strpth_pwd
45
- utl_trace_var "strpth_scriptLoc" $strpth_scriptLoc
46
- echo ""
47
- utl_trace_var "kstr_defDkrHubId" $kstr_defDkrHubId
48
- utl_trace_var "kstr_defDkrImageName" $kstr_defDkrImageName
49
- utl_trace_var "kstr_defDkrTagVersion" $kstr_defDkrTagVersion
50
- utl_trace_var "kstr_defDkrTagStage" $kstr_defDkrTagStage
51
- echo ""
52
- utl_trace_var "kstr_dkrHubImg" $kstr_dkrHubImg
53
- utl_trace_var "kstr_dkrImg" $kstr_dkrImg
54
- utl_trace_var "kstr_dkrCtr" $kstr_dkrCtr
55
- echo ""
56
- }
57
-
58
- #echo -e "\nTRACE: Echo config ..."
59
- utl_trace_config
60
-
61
-
62
- #--- to build/rebuild the image; make sure you stop and remove the container if you are replacing/upgrading; or change the version tag# from 0.1
63
- #--- stop the container if it is running
64
- #--- delete container if it exists
65
- echo -e "\nTRACE: Stop and remove container if it exists ..."
66
- docker stop $kstr_dkrCtr
67
- docker rm $kstr_dkrCtr
68
-
69
- #--- build the docker image
70
- echo -e "\nTRACE: Build the docker image ..."
71
- docker build -t $kstr_dkrImg .
72
-
73
-
74
- #--- to tag the image prior to push to DockerHub; docker login and then register user/image:tag
75
- #--- to push this image to DockerHub, example based on the repo: kidcoconut73/img_stm_omdenasaudi_hcc
76
- # docker tag img_omdenasaudi_hcc:0.1 kidcoconut73/img_stm_omdenasaudi_hcc:demo
77
- # docker tag img_omdenasaudi_hcc:0.1 kidcoconut73/img_stm_omdenasaudi_hcc:0.1
78
- #--- tag the image
79
- echo -e "\nTRACE: Tag the image ..."
80
- docker tag ${kstr_dkrImg} $kstr_dkrHubImg
81
- docker tag ${kstr_dkrImg} "${kstr_defDkrHubId}/${kstr_defDkrImageName}:${kstr_defDkrTagVersion}"
82
-
83
-
84
- #--- prereq: make sure you are signed in through Docker Desktop
85
- #--- push the image to dockerHub
86
- docker push kidcoconut73/img_stm_omdenasaudi_hcc:demo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
scripts/docker/util_local_runDockerDemo.sh DELETED
@@ -1,33 +0,0 @@
1
- #!/bin/bash
2
-
3
- #--- Note: this file is designed to run locally to launch docker
4
- #--- Entry: this script is assumed to run from the /app root folder
5
- #--- Usage: ./scripts/util_local_runDockerDemo.sh
6
- #--- Assume: docker image has been built; container is not running
7
-
8
- <<blockComment
9
- util_local_runDockerDemo -> Dockerfile -> util_dockerPreRun -> util_local_runStreamlitFastApi
10
- blockComment
11
-
12
-
13
- #--- initialize/config
14
- kstr_defDkrHubId="kidcoconut73"
15
- kstr_defDkrImageName="img_stm_omdenasaudi_hcc"
16
- kstr_defDkrCtrName=${kstr_defDkrImageName/img_/ctr_}
17
- kstr_defDkrTagVersion="0.1.3"
18
- kstr_defDkrTagStage="demo"
19
-
20
- kstr_dkrImg="${kstr_defDkrImageName}:${kstr_defDkrTagVersion}"
21
- kstr_dkrCtr="${kstr_defDkrImageName/img_/ctr_}" #--- bash replace one occurrence
22
-
23
- #--- stop the container if it is running
24
- docker stop $kstr_dkrCtr
25
-
26
- #--- delete container if it exists
27
- docker rm $kstr_dkrCtr
28
-
29
- #--- to run the container from the image; specific port mapping (-p) vs any available port mapping (-P)
30
- # docker run -p 49400:39400 -p 49500:39500 --name ctr_stmOmdenaSaudiHcc -v ./data:/app/data img_stm_omdenasaudi_hcc:0.1
31
-
32
- #--- run docker demo locally
33
- docker run -p 49400:39400 -p 49500:39500 --name $kstr_dkrCtr -v ./data:/app/data $kstr_dkrImg
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
scripts/huggingface/util_local_deploy_toHugSpace.sh ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ #--- Note: this file is designed to run locally to ready the deploy branch for hugspace
4
+ #--- Entry: this script is assumed to run from the /app root folder
5
+ #--- Usage: ./scripts/huggingface/util_local_deploy_toHugSpace.sh
6
+
7
+ #--- Prereqs:
8
+ # - deploy_dockerLocal branch image and container has been tested and tagged
9
+ # - deploy_dockerHub branch has been merged from deploy_dockerLocal, tagged and pushed an image to kidcoconut73/img_stm_omdenasaudi_hcc:<version>
10
+ # - deploy_hugspace branch has been merged from deploy_dockerLocal, readyToDeployScript run, and pushed to hugspace
11
+
12
+ <<blockComment
13
+ - if all code is within a dockerHub image, all we need to push to huggingFace is the Dockerfile and the README.md
14
+ blockComment
15
+
16
+
17
+ #--- initialize/configuration
18
+ echo "WARN: this script should only be run from deploy_hugspace"
19
+
20
+
21
+ #--- merge
22
+ echo "TRACE: Merge from deploy_dockerLocal ..."
23
+ git merge deploy_dockerLocal
24
+
25
+ #--- ready the Dockerfile.hug as the active Dockerfile
26
+ echo "TRACE: update Dockerfile for hugspace ..."
27
+ cp Dockerfile.hug Dockerfile
28
+
29
+ #--- cleanup all extraneous code
30
+ echo "TRACE: cleanup all extraneous code ..."
31
+ git rm -r bin data lib routes scripts/docker scripts/dockerHub scripts/models scripts/streamlitFastApi templ uix
32
+ git rm .dockerignore .gitattributes app.py config.toml Dockerfile.hug Dockerfile.local main.py packages.txt requirements.txt
33
+
34
+ #--- manually check from this point
35
+ # - git status
36
+ # - git rm any remaining unneeded files
37
+ # - git commit -a -m "ready for deploy to hugspace v0.1.5"
38
+ # - git tag 0.1.5_hugspace
39
+ # - git push --force hugspace deploy_hugspace:main
scripts/huggingface/util_local_readyDeploy_toHugSpace_streamlit.sh DELETED
@@ -1,93 +0,0 @@
1
- #!/bin/bash
2
-
3
- #--- Note: this file is designed to run locally to ready the deploy branch for hugspace
4
- #--- Entry: this script is assumed to run from the /app root folder
5
- #--- Usage: ./scripts/util_local_readyDeploy_toHugSpace_streamlit.sh
6
-
7
- #--- Prereqs:
8
- # - deploy_dockerLocal branch image and container has been tested and tagged
9
- # - deploy_dockerHub branch has been merged from deploy_dockerLocal, tagged and pushed an image to kidcoconut73/img_stm_omdenasaudi_hcc:<version>
10
- # - deploy_hugspace branch has been merged from deploy_dockerLocal, readyToDeployScript run, and pushed to hugspace
11
-
12
- <<blockComment
13
- bash: util_local_readyDeploy_toHugSpace_streamlit -> git
14
- git: local/task-5-deployment -> omdena/deploy_hugspace_streamlit -> hugspace/main
15
- blockComment
16
-
17
-
18
- #--- initialize/configuration
19
- echo "TRACE: Initializing ..."
20
- kstr_hugspaceId="kidcoconut"
21
-
22
-
23
- #--- git checkout deploy_hugspace_streamlit
24
- #--- git merge task-5-deployment
25
- #--- delete all unnecessary files
26
- <<deadCode
27
- kstr_defDkrHubId="kidcoconut73"
28
- kstr_defDkrImageName="img_stm_omdenasaudi_hcc"
29
- kstr_defDkrTagVersion="0.1.2"
30
- kstr_defDkrTagStage="demo"
31
- strpth_pwd=$(pwd)
32
- strpth_scriptLoc=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
33
-
34
-
35
- #--- declarations
36
- echo "TRACE: Declarations ..."
37
-
38
- #strUtl_scriptLoc="$(utl_getScriptLoc)"
39
- source ${strpth_scriptLoc}/util.sh
40
-
41
- #kstr_dkrImg="kidcoconut73/img_stm_omdenasaudi_hcc:demo"
42
- #kstr_dkrCtr="kidcoconut73/ctr_stm_omdenasaudi_hcc:demo"
43
- kstr_dkrHubImg="${kstr_defDkrHubId}/${kstr_defDkrImageName}:${kstr_defDkrTagStage}"
44
- kstr_dkrImg="${kstr_defDkrImageName}:${kstr_defDkrTagVersion}"
45
- kstr_dkrCtr="${kstr_dkrImg/img_/ctr_}" #--- bash replace one occurrence
46
-
47
-
48
-
49
- function utl_trace_config () {
50
- echo ""
51
- utl_trace_var "strpth_pwd" $strpth_pwd
52
- utl_trace_var "strpth_scriptLoc" $strpth_scriptLoc
53
- echo ""
54
- utl_trace_var "kstr_defDkrHubId" $kstr_defDkrHubId
55
- utl_trace_var "kstr_defDkrImageName" $kstr_defDkrImageName
56
- utl_trace_var "kstr_defDkrTagVersion" $kstr_defDkrTagVersion
57
- utl_trace_var "kstr_defDkrTagStage" $kstr_defDkrTagStage
58
- echo ""
59
- utl_trace_var "kstr_dkrHubImg" $kstr_dkrHubImg
60
- utl_trace_var "kstr_dkrImg" $kstr_dkrImg
61
- utl_trace_var "kstr_dkrCtr" $kstr_dkrCtr
62
- echo ""
63
- }
64
-
65
- echo -e "\nTRACE: Echo config ...\n"
66
- utl_trace_config
67
-
68
-
69
- #--- to build/rebuild the image; make sure you stop and remove the container if you are replacing/upgrading; or change the version tag# from 0.1
70
- #--- stop the container if it is running
71
- #--- delete container if it exists
72
- echo -e "\nTRACE: Stop and remove container if it exists ..."
73
- docker stop $kstr_dkrCtr
74
- docker rm $kstr_dkrCtr
75
-
76
- #--- build the docker image
77
- echo -e "\nTRACE: Build the docker image ..."
78
- docker build -t $kstr_dkrImg .
79
-
80
-
81
- #--- to tag the image prior to push to DockerHub; docker login and then register user/image:tag
82
- #--- to push this image to DockerHub, example based on the repo: kidcoconut73/img_stm_omdenasaudi_hcc
83
- # docker tag img_omdenasaudi_hcc:0.1 kidcoconut73/img_stm_omdenasaudi_hcc:demo
84
- # docker tag img_omdenasaudi_hcc:0.1 kidcoconut73/img_stm_omdenasaudi_hcc:0.1
85
- #--- tag the image
86
- echo -e "\nTRACE: Tag the image ..."
87
- docker tag ${kstr_dkrImg} $kstr_dkrHubImg
88
- docker tag ${kstr_dkrImg} "${kstr_defDkrHubId}/${kstr_defDkrImageName}:${kstr_defDkrTagVersion}"
89
-
90
-
91
- #--- push the image to dockerHub
92
- # docker push kidcoconut73/img_stm_omdenasaudi_hcc:demo
93
- deadCode
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
scripts/models/util_joinModel.sh DELETED
@@ -1,45 +0,0 @@
1
- #!/bin/bash
2
-
3
- <<blkHeader
4
- Name: util_joinModel
5
- Purpose: reconstitutes a split pyTorch binary model with weights, into a single binary file
6
- Usage: ./util_joinModel.sh <source pattern match> <dest model file>
7
- - the first arg has to be wrapped in single quotes to ensure that bash does not expand wildcards
8
- Prereqs: a model folder within bin/models; containing a split pyTorch model.pth as 1 or more model_nn files
9
- Todo: get the parent folder name and use this as the name for the model file
10
- blkHeader
11
-
12
- #--- dependencies
13
- #none
14
-
15
-
16
- #--- initialize/configuration
17
- #--- $1: first arg; source pattern match; eg './bin/models/deeplabv3*vhflip30/model_a*'; Note that this is wildcarded so must be in quotes
18
- #--- $n: last arg; dest model file; eg. ./bin/models/model.pth
19
- echo -e "INFO(util_joinModel):\t Initializing ..."
20
- strPth_patternMatch=$1
21
- if [ -z "$strPth_patternMatch" ]; then
22
- echo "WARN: no args provided. Exiting script."
23
- exit
24
- fi
25
-
26
- strPth_filMatch=( $strPth_patternMatch ) #--- expand the pattern match; get the first value of the pattern match
27
- strPth_parentFld=$(dirname $strPth_filMatch) #--- get the parent dir of the first file match
28
- strPth_mdlFile=${@: -1} #--- Note: this gets the last arg; otherwise the 2nd arg would be an iteration of the 1st arg wildcard
29
-
30
- strpth_pwd=$(pwd)
31
- strpth_scriptLoc=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
32
- strpth_scrHome="${strpth_scriptLoc}/../"
33
- strpth_appHome="${strpth_scrHome}/../"
34
-
35
- #echo "TRACE: strPth_patternMatch= $strPth_patternMatch"
36
- #echo "TRACE: strPth_filMatch= $strPth_filMatch"
37
- #echo "TRACE: strPth_parentFld= $strPth_parentFld"
38
- #echo "TRACE: strPth_mdlFile= $strPth_mdlFile"
39
-
40
- #--- reconstitute model
41
- #--- Note: cat command does not work with single-quote literals; do not reapply single quotes
42
- #echo "cat ${strPth_patternMatch} > ${strPth_mdlFile}"
43
- echo -e "INFO:\t Joining model binary ..."
44
- cat ${strPth_patternMatch} > ${strPth_mdlFile}
45
- echo -e "INFO:\t Done ...\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
scripts/models/util_splitModel.sh DELETED
@@ -1,44 +0,0 @@
1
- #!/bin/bash
2
-
3
- <<blkHeader
4
- Name: util_splitModel
5
- Purpose: convenience script to split a single pyTorch .pth model file with weights into smaller 10MB chunks in order to store within github
6
- Usage: ./util_splitModel.sh <src model file> <dest folder>
7
- - the first arg has to be wrapped in single quotes to ensure that bash does not expand wildcards
8
- Prereqs: a pytorch model file
9
- Todo: get the parent folder name and use this as the name for the model file
10
- blkHeader
11
-
12
- #--- dependencies
13
- #none
14
-
15
-
16
- #--- initialization/configuration
17
- #--- $1: first arg; the source model file; eg ./bin/models/model.pth
18
- #--- $n: last arg; dest model path; eg. ./test_model_folder
19
- strPth_mdlFile=$1
20
- strPth_mdlFolder=$2
21
- strPrefix='/model_'
22
-
23
- if [ -z "$strPth_mdlFile" ] || [ -z "$strPth_mdlFolder" ]; then
24
- echo "WARN: no args provided. Exiting script."
25
- exit
26
- fi
27
-
28
- strpth_pwd=$(pwd)
29
- strpth_scriptLoc=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
30
- strpth_scrHome="${strpth_scriptLoc}/../"
31
- #strpth_ignHome="${strpth_scrHome}/../"
32
- strpth_appHome="${strpth_scrHome}/../"
33
-
34
- #echo "TRACE: strPth_mdlFile= $strPth_mdlFile"
35
- echo "TRACE: strPth_mdlFolder= $strPth_mdlFolder"
36
-
37
- #--- ensure the target dir exists
38
- mkdir -p $strPth_mdlFolder
39
-
40
- #--- split the model into smaller chunks
41
- echo "split -b 10M $strPth_mdlFile $strPth_mdlFolder$strPrefix"
42
- split -b 10M $strPth_mdlFile $strPth_mdlFolder$strPrefix
43
-
44
- echo -e "INFO:\t Done ...\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
scripts/streamlitFastApi/util_local_runStreamlitFastApi.sh DELETED
@@ -1,27 +0,0 @@
1
- #!/bin/bash
2
-
3
- #--- Note: this file is designed to run locally and within docker to prep the environment
4
- #--- Entry: this script is assumed to run from the /app root folder
5
- #--- Usage: ./scripts/util_local_runStreamlitFastApi.sh
6
- echo -e "INFO(util_local_runStreamlitFastApi):\t Initializing ..."
7
-
8
- #--- for volume initialization; ensure folders are in place; assume: we are in the /app folder
9
- mkdir -p data/demo_tiles/raw
10
- mkdir -p data/tiles/raw data/tiles/pred data/tiles/grad_bg data/tiles/grad_wt data/tiles/grad_vt
11
- mkdir -p data/wsi/raw
12
-
13
- #--- for streamlit; external 49400; internal 39400
14
- echo "INFO: starting streamlit ..."
15
- streamlit run app.py --server.port=39400 --server.maxUploadSize=2000 &
16
-
17
- #--- for fastapi; external 49500; internal 39500
18
- echo "INFO: starting fastapi ..."
19
-
20
- #--- uvicorn main:app --reload --workers 1 --host 0.0.0.0 --port 39500 &
21
- uvicorn main:app --reload --workers 1 --host 0.0.0.0 --port 39500
22
-
23
- #--- wait for any process to exit
24
- #wait -n
25
-
26
- #--- Exit with status of process that exited first
27
- #exit $?