Skip to content

Commit 7499b9b

Browse files
Add Example for DeepMedic
1 parent e07a705 commit 7499b9b

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM personalhealthtrain/train-api-python:1.0rc3-petronetto-deepmedic
2+
COPY entrypoint.py /opt/entrypoint.py
3+
ENTRYPOINT [ "python", "/opt/entrypoint.py" ]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.PHONY: all, describe, run
2+
all:
3+
docker build --rm --no-cache -t hello-world-petronetto-deepmedic:station.1 .
4+
5+
describe:
6+
docker run --rm hello-world-petronetto-deepmedic:station.1 --station-id 1 describe
7+
8+
run:
9+
docker run --rm hello-world-petronetto-deepmedic:station.1 --station-id 1 run
10+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
from pht.internal import StationRuntimeInfo, ConjunctionBuilder
3+
from pht.train.response import RunResponse
4+
from pht.train import SimpleTrain
5+
from pht.requirement import url_by_name, Require
6+
from pht.train.response.exit_state import SUCCESS
7+
from pht.rebase import DockerRebaseStrategy
8+
from pht.entrypoint import cmd_for_train
9+
import deepmedic
10+
11+
model_file = '/opt/model'
12+
13+
14+
class MyTrain(SimpleTrain):
15+
def __init__(self):
16+
self.data_source = url_by_name('MY_DATA_SOURCE')
17+
18+
# Define the requirements of the Train here
19+
def requirements(self) -> ConjunctionBuilder:
20+
return Require(self.data_source)
21+
22+
# Generate the Summary of the Model
23+
def model_summary(self) -> str:
24+
return 'Hello from: DeepMedic'
25+
26+
# Run the algorithm (fetch data, generate model, etc.)
27+
def run(self, info: StationRuntimeInfo) -> RunResponse:
28+
29+
# Fetch the data here
30+
31+
# Implement the algorithm here and serialze the learned model to the filesystem, something like this
32+
if not os.path.exists('/opt'):
33+
os.mkdir('/opt')
34+
with open(model_file, 'w') as f:
35+
f.write('Hello World')
36+
37+
return RunResponse(
38+
state=SUCCESS,
39+
free_text_message='Hello world',
40+
rebase=DockerRebaseStrategy(
41+
frm='personalhealthtrain/train-api-python:1.0rc3',
42+
next_train_tag='station.2',
43+
export_files=[model_file]
44+
)
45+
)
46+
47+
48+
if __name__ == '__main__':
49+
cmd_for_train(MyTrain())

0 commit comments

Comments
 (0)