This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage import measure | |
labels = measure.label(mask) | |
props = measure.regionprops(labels, img_hed)[0] | |
angle = props.orientation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage import morphology | |
mask = morphology.remove_small_objects(mask, 40000) | |
mask = morphology.remove_small_holes(mask, 40000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img_rgb = skimage.io.imread('../pics/video_red/00535.jpeg') | |
mask = ((img_rgb[:, :, 0] > 130) & (img_rgb[:, :, 1] < 60) & (img_rgb[:, :, 2] < 60)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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)']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.fit() | |
predictor = model.deploy(initial_instance_count=1, instance_type='ml.m5.4xlarge') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
NewerOlder