Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update params.json #5

Open
wants to merge 107 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
02d8aea
Update params.json
USYD-jqia9055-Lucas Oct 17, 2021
b989404
Update params.json
USYD-jqia9055-Lucas Oct 17, 2021
1aed41c
Create test.txt
USYD-jqia9055-Lucas Oct 17, 2021
ce22bc6
Update test.txt
USYD-jqia9055-Lucas Oct 17, 2021
2cb1fc4
Update test.txt
USYD-jqia9055-Lucas Oct 17, 2021
621d140
Update test.txt
USYD-jqia9055-Lucas Oct 17, 2021
34fcdd3
Update test.txt
USYD-jqia9055-Lucas Oct 18, 2021
f47401c
Update test.txt
USYD-jqia9055-Lucas Oct 18, 2021
f4ac0bc
Update test.txt
USYD-jqia9055-Lucas Oct 18, 2021
c5b0a51
Update Dockerfile
USYD-jqia9055-Lucas Oct 18, 2021
0244932
Update Dockerfile
USYD-jqia9055-Lucas Oct 18, 2021
09ded25
Update Dockerfile
USYD-jqia9055-Lucas Oct 18, 2021
d4fb000
Update Dockerfile
USYD-jqia9055-Lucas Oct 18, 2021
df0f6fd
Update Dockerfile
USYD-jqia9055-Lucas Oct 18, 2021
42d67b4
Update test.txt
USYD-jqia9055-Lucas Oct 19, 2021
e710bf2
Update test.txt
USYD-jqia9055-Lucas Oct 19, 2021
0dd5917
Update test.txt
USYD-jqia9055-Lucas Oct 20, 2021
2191d3b
Update Dockerfile
USYD-jqia9055-Lucas Oct 22, 2021
264bb58
Update Dockerfile
USYD-jqia9055-Lucas Oct 22, 2021
df77141
Update Dockerfile
USYD-jqia9055-Lucas Oct 22, 2021
88944e7
Create requirements.txt
USYD-jqia9055-Lucas Oct 22, 2021
01fbd61
Update test.txt
USYD-jqia9055-Lucas Oct 22, 2021
3850e45
Update Dockerfile
USYD-jqia9055-Lucas Oct 22, 2021
fdf8386
Update Dockerfile
USYD-jqia9055-Lucas Oct 22, 2021
7b85a59
Update Dockerfile
USYD-jqia9055-Lucas Oct 22, 2021
d65fb80
Update Dockerfile
USYD-jqia9055-Lucas Oct 22, 2021
1fa8b20
Update Dockerfile
USYD-jqia9055-Lucas Oct 22, 2021
7306b5f
Update Dockerfile
USYD-jqia9055-Lucas Oct 22, 2021
1aa0de5
Delete requirements.txt
USYD-jqia9055-Lucas Oct 22, 2021
33032ce
Update Dockerfile
USYD-jqia9055-Lucas Oct 22, 2021
61e0ec5
Update test.txt
USYD-jqia9055-Lucas Oct 22, 2021
87a5ae9
Update test.txt
USYD-jqia9055-Lucas Oct 23, 2021
ad64711
Update Dockerfile
USYD-jqia9055-Lucas Oct 27, 2021
8e15b06
Update Dockerfile
USYD-jqia9055-Lucas Oct 27, 2021
6a9a24e
Update Dockerfile
USYD-jqia9055-Lucas Oct 27, 2021
ea5fb2d
Update Dockerfile
USYD-jqia9055-Lucas Oct 27, 2021
fadee65
Update serve
USYD-jqia9055-Lucas Oct 27, 2021
8e046ef
Update train
USYD-jqia9055-Lucas Oct 27, 2021
8497fee
Update serve
USYD-jqia9055-Lucas Oct 27, 2021
2c470b6
Update train
USYD-jqia9055-Lucas Oct 27, 2021
c02623d
Update train
USYD-jqia9055-Lucas Oct 27, 2021
a851bb5
Update Dockerfile
USYD-jqia9055-Lucas Oct 27, 2021
a39dce8
Update Dockerfile
USYD-jqia9055-Lucas Oct 27, 2021
cac209e
Update Dockerfile
USYD-jqia9055-Lucas Oct 27, 2021
272a5f9
Update train
USYD-jqia9055-Lucas Oct 28, 2021
c4a567d
Update train
USYD-jqia9055-Lucas Oct 28, 2021
68893f7
Update Dockerfile
USYD-jqia9055-Lucas Oct 28, 2021
8bdb5b1
Update train
USYD-jqia9055-Lucas Oct 28, 2021
12fce52
Add files via upload
USYD-jqia9055-Lucas Oct 28, 2021
502a703
Delete test.csv
USYD-jqia9055-Lucas Oct 31, 2021
8bced6e
Update test.txt
USYD-jqia9055-Lucas Nov 1, 2021
fde767f
Update test.txt
USYD-jqia9055-Lucas Nov 1, 2021
8637863
Update test.txt
USYD-jqia9055-Lucas Nov 2, 2021
f179427
Update train
USYD-jqia9055-Lucas Nov 3, 2021
387d12f
Update train
USYD-jqia9055-Lucas Nov 3, 2021
6b6fa74
Update train
USYD-jqia9055-Lucas Nov 3, 2021
85776a4
Update train
USYD-jqia9055-Lucas Nov 3, 2021
418e00e
Update Dockerfile
USYD-jqia9055-Lucas Nov 3, 2021
d5ebe43
Update train
USYD-jqia9055-Lucas Nov 3, 2021
a5938cf
Update train
USYD-jqia9055-Lucas Nov 4, 2021
8d69dcb
Update Dockerfile
USYD-jqia9055-Lucas Nov 4, 2021
28b2e01
Update train
USYD-jqia9055-Lucas Nov 4, 2021
f5cae79
Update train
USYD-jqia9055-Lucas Nov 4, 2021
b00d9af
Update train
USYD-jqia9055-Lucas Nov 4, 2021
96d9338
Update train
USYD-jqia9055-Lucas Nov 4, 2021
323fd2b
Update train
USYD-jqia9055-Lucas Nov 4, 2021
a3a616f
Update train
USYD-jqia9055-Lucas Nov 4, 2021
f9a2956
Update train
USYD-jqia9055-Lucas Nov 4, 2021
2b85b6b
Update train
USYD-jqia9055-Lucas Nov 4, 2021
ab3c28f
Update train
USYD-jqia9055-Lucas Nov 4, 2021
0bfb644
Update train
USYD-jqia9055-Lucas Nov 4, 2021
db237c1
Update test.txt
USYD-jqia9055-Lucas Nov 4, 2021
49c6242
Update predictor.py
USYD-jqia9055-Lucas Nov 4, 2021
5062e6d
Update predictor.py
USYD-jqia9055-Lucas Nov 5, 2021
ecc9dab
Update Dockerfile
USYD-jqia9055-Lucas Nov 5, 2021
015370a
Update Dockerfile
USYD-jqia9055-Lucas Nov 5, 2021
feda288
Update Dockerfile
USYD-jqia9055-Lucas Nov 5, 2021
3dd7ec1
Update predictor.py
USYD-jqia9055-Lucas Nov 8, 2021
b8b0ad1
Update train
USYD-jqia9055-Lucas Nov 9, 2021
b2a84ce
Update train
USYD-jqia9055-Lucas Nov 9, 2021
e4cc626
Update predictor.py
USYD-jqia9055-Lucas Nov 9, 2021
7750085
Update train
USYD-jqia9055-Lucas Nov 9, 2021
201dc6c
Update train
USYD-jqia9055-Lucas Nov 10, 2021
2deab5e
Update predictor.py
USYD-jqia9055-Lucas Nov 10, 2021
a101264
Update train
USYD-jqia9055-Lucas Nov 10, 2021
ede16a2
Update predictor.py
USYD-jqia9055-Lucas Nov 10, 2021
f22ce03
Update predictor.py
USYD-jqia9055-Lucas Nov 10, 2021
08b7d2e
Update predictor.py
USYD-jqia9055-Lucas Nov 10, 2021
82ebde3
Update predictor.py
USYD-jqia9055-Lucas Nov 10, 2021
bad0a13
Update predictor.py
USYD-jqia9055-Lucas Nov 10, 2021
3ace32a
Update predictor.py
USYD-jqia9055-Lucas Nov 10, 2021
d4621ce
Update predictor.py
USYD-jqia9055-Lucas Nov 10, 2021
b12a17d
Update predictor.py
USYD-jqia9055-Lucas Nov 10, 2021
2644f1d
Update predictor.py
USYD-jqia9055-Lucas Nov 10, 2021
21b3c70
Update predictor.py
USYD-jqia9055-Lucas Nov 11, 2021
bd0b441
Update predictor.py
USYD-jqia9055-Lucas Nov 11, 2021
7e3d359
Update predictor.py
USYD-jqia9055-Lucas Nov 11, 2021
868c7c0
Update predictor.py
USYD-jqia9055-Lucas Nov 11, 2021
840553c
Update predictor.py
USYD-jqia9055-Lucas Nov 11, 2021
8de9cd0
Update predictor.py
USYD-jqia9055-Lucas Nov 11, 2021
d7af636
Update predictor.py
USYD-jqia9055-Lucas Nov 11, 2021
22f5183
Update predictor.py
USYD-jqia9055-Lucas Nov 11, 2021
cdc7c41
Update predictor.py
USYD-jqia9055-Lucas Nov 11, 2021
1644868
Update train
USYD-jqia9055-Lucas Nov 13, 2021
9bd2a45
Delete assets directory
USYD-jqia9055-Lucas Nov 15, 2021
9965ce3
Delete container/local_test directory
USYD-jqia9055-Lucas Nov 15, 2021
5d4d653
Update params.json
USYD-jqia9055-Lucas Nov 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed assets/Architecture.PNG
Binary file not shown.
Binary file removed assets/folder_structure.PNG
Binary file not shown.
32 changes: 16 additions & 16 deletions cfn/params.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[
{
"ParameterKey": "GitHubRepo",
"ParameterValue": "codepipeline-ecr-build-sf-execution"
"ParameterValue": "enter cloned repo name here for codepipeline-ecr-build-sf-execution"
},
{
"ParameterKey": "GitHubBranch",
"ParameterValue": "master"
},
{
"ParameterKey": "GitHubToken",
"ParameterValue": ""
},
{
"ParameterKey": "GitHubUser",
"ParameterValue": ""
},
{
"ParameterKey": "MlOpsStepFunctionArn",
"ParameterValue": ""
}
]
"ParameterValue": "enter branch - main or xxx"
},
{
"ParameterKey": "GitHubToken",
"ParameterValue": "enter github token here"
},
{
"ParameterKey": "GitHubUser",
"ParameterValue": "enter github user here"
},
{
"ParameterKey": "MlOpsStepFunctionArn",
"ParameterValue": "enter MLOpsStep Functions Arn here"
}
]
51 changes: 35 additions & 16 deletions container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,44 @@
# for serving inferences in a stable way.

FROM public.ecr.aws/lts/ubuntu:20.04
RUN apt update
RUN apt install -y software-properties-common
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt install -y python3.7

# install pip
RUN apt install -y python3-pip

RUN apt-get -y update && apt-get install -y --no-install-recommends \
wget \
python \
nginx \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get install -y --no-install-recommends nginx ca-certificates
RUN rm -rf /var/lib/apt/lists/*

# Here we get all python packages.
# There's substantial overlap between scipy and numpy that we eliminate by
# linking them together. Likewise, pip leaves the install caches populated which uses
# a significant amount of space. These optimizations save a fair amount of space in the
# image, which reduces start up time.
RUN wget https://bootstrap.pypa.io/pip/2.7/get-pip.py && python get-pip.py && \
pip install numpy==1.16.2 scipy==1.2.1 scikit-learn==0.20.2 pandas flask gevent gunicorn && \
(cd /usr/local/lib/python2.7/dist-packages/scipy/.libs; rm *; ln ../../numpy/.libs/* .) && \
rm -rf /root/.cache
RUN python3.7 -m pip install langid
RUN python3.7 -m pip install langdetect
RUN python3.7 -m pip install emoji
RUN python3.7 -m pip install nltk==3.2.5
RUN python3.7 -m pip install pandas==1.1.5
RUN python3.7 -m pip install numpy==1.19.5
RUN python3.7 -m pip install torch
RUN python3.7 -m pip install transformers
RUN python3.7 -m pip install flask
#previos versions for package gevent and gunicorn
#RUN python3.7 -m pip install gevent==1.5.0
#RUN python3.7 -m pip install gunicorn

#RUN python3.7 -m pip install gevent==1.3.4
#RUN python3.7 -m pip install gunicorn==19.9.0


#RUN python3.7 -m pip install gevent==20.6.2
#RUN python3.7 -m pip install gunicorn==20.0.4

RUN python3.7 -m pip install gevent==20.9.0
RUN python3.7 -m pip install gunicorn==20.0.4

RUN python3.7 -m pip install sklearn
RUN python3.7 -m pip install gensim
RUN python3.7 -m pip install xlrd
RUN python3.7 -m pip install openpyxl

# Set some environment variables. PYTHONUNBUFFERED keeps Python from buffering our standard
# output stream, which means that logs can be delivered to the user quickly. PYTHONDONTWRITEBYTECODE
Expand All @@ -37,4 +57,3 @@ WORKDIR /opt/program

RUN chmod +x /opt/program/train
RUN chmod +x /opt/program/serve

92 changes: 80 additions & 12 deletions container/decision_trees/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
import os
import json
import pickle
import StringIO
import sys
import signal
import traceback

import flask
import io

import numpy as np

import pandas as pd
import torch

prefix = '/opt/ml/'
model_path = os.path.join(prefix, 'model')
Expand All @@ -27,28 +29,73 @@ class ScoringService(object):
@classmethod
def get_model(cls):
"""Get the model object for this instance, loading it if it's not already loaded."""
print('test get model -- test+1')
if cls.model == None:
with open(os.path.join(model_path, 'decision-tree-model.pkl'), 'r') as inp:
cls.model = pickle.load(inp)
#with open(os.path.join(model_path, 'decision-tree-model.pkl'), 'r') as inp:
# with open(os.path.join(model_path, 'best-LSTM-model-parameters.pkl'), 'rb') as inp:
# cls.model = pickle.load(inp)
#the_model = torch.load(os.path.join(model_path, 'best-LSTM-model-parameters.pt'))
#return cls.model

cls.model = torch.jit.load(os.path.join(model_path, 'best-LSTM-model-parameters.pth'))

return cls.model

@classmethod
def predict(cls, input):
print('test predict')
"""For the input, do the predictions and return them.

Args:
input (a pandas dataframe): The data on which to do the predictions. There will be
one prediction per row in the dataframe"""
clf = cls.get_model()
return clf.predict(input)


try:
clf = cls.get_model()
except:
print('did not get the model')

print('@@@@@@@@@@@@@@@@@@@')
print(type(input))
print(input)
print(input[0])
print(input[1])
print('@@@@@@@@@@@@@@@@@@@')


test_input=[[2779, 4496, 1744, 3480, 674, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24]]

#return clf.predict(input)


try:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
x=torch.from_numpy(np.array(input)).to(device)
except Exception as error:
print('Caught this error: ' + repr(error))
print('error when generating input')

try:
with torch.no_grad():
result = clf(x)
except Exception as error:
print('Caught this error: ' + repr(error))
print('error when returing results for prediction')

return result

# The flask app for serving predictions
app = flask.Flask(__name__)

@app.route('/ping', methods=['GET'])
def ping():
"""Determine if the container is working and healthy. In this sample container, we declare
it healthy if we can load the model successfully."""
print('testing ping()')
health = ScoringService.get_model() is not None # You can insert a health check here

status = 200 if health else 404
Expand All @@ -61,23 +108,44 @@ def transformation():
just means one prediction per line, since there's a single column.
"""
data = None

print('testing transformation')
# Convert from CSV to pandas
if flask.request.content_type == 'text/csv':
data = flask.request.data.decode('utf-8')
s = StringIO.StringIO(data)
s = io.StringIO(data)
data = pd.read_csv(s, header=None)
else:
return flask.Response(response='This predictor only supports CSV data', status=415, mimetype='text/plain')


print('#############')
print('aaa')
print('#############1')
print(data)
print('#############2')
print(data[0])
print('#############3')
print(data.head() )
print(type(data))
print('############4')
print('start')
print(len(data[0]))
for x in range(len(data[0])):
print(x)

print('aaa')
print('Invoked with {} records'.format(data.shape[0]))

# Do the prediction
predictions = ScoringService.predict(data)


print('*******')
print(predictions)
print('*******')

# Convert from numpy back to CSV
out = StringIO.StringIO()
pd.DataFrame({'results':predictions}).to_csv(out, header=False, index=False)
out = io.StringIO()
pd.DataFrame({'results':predictions[0]}).to_csv(out, header=False, index=False)
result = out.getvalue()

return flask.Response(response=result, status=200, mimetype='text/csv')
3 changes: 2 additions & 1 deletion container/decision_trees/serve
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/python3.7
#######!/usr/bin/env python

# This file implements the scoring service shell. You don't necessarily need to modify it for various
# algorithms. It starts nginx and gunicorn with the correct configurations and then simply waits until
Expand Down
Loading