Skip to content

Instantly share code, notes, and snippets.

Avatar

Siaterlis Konstantinos siakon89

View GitHub Profile
View custom_label.py
import boto3
import io
from PIL import Image, ImageDraw, ExifTags, ImageColor, ImageFont
import os
def show_custom_labels(model,bucket,photo, min_confidence):
profile_dev = boto3.session.Session(profile_name='dev', region_name='us-west-2')
client = profile_dev.client('rekognition')
View elatic_inference.py
predictor = estimator.deploy(
initial_instance_count=1,
instance_type='ml.p2.xlarge',
endpoint_name="no-elastic-inference-test"
)
predictor = estimator.deploy(
initial_instance_count=1,
instance_type='ml.c5.large',
accelerator_type='ml.eia1.medium',
View spot_instances.py
estimator = TensorFlow(
entry_point='model.py', # Script that has the model
train_instance_type='ml.p3.2xlarge', # The instance type for training
train_instance_count=1, # The number of instances to be spawned
model_dir='/opt/ml/model', # The location for the trained model
hyperparameters={ # Hyperparameters for the model
'epochs': 250,
'batch_size': 128,
'learning_rate': 0.001
},
View dagemaker_debugger_rule.py
from sagemaker.debugger import Rule, rule_configs
estimator = TensorFlow(
entry_point='model.py',
train_instance_type=train_instance_type,
train_instance_count=1,
model_dir=model_dir,
hyperparameters=hyperparameters,
role=sagemaker.get_execution_role(),
base_job_name='tf-fashion-mnist',
View smdebug_example.py
from smdebug.trials import create_trial
from smdebug import modes
import numpy as np
import matplotlib.pyplot as plt
# Get the tensors from S3
s3_output_path = estimator.latest_job_debugger_artifacts_path()
# Create a Trial https://github.com/awslabs/sagemaker-debugger/blob/master/docs/analysis.md#Trial
View custom_debugger_hook.py
debugger_hook_config = DebuggerHookConfig(
s3_output_path=f"s3://{bucket}/fashion-mnist/hook",
collection_configs=[
CollectionConfig(
name="all_tensors",
parameters={
"include_regex": ".*",
"save_steps": "1, 2, 3"
}
)
View estimator_hook.py
hyperparameters = {'epochs': 10, 'batch_size': 256, 'learning_rate': 0.001}
estimator = TensorFlow(
entry_point='model.py',
train_instance_type='ml.p3.2xlarge',
train_instance_count=1,
model_dir='/opt/ml/model',
hyperparameters=hyperparameters,
role=sagemaker.get_execution_role(),
base_job_name='tf-fashion-mnist',
View sagemaker_debugger_hook.py
from sagemaker.debugger import CollectionConfig, DebuggerHookConfig
bucket = sess.default_bucket()
collection_config_biases = CollectionConfig(name='biases')
collection_config_weights = CollectionConfig(name='weights')
collection_config_metrics = CollectionConfig(name='metrics')
debugger_hook_config = DebuggerHookConfig(
s3_output_path=f"s3://{bucket}/fashion-mnist/hook",
View deploy.sh
sam build
sam package --output-template-file .aws-sam/packaged.yaml --s3-bucket <a bucket to save the template> --profile <your profile name>
sam deploy --template-file .aws-sam/packaged.yaml --stack-name imageTagging --capabilities CAPABILITY_IAM --profile <your profile name>
View upload_images.py
import boto3
from boto3.s3.transfer import TransferConfig
BUCKET = "<your bucket from SAM template>"
REGION = "<your region>"
PROFILE = "<your profile>"
def upload_to_s3(file_name, key, bucket=BUCKET, region=REGION):
You can’t perform that action at this time.