Skip to content

Instantly share code, notes, and snippets.

View juliensimon's full-sized avatar

Julien Simon juliensimon

View GitHub Profile
@juliensimon
juliensimon / retrain8.yml
Created May 12, 2018 20:05
retrain8.yml
service: sagemakerscheduler
provider:
name: aws
runtime: python2.7
memorySize: 128
iamRoleStatements:
- Effect: "Allow"
Action:
- sagemaker:DescribeTrainingJob
@juliensimon
juliensimon / retrain7.json
Created May 12, 2018 19:00
retrain7.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:CreateLogGroup"
@juliensimon
juliensimon / retrain6.sh
Last active May 12, 2018 19:33
retrain6.sh
$ chalice deploy
$ export URL=`chalice url`
$ http post $URL/train/DEMO-imageclassification-2018-05-10-09-58-12 \
TrainingJobName=imageclassification-2018-05-12 \
InstanceType=ml.p3.2xlarge InstanceCount=2
{
"ResponseMetadata": {
"HTTPHeaders": {
"connection": "keep-alive",
{
@juliensimon
juliensimon / retrain5.py
Last active May 12, 2018 19:33
retrain5.py
@app.route('/train/{name}', methods=['POST'])
def train_job_by_name(name):
job = sm.describe_training_job(TrainingJobName=name)
body = app.current_request.json_body
if 'TrainingJobName' not in body:
raise BadRequestError('Missing new job name')
else:
job['TrainingJobName'] = body['TrainingJobName']
if 'S3OutputPath' in body:
@juliensimon
juliensimon / retrain3.py
Created May 12, 2018 15:51
retrain3.py
@app.route('/get/{name}')
def get_job_by_name(name):
job = sm.describe_training_job(TrainingJobName=name)
return {'job': str(job)}
@juliensimon
juliensimon / retrain2.sh
Last active May 12, 2018 17:31
retrain2.sh
$ http get localhost:8000/jobs/2
{
"jobs": [
[
"sagemaker-tensorflow-py2-cpu-2018-03-10-10-41-27-307",
"Completed"
],
[
"sagemaker-mxnet-py2-gpu-2018-03-10-09-50-33-717",
"Completed"
@juliensimon
juliensimon / retrain1.py
Created May 12, 2018 15:46
retrain1.py
@app.route('/list/{results}')
def list_jobs(results):
jobs = sm.list_training_jobs(MaxResults=int(results), SortBy="CreationTime", SortOrder="Descending")
job_names = map(lambda job: [job['TrainingJobName'], job['TrainingJobStatus']], jobs['TrainingJobSummaries'])
return {'jobs': list(job_names)}
@juliensimon
juliensimon / spam-sagemaker5.txt
Created May 8, 2018 17:00
spam-sagemaker5.txt
+-----+--------------------+----------+
|label| features|prediction|
+-----+--------------------+----------+
| 1.0|(200,[25,41,99,14...| 1.0|
| 1.0|(200,[30,41,63,91...| 1.0|
| 1.0|(200,[0,13,30,48,...| 1.0|
| 1.0|(200,[22,30,36,40...| 1.0|
| 1.0|(200,[15,17,29,32...| 1.0|
| 1.0|(200,[25,31,45,48...| 0.0|
| 1.0|(200,[25,32,34,47...| 1.0|
@juliensimon
juliensimon / spam-sagemaker4.txt
Created May 8, 2018 16:57
spam-sagemaker4.txt
+-----+--------------------+
|label| features|
+-----+--------------------+
| 1.0|(200,[1,29,37,48,...|
| 1.0|(200,[17,19,42,48...|
| 1.0|(200,[17,19,20,25...|
| 1.0|(200,[13,20,34,36...|
| 1.0|(200,[3,25,36,73,...|
+-----+--------------------+
@juliensimon
juliensimon / spam-sagemaker3.scala
Created May 8, 2018 16:47
spam-sagemaker3.scala
val testData_libsvm = MLUtils.convertVectorColumnsToML(testData.toDF)
val transformedData = xgboost_model.transform(testData_libsvm)
val accuracy = 1.0 * transformedData.filter($"label"=== $"prediction").count / transformedData.count()