Commit dee0aaa3 authored by Benjamin Milde's avatar Benjamin Milde

Implemented rudimentary average_utts=False getVectors functionality, needs testing

parent ca3d302f
...@@ -85,6 +85,13 @@ def get_vectors(): ...@@ -85,6 +85,13 @@ def get_vectors():
else: else:
print('POST /get_vectors called without average_utts parameter, setting to default true (enable)') print('POST /get_vectors called without average_utts parameter, setting to default true (enable)')
average_utts = True average_utts = True
if not average_utts or average_utts == 'False' or average_utts == 'false':
if 'stride' in flask.request.form:
stride = int(flask.request.form['stride'])
print('POST /get_vectors called with average_utts = False, but stride parameter is not set, setting it to the default value (1)')
stride = 1
normalize = ('normalize' in flask.request.form) normalize = ('normalize' in flask.request.form)
...@@ -115,8 +122,22 @@ def get_vectors(): ...@@ -115,8 +122,22 @@ def get_vectors():
response_str = json.dumps({'status':'success', 'vectors':response_vec_dict}) response_str = json.dumps({'status':'success', 'vectors':response_vec_dict})
else: else:
print('Not yet supported') if stride != 1:
response_str = json.dumps({'status':'fail', 'reason':'average_utts==False not yet supported'}) feats = [feat[::stride] for feat in feats]
if half_index != -1:
print('Cutting vectors at ', half_index)
print('Not yet supported')
if normalize:
feats = [(feat.T / np.linalg.norm(feat, axis=1)).T for feat in feats]
response_vec_dict = {}
for utt_id, feat in zip(utt_ids, feats):
response_vec_dict[utt_id] = feat.tolist()
response_str = json.dumps({'status':'success', 'vectors':response_vec_dict})
response = Response(response_str, mimetype='application/json') response = Response(response_str, mimetype='application/json')
return response return response
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment