Pycontw2020 - 我們如何在醫院打造即時醫療影像AI平台

Max Lai
Max LaiPythonista, Agile Coach
我們如何在醫院打造
即時醫療影像AI平台
Max Lai
台中童綜合醫院 資訊部
About Me
• Taichung.py 社群共同發起人
• Agile Taichung 社群共同發起人
• 台中童綜合醫院 AI Lab Senior Manager
台中童綜合醫院
• 位於台中市梧棲區, 1,500 病床
• 資訊部有 78位成員
• AI Lab 目前有 8位 AI工程師& 4位資料分析師
• 主要標註者為 3位 放射科醫師& 4位放射師
Ethics and Privacy Announcement
All of our researches concerning ethics and privacy are
under oversight by an independent committee of IRB
(Institutional Review Boards).
All sensitive data in this presentation are de-identified
and de-linked before use.
https://www.cnshealthcare.com/learn-more/what-is-clinical-research/item/73-what-s-an-irb.html
Agenda
• Deep Learning Pipeline
• 醫學影像標註系統的設計考量
• 即時胸部X光腫瘤AI平台
• 深度學習模型封裝
• 結論
早期治療五年存活率>70%
若為第四期肺癌則<5%
2017年台 男女性10大 症 化發生率
料來 :本 症登記 料(不含原位 ) 資料來源: 國民健康署 2020/06/02 https://bit.ly/3baZoBU
節結 (<3cm)腫塊 (>=3cm)
醫院 AI 平台目標
• 使用類神經網路在X光影像上偵測結節及腫塊
• 整合 PACS 系統,建置醫學影像標註系統
• 整合至報告系統,在醫師打報告時即時顯示病灶位置
胸部X光是放射影像中使用最多、數量最大,也是最重要的初步診斷工具。
但小的結節有時肉眼辨識不易,因而延誤早期治療之時機。
報告資料庫
影像資料庫
資料集 預標註
去識別化
訓練模型即時輔助診斷醫師產出報告 人工標註
Medical Deep Learning Pipeline
佈署
醫學影像標註系統
放射報告系統整合
Pycontw2020 - 我們如何在醫院打造即時醫療影像AI平台
Pycontw2020 - 我們如何在醫院打造即時醫療影像AI平台
Central Venous Catheter/中心靜脈導管 Endotracheal Tube/氣管內管
97.98% 98.18%
Nasogastric Tube/鼻胃管 Pacemaker/心律調節器
95.42% 100%
醫學影像標註系統的設計考量
• 標註者多為領域專家,UI Flow 宜貼近原工作之習慣
• 結合醫院的報告系統,可透過關鍵字進行預標註
• 標註一致性的提升:
• 事先溝通
• 專案說明
• 標註與確認
• 隱私權的考量:去識別化功能
• 訓練集(train set)、驗證集(validation set)、測試集(test set)要考
量同一人不同影像的情況
NIH註解
童綜合醫院註解
• NIH Chest X-ray的分類:0, 低度懷疑, 中度懷疑, 高度懷疑
標註資料的品質
t
即時胸部X光腫瘤AI平台
Image
Storage
檢查新Xray
Get Dicom
Labeling
System
PACS
AI Service
刪除30天
前舊圖
Task QueueHIS
RIS
False positive
False negative
Inference
Result
Convert to JPG
APScheduler
APScheduler
Pydicom
API
API
API
API
深度學習模型封裝
以 PyTorch 為例
AI Model/ API/ Client
AI Model/ API/ Client
Image
Storage
APIClient
Class
API
Docker
Object
storage
Model
github.com/cclai999/pycontw2020-demo
V1-Script
├── v1-script
│ └── main.py
V1-Script, main.py (1/2)
transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(
mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225]
)])
img = Image.open("cat.jpg")
img_t = transform(img)
batch_t = torch.unsqueeze(img_t, 0)
# build a transform; load image,
V1-Script , main.py (2/2)
# First, load the model
resnet = models.resnet101(pretrained=False)
state_dict = torch.load("resnet101-5d3b4d8f.pth")
resnet.load_state_dict(state_dict)
# Second, put the network in eval mode
resnet.eval()
# Third, carry out model inference
out = resnet(batch_t)
_, index = torch.max(out, 1)
percentage = torch.nn.functional.softmax(out, dim=1)[0] * 100
print(classes[index[0]], percentage[index[0]].item())
# load model, and do inference
V2-model-class
├── v2-model-class
├── main.py
└── model
├── __init__.py
└── myresnet.py
V2-model-class, myresnet.py (1/2)
class MyResnet():
def __init__(self, model_state_path: str,
classes_names_path: str):
# load the model
self._model = models.resnet101(pretrained=False)
state_dict = torch.load(model_state_path)
self._model.load_state_dict(state_dict)
# put the network in eval mode
self._model.eval()
# create an image transform
.....
# load names of all classes
.....
# wrap AI model into a class
V2-model-class, myresnet.py (2/2)
class MyResnet():
def predict(self, img: Image):
img_t = self.transform(img)
batch_t = torch.unsqueeze(img_t, 0)
# carry out model inference
out = self._model(batch_t)
_, index = torch.max(out, 1)
percentage = torch.nn.functional.softmax(out,
dim=1)[0] * 100
return self.classes[index[0]],
percentage[index[0]].item()
# wrap AI model into a class
V2-model-class, main.py
from PIL import Image
from model import MyResnet
imgnet = MyResnet("resnet101-5d3b4d8f.pth",
"imagenet_classes.txt")
img = Image.open("../test-data/cat.jpg")
class_name, percentage = imgnet.predict(img)
# pass an image to MyResnet and do predict
V3-docker
├── v3-docker
├── Dockerfile
├── ....
├── docker-compose.yml
├── model
│ ├── __init__.py
│ ├── myresnet.py
│ └── ....
├── requirements.txt
├── .. ..
└── web.py
V3-docker, web.py
@app.route('/api/imgnet', methods=['POST'])
def inference():
req_data = request.get_json()
if req_data.get('img_url', None):
img = Image.open(....)
class_name, percentage = imgnet.predict(img)
result = {
"status": "success",
"status_code": 200,
"img_url": req_data['img_url'],
"class_name": class_name,
"percentage": percentage,
}
return jsonify(result), 200
# apply Flask to wrap model class into an API
V3-docker, Dockerfile
FROM aibase:0.1.01beta
....
WORKDIR /root/aimodel
# add app
COPY model model
COPY web.py .
....
# start web
CMD gunicorn --bind 0.0.0.0:5000 web:app
# 使用 Docker 封裝 Restful API
V3-docker, docker-compose.yml
version: '3.7'
services:
aimodel:
image: aimodel:pycontw2020
build:
context: .
ports:
- "15000:5000"
# 使用 docker-compose 來執行 docker container
V4-docker-w-minio
└── v4-docker-w-minio
├── Dockerfile
├── ....
├── docker-compose.yml
├── model
│ ├── __init__.py
│ └── myresnet.py
├── model-state
│ ├── config.yaml
│ ├── ....
├── requirements.txt
└── web.py
ai-client.pay
http://127.0.0.1:15000/api/imgnet
http://127.0.0.1:9000
http://127.0.0.1:15001/api/imgnet
Docker-Compose
V4-docker-w-minio, docker-compose.yml(1/2)
version: '3.7'
services:
aimodel:
image: aimodel2:pycontw2020
build:
context: .
ports:
- "15000:5000"
volumes: # 更改 AI model 不必重新再 build docker image
- "./model-state:/root/aimodel/model-state"
# model-state 目錄提出到 host machine
V4-docker-w-minio, docker-compose.yml(2/2)
minio:
image: minio/minio
container_name: minio
ports:
- "9000:9000"
environment:
MINIO_ACCESS_KEY: minio
MINIO_SECRET_KEY: minio123
command: server /data
volumes: # image storage bind 到 host machine
- "./minio-data:/data"
# 新增一個 service: minio (container)
V4-docker-w-minio, ai-client.py
minioClient = Minio('127.0.0.1:9000', access_key='minio',
secret_key='minio123’, secure=False)
try:
s1 = minioClient.fput_object('mybucket', 'violin.jpg', 'violin.jpg')
except ResponseError as err:
....
r = requests.post('http://127.0.0.1:15000/api/imgnet', json={"img_url":
"violin.jpg"})
if r.status_code == 200:
print(r.text)
else:
....
# client 先上傳一張影像到 minio, 再 call AI API
V4-docker-w-minio, web.py(1/2)
app = Flask(__name__)
model_config = yaml.safe_load(open('./model-state/config.yaml', 'r'))
model_state_file = Path('./model-state') / model_config['MODEL_STATE_FILE']
model_classes_file = Path('./model-state') /
model_config['MODEL_CLASSES_FILE']
imgnet = MyResnet(model_state_file, model_classes_file)
minioClient = Minio('minio:9000', access_key='minio',
secret_key='minio123', secure=False)
# 讀取 host machine 之 model-state 目錄的 model config
V4-docker-w-minio, web.py(2/2)
def get_minio_img(img_url):
resp = minioClient.get_object("mybucket", img_url)
return Image.open(io.BytesIO(resp.data))
@app.route('/api/imgnet', methods=['POST'])
def inference():
req_data = request.get_json()
if req_data.get('img_url', None):
img = get_minio_img(req_data["img_url"])
class_name, percentage = imgnet.predict(img)
result = {
....
"class_name": class_name,
"percentage": percentage,
"model_name": model_config['AIMODEL_NAME'],
"model_version": model_config['AIMODEL_VERSION'],
}
return jsonify(result), 200
附加價值
資料
標註
硬體運算力
模型設計
訓練
系統整合服務
資料
標註
硬體運算力
模型設計
訓練
系統整合服務
結論:AI服務的價值
•資料標註生產線
•高品質的資料
•應用場域
誠徵前端及後端工程師
歡迎加入我們AI團隊,一起來探索醫療新應用
謝謝您的聆聽
1 of 40

Recommended

Corporate Social Responsibility Initiatives in India by
Corporate Social Responsibility Initiatives in India Corporate Social Responsibility Initiatives in India
Corporate Social Responsibility Initiatives in India Olivier Tisun
14.3K views79 slides
Mcb Final Project by
Mcb Final ProjectMcb Final Project
Mcb Final Projectwheelrzzzz
4.6K views27 slides
SWOT Analysis by
SWOT AnalysisSWOT Analysis
SWOT Analysisreneefranklin
2.6K views5 slides
HRM process of coca cola beverages of pakistan ltd. by
HRM process of coca cola beverages of pakistan ltd.HRM process of coca cola beverages of pakistan ltd.
HRM process of coca cola beverages of pakistan ltd.Nasir Ali
5.3K views43 slides
IRJET- Object Detection in an Image using Convolutional Neural Network by
IRJET- Object Detection in an Image using Convolutional Neural NetworkIRJET- Object Detection in an Image using Convolutional Neural Network
IRJET- Object Detection in an Image using Convolutional Neural NetworkIRJET Journal
50 views3 slides
Inception V3 Image Processing .pptx by
Inception V3 Image Processing .pptxInception V3 Image Processing .pptx
Inception V3 Image Processing .pptxMahmoudMohamedAbdelb
57 views16 slides

More Related Content

Similar to Pycontw2020 - 我們如何在醫院打造即時醫療影像AI平台

[WSO2Con EU 2017] The Effects of Microservices on Corporate IT Strategy by
[WSO2Con EU 2017] The Effects of Microservices on Corporate IT Strategy[WSO2Con EU 2017] The Effects of Microservices on Corporate IT Strategy
[WSO2Con EU 2017] The Effects of Microservices on Corporate IT StrategyWSO2
296 views23 slides
Analytics Zoo: Building Analytics and AI Pipeline for Apache Spark and BigDL ... by
Analytics Zoo: Building Analytics and AI Pipeline for Apache Spark and BigDL ...Analytics Zoo: Building Analytics and AI Pipeline for Apache Spark and BigDL ...
Analytics Zoo: Building Analytics and AI Pipeline for Apache Spark and BigDL ...Databricks
1.3K views23 slides
Supervised Learning by
Supervised LearningSupervised Learning
Supervised LearningFEG
4 views28 slides
Real-time Computer Vision With Ruby - OSCON 2008 by
Real-time Computer Vision With Ruby - OSCON 2008Real-time Computer Vision With Ruby - OSCON 2008
Real-time Computer Vision With Ruby - OSCON 2008Jan Wedekind
780 views44 slides
Detection Rules Coverage by
Detection Rules CoverageDetection Rules Coverage
Detection Rules CoverageSunny Neo
1.2K views69 slides
2_Image Classification.pdf by
2_Image Classification.pdf2_Image Classification.pdf
2_Image Classification.pdfFEG
32 views55 slides

Similar to Pycontw2020 - 我們如何在醫院打造即時醫療影像AI平台(20)

[WSO2Con EU 2017] The Effects of Microservices on Corporate IT Strategy by WSO2
[WSO2Con EU 2017] The Effects of Microservices on Corporate IT Strategy[WSO2Con EU 2017] The Effects of Microservices on Corporate IT Strategy
[WSO2Con EU 2017] The Effects of Microservices on Corporate IT Strategy
WSO2296 views
Analytics Zoo: Building Analytics and AI Pipeline for Apache Spark and BigDL ... by Databricks
Analytics Zoo: Building Analytics and AI Pipeline for Apache Spark and BigDL ...Analytics Zoo: Building Analytics and AI Pipeline for Apache Spark and BigDL ...
Analytics Zoo: Building Analytics and AI Pipeline for Apache Spark and BigDL ...
Databricks1.3K views
Supervised Learning by FEG
Supervised LearningSupervised Learning
Supervised Learning
FEG4 views
Real-time Computer Vision With Ruby - OSCON 2008 by Jan Wedekind
Real-time Computer Vision With Ruby - OSCON 2008Real-time Computer Vision With Ruby - OSCON 2008
Real-time Computer Vision With Ruby - OSCON 2008
Jan Wedekind780 views
Detection Rules Coverage by Sunny Neo
Detection Rules CoverageDetection Rules Coverage
Detection Rules Coverage
Sunny Neo1.2K views
2_Image Classification.pdf by FEG
2_Image Classification.pdf2_Image Classification.pdf
2_Image Classification.pdf
FEG32 views
influence of AI in IS by ISACA Riyadh
influence of AI in ISinfluence of AI in IS
influence of AI in IS
ISACA Riyadh504 views
Using Genetic algorithm for Network Intrusion Detection by Sagar Uday Kumar
Using Genetic algorithm for Network Intrusion DetectionUsing Genetic algorithm for Network Intrusion Detection
Using Genetic algorithm for Network Intrusion Detection
Sagar Uday Kumar2.6K views
“Practical Guide to Implementing Deep Neural Network Inferencing at the Edge,... by Edge AI and Vision Alliance
“Practical Guide to Implementing Deep Neural Network Inferencing at the Edge,...“Practical Guide to Implementing Deep Neural Network Inferencing at the Edge,...
“Practical Guide to Implementing Deep Neural Network Inferencing at the Edge,...
DATA MINING TOOL- ORANGE by Neeraj Goswami
DATA MINING TOOL- ORANGEDATA MINING TOOL- ORANGE
DATA MINING TOOL- ORANGE
Neeraj Goswami28.3K views
Adversarial machine learning for av software by junseok seo
Adversarial machine learning for av softwareAdversarial machine learning for av software
Adversarial machine learning for av software
junseok seo1.1K views
Defend against adversarial AI using Adversarial Robustness Toolbox by Animesh Singh
Defend against adversarial AI using Adversarial Robustness Toolbox Defend against adversarial AI using Adversarial Robustness Toolbox
Defend against adversarial AI using Adversarial Robustness Toolbox
Animesh Singh371 views
42 minutes to secure your code.... by Sebastien Gioria
42 minutes to secure your code....42 minutes to secure your code....
42 minutes to secure your code....
Sebastien Gioria2.1K views
Building Interpretable & Secure AI Systems using PyTorch by geetachauhan
Building Interpretable & Secure AI Systems using PyTorchBuilding Interpretable & Secure AI Systems using PyTorch
Building Interpretable & Secure AI Systems using PyTorch
geetachauhan259 views

Recently uploaded

Correct handling of laboratory Rats ppt.pptx by
Correct handling of laboratory Rats ppt.pptxCorrect handling of laboratory Rats ppt.pptx
Correct handling of laboratory Rats ppt.pptxTusharChaudhary99
34 views12 slides
Testicular tumors.pptx by
Testicular tumors.pptxTesticular tumors.pptx
Testicular tumors.pptxUtkarsh Singhal
36 views64 slides
Prodrugs by
ProdrugsProdrugs
ProdrugsDr. Ajmer Singh Grewal
62 views113 slides
Buccoadhesive drug delivery System.pptx by
Buccoadhesive drug delivery System.pptxBuccoadhesive drug delivery System.pptx
Buccoadhesive drug delivery System.pptxABG
176 views43 slides
Clindamycin by
ClindamycinClindamycin
ClindamycinDr. Ajmer Singh Grewal
13 views23 slides
Breast Ductography.pptx by
Breast Ductography.pptxBreast Ductography.pptx
Breast Ductography.pptxPeerzadaJunaidUlIsla
56 views18 slides

Recently uploaded(20)

Correct handling of laboratory Rats ppt.pptx by TusharChaudhary99
Correct handling of laboratory Rats ppt.pptxCorrect handling of laboratory Rats ppt.pptx
Correct handling of laboratory Rats ppt.pptx
Buccoadhesive drug delivery System.pptx by ABG
Buccoadhesive drug delivery System.pptxBuccoadhesive drug delivery System.pptx
Buccoadhesive drug delivery System.pptx
ABG176 views
Gastro-retentive drug delivery systems.pptx by ABG
Gastro-retentive drug delivery systems.pptxGastro-retentive drug delivery systems.pptx
Gastro-retentive drug delivery systems.pptx
ABG242 views
Western Blotting (Protein Separation technique) .pptx by Ankit Mehra
Western Blotting (Protein Separation technique) .pptxWestern Blotting (Protein Separation technique) .pptx
Western Blotting (Protein Separation technique) .pptx
Ankit Mehra55 views
Prof. Dame Louise Robinson - Future of Ageing 2023 by ILCUK
Prof. Dame Louise Robinson - Future of Ageing 2023Prof. Dame Louise Robinson - Future of Ageing 2023
Prof. Dame Louise Robinson - Future of Ageing 2023
ILCUK37 views
Suppositories and pessaries by Priyanka Kandhare by Priyanka Kandhare
Suppositories and pessaries by Priyanka KandhareSuppositories and pessaries by Priyanka Kandhare
Suppositories and pessaries by Priyanka Kandhare
Calcutta Clinical Course - Allen College of Homoeopathy by Allen College
Calcutta Clinical Course - Allen College of HomoeopathyCalcutta Clinical Course - Allen College of Homoeopathy
Calcutta Clinical Course - Allen College of Homoeopathy
Allen College103 views
Adverse Drug Reactions by NAKUL DHORE
Adverse Drug ReactionsAdverse Drug Reactions
Adverse Drug Reactions
NAKUL DHORE26 views

Pycontw2020 - 我們如何在醫院打造即時醫療影像AI平台