Skip to content

Commit 2cb278f

Browse files
authored
Remove regex from tutorial (#699)
1 parent 1abb8ac commit 2cb278f

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

examples/sklearn/iris-classifier/README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,14 @@ $ python3 trainer.py
6161

6262
import boto3
6363
import pickle
64-
import re
6564

6665
labels = ["setosa", "versicolor", "virginica"]
6766

6867

6968
class PythonPredictor:
7069
def __init__(self, config):
71-
bucket, key = re.match("s3://(.+?)/(.+)", config["model"]).groups()
7270
s3 = boto3.client("s3")
73-
s3.download_file(bucket, key, "model.pkl")
71+
s3.download_file(config["bucket"], config["key"], "model.pkl")
7472

7573
self.model = pickle.load(open("model.pkl", "rb"))
7674

@@ -117,7 +115,8 @@ Create a `cortex.yaml` file and add the configuration below. A `deployment` spec
117115
python:
118116
predictor: predictor.py
119117
config:
120-
model: s3://cortex-examples/sklearn/iris-classifier/model.pkl
118+
bucket: cortex-examples
119+
key: sklearn/iris-classifier/model.pkl
121120
```
122121
123122
<br>
@@ -182,7 +181,8 @@ Add a `tracker` to your `cortex.yaml` and specify that this is a classification
182181
python:
183182
predictor: predictor.py
184183
config:
185-
model: s3://cortex-examples/sklearn/iris-classifier/model.pkl
184+
bucket: cortex-examples
185+
key: sklearn/iris-classifier/model.pkl
186186
tracker:
187187
model_type: classification
188188
```
@@ -224,7 +224,8 @@ This model is fairly small but larger models may require more compute resources.
224224
python:
225225
predictor: predictor.py
226226
config:
227-
model: s3://cortex-examples/sklearn/iris-classifier/model.pkl
227+
bucket: cortex-examples
228+
key: sklearn/iris-classifier/model.pkl
228229
tracker:
229230
model_type: classification
230231
compute:
@@ -269,7 +270,8 @@ If you trained another model and want to A/B test it with your previous model, s
269270
python:
270271
predictor: predictor.py
271272
config:
272-
model: s3://cortex-examples/sklearn/iris-classifier/model.pkl
273+
bucket: cortex-examples
274+
key: sklearn/iris-classifier/model.pkl
273275
tracker:
274276
model_type: classification
275277
compute:
@@ -281,7 +283,8 @@ If you trained another model and want to A/B test it with your previous model, s
281283
python:
282284
predictor: predictor.py
283285
config:
284-
model: s3://cortex-examples/sklearn/iris-classifier/another-model.pkl
286+
bucket: cortex-examples
287+
key: sklearn/iris-classifier/another-model.pkl
285288
tracker:
286289
model_type: classification
287290
compute:
@@ -316,16 +319,14 @@ First, implement `batch-predictor.py` with a `predict` function that can process
316319
317320
import boto3
318321
import pickle
319-
import re
320322
321323
labels = ["setosa", "versicolor", "virginica"]
322324
323325
324326
class PythonPredictor:
325327
def __init__(self, config):
326-
bucket, key = re.match("s3://(.+?)/(.+)", config["model"]).groups()
327328
s3 = boto3.client("s3")
328-
s3.download_file(bucket, key, "model.pkl")
329+
s3.download_file(config["bucket"], config["key"], "model.pkl")
329330
330331
self.model = pickle.load(open("model.pkl", "rb"))
331332
@@ -355,7 +356,8 @@ Next, add the `api` to `cortex.yaml`:
355356
python:
356357
predictor: predictor.py
357358
config:
358-
model: s3://cortex-examples/sklearn/iris-classifier/model.pkl
359+
bucket: cortex-examples
360+
key: sklearn/iris-classifier/model.pkl
359361
tracker:
360362
model_type: classification
361363
compute:
@@ -367,7 +369,8 @@ Next, add the `api` to `cortex.yaml`:
367369
python:
368370
predictor: predictor.py
369371
config:
370-
model: s3://cortex-examples/sklearn/iris-classifier/another-model.pkl
372+
bucket: cortex-examples
373+
key: sklearn/iris-classifier/another-model.pkl
371374
tracker:
372375
model_type: classification
373376
compute:
@@ -380,7 +383,8 @@ Next, add the `api` to `cortex.yaml`:
380383
python:
381384
predictor: batch-predictor.py
382385
config:
383-
model: s3://cortex-examples/sklearn/iris-classifier/model.pkl
386+
bucket: cortex-examples
387+
key: sklearn/iris-classifier/model.pkl
384388
compute:
385389
cpu: 0.5
386390
mem: 1G

examples/sklearn/iris-classifier/batch-predictor.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
import boto3
44
import pickle
5-
import re
65

76
labels = ["setosa", "versicolor", "virginica"]
87

98

109
class PythonPredictor:
1110
def __init__(self, config):
12-
bucket, key = re.match("s3://(.+?)/(.+)", config["model"]).groups()
1311
s3 = boto3.client("s3")
14-
s3.download_file(bucket, key, "model.pkl")
12+
s3.download_file(config["bucket"], config["key"], "model.pkl")
1513

1614
self.model = pickle.load(open("model.pkl", "rb"))
1715

examples/sklearn/iris-classifier/cortex.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
python:
99
predictor: predictor.py
1010
config:
11-
model: s3://cortex-examples/sklearn/iris-classifier/model.pkl
11+
bucket: cortex-examples
12+
key: sklearn/iris-classifier/model.pkl
1213
tracker:
1314
model_type: classification
1415
compute:
@@ -20,7 +21,8 @@
2021
python:
2122
predictor: predictor.py
2223
config:
23-
model: s3://cortex-examples/sklearn/iris-classifier/another-model.pkl
24+
bucket: cortex-examples
25+
key: sklearn/iris-classifier/another-model.pkl
2426
tracker:
2527
model_type: classification
2628
compute:
@@ -32,7 +34,8 @@
3234
python:
3335
predictor: batch-predictor.py
3436
config:
35-
model: s3://cortex-examples/sklearn/iris-classifier/model.pkl
37+
bucket: cortex-examples
38+
key: sklearn/iris-classifier/model.pkl
3639
compute:
3740
cpu: 0.5
3841
mem: 1G

examples/sklearn/iris-classifier/predictor.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
import boto3
44
import pickle
5-
import re
65

76
labels = ["setosa", "versicolor", "virginica"]
87

98

109
class PythonPredictor:
1110
def __init__(self, config):
12-
bucket, key = re.match("s3://(.+?)/(.+)", config["model"]).groups()
1311
s3 = boto3.client("s3")
14-
s3.download_file(bucket, key, "model.pkl")
12+
s3.download_file(config["bucket"], config["key"], "model.pkl")
1513

1614
self.model = pickle.load(open("model.pkl", "rb"))
1715

0 commit comments

Comments
 (0)