Skip to content

Instantly share code, notes, and snippets.

from skimage import measure
labels = measure.label(mask)
props = measure.regionprops(labels, img_hed)[0]
angle = props.orientation
from skimage import morphology
mask = morphology.remove_small_objects(mask, 40000)
mask = morphology.remove_small_holes(mask, 40000)
img_rgb = skimage.io.imread('../pics/video_red/00535.jpeg')
mask = ((img_rgb[:, :, 0] > 130) & (img_rgb[:, :, 1] < 60) & (img_rgb[:, :, 2] < 60))
...
img_rgb = skimage.io.imread(fnamei)
# 1. RGB to HED
img_hed = rgb2hed(img_rgb)
img = img_hed[:, :, 1]
# 2. Create mask using threshold
mask = (img > 0.05)
...
for time in tqdm(ran):
o0 = np.interp(time, Time, df['gyroRotationX(rad/s)'])
o1 = np.interp(time, Time, df['gyroRotationY(rad/s)'])
o2 = np.interp(time, Time, df['gyroRotationZ(rad/s)'])
a0 = np.interp(time, Time, df['accelerometerAccelerationX(G)'])
a1 = np.interp(time, Time, df['accelerometerAccelerationY(G)'])
a2 = np.interp(time, Time, df['accelerometerAccelerationZ(G)'])
import pandas as pd
import pylab as plt
import numpy as np
from tqdm import tqdm
df = pd.read_csv("../data/measurements_new.csv")
# 0. Initialize variablles
e0 = np.array((1, 0, 0), np.longdouble)
e1 = np.array((0, 1, 0), np.longdouble)
import boto3
import json
client = boto3.client('sagemaker-runtime')
response = client.invoke_endpoint(
EndpointName=predictor.endpoint_name,
Body=json.dumps({"text": "preved medved"}),
ContentType='application/json',
Accept="application/json"
)
result = response['Body'].read().decode()
model.fit()
predictor = model.deploy(initial_instance_count=1, instance_type='ml.m5.4xlarge')
from sagemaker.predictor import RealTimePredictor, json_deserializer
import sagemaker
from sagemaker.pytorch import PyTorch, PyTorchModel
from sagemaker.sklearn import SKLearn
role = sagemaker.get_execution_role()
## Class to accept output in JSON format
class Predictor(RealTimePredictor):
def __init__(self, endpoint_name, sagemaker_session):
super().__init__(endpoint_name, sagemaker_session=sagemaker_session, serializer=None,
# Specify that endpoint accept JSON
JSON_CONTENT_TYPE = 'application/json'
def predict_fn(input, model):
proba = model.predict_proba(input)
return json.dumps({
"proba": str(list(proba[0]))
})
def model_fn(model_dir):