Skip to content

Instantly share code, notes, and snippets.

View andreaschandra's full-sized avatar
💼
work at anywhere

Andreas Chandra andreaschandra

💼
work at anywhere
View GitHub Profile
kmeans_model = 'topic-kmeans'
sm = boto3.client('sagemaker')
containers = {'us-west-2': '174872318107.dkr.ecr.us-west-2.amazonaws.com/kmeans:latest'}
create_model_response = sm.create_model( ModelName=kmeans_model,
ExecutionRoleArn=role,
PrimaryContainer={
'Image': containers[boto3.Session().region_name],
kmeans_endpoint_config = 'topic-kmeans-config'
print(kmeans_endpoint_config)
create_endpoint_config_response = sm.create_endpoint_config(
EndpointConfigName = kmeans_endpoint_config,
ProductionVariants = [{'InstanceType' : 'ml.m4.xlarge',
'InitialInstanceCount': 1,
'ModelName' : kmeans_model,
'VariantName' : 'AllTraffic'}
])
%%time
kmeans_endpoint = 'topic-kmeans-endpoint'
print(kmeans_endpoint)
create_endpoint_response = sm.create_endpoint(
EndpointName = kmeans_endpoint,
EndpointConfigName = kmeans_endpoint_config)
print(create_endpoint_response['EndpointArn'])
import tensorflow as tf
a_const = tf.constant([1,2,3])
sess = tf.Session()
sess.run(a_const)
#array([1, 2, 3], dtype=int32)
d = tf.Variable([3,4,5])
init_op = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init_op)
sess.run(d)
#array([4, 5, 6], dtype=int32)
ph = tf.placeholder(tf.int32)
sess = tf.Session()
sess.run(ph, feed_dict={ph: [9,8,7]})
#array([9, 8, 7], dtype=int32)
if len(args) != 2:
sys.stderr.write(
'Usage: example.py <aggressiveness> <path to wav file>\n')
sys.exit(1)
print("Reading file:", args[1])
print("aggressiveness:", args[0])
audio, sample_rate = read_wave(args[1])
vad = webrtcvad.Vad(int(args[0]))
print("Generating Frames...")
frames = frame_generator(30, audio, sample_rate)
frames = list(frames)
def vad_collector(sample_rate, frame_duration_ms, padding_duration_ms, vad, frames):
triggered = False
voiced_frames = []
for frame in frames:
is_speech = vad.is_speech(frame.bytes, sample_rate)
sys.stdout.write('1' if is_speech else '0')
if not triggered:
ring_buffer.append((frame, is_speech))