@@ -157,6 +157,7 @@ def _process_segment_and_label(video_matrix, num_frames, contexts,
157
157
return output_dict
158
158
159
159
160
+ # TODO(allenyan, zhengxu): Adds a unit test for this function.
160
161
def _get_video_matrix (features , feature_size , dtype , max_frames ,
161
162
max_quantized_value , min_quantized_value ):
162
163
"""Decodes features from an input string and quantizes it.
@@ -187,8 +188,16 @@ def _get_video_matrix(features, feature_size, dtype, max_frames,
187
188
return feature_matrix , num_frames
188
189
189
190
190
- def _concat_features (features , feature_names , feature_sizes , feature_dtypes ,
191
- max_frames , max_quantized_value , min_quantized_value ):
191
+ def _concat_features (
192
+ features ,
193
+ feature_names ,
194
+ feature_sizes ,
195
+ feature_dtypes ,
196
+ max_frames ,
197
+ max_quantized_value ,
198
+ min_quantized_value ,
199
+ per_feature_l2_norm = False ,
200
+ ):
192
201
"""Loads (potentially) different types of features and concatenates them.
193
202
194
203
Args:
@@ -199,6 +208,7 @@ def _concat_features(features, feature_names, feature_sizes, feature_dtypes,
199
208
max_frames: number of frames in the sequence
200
209
max_quantized_value: the maximum of the quantized value.
201
210
min_quantized_value: the minimum of the quantized value.
211
+ per_feature_l2_norm: whether to l2 normalize each feature.
202
212
203
213
Returns:
204
214
video_matrix: different features concatenated into one matrix
@@ -225,6 +235,8 @@ def _concat_features(features, feature_names, feature_sizes, feature_dtypes,
225
235
min_quantized_value )
226
236
num_common_frames = tf .math .minimum (num_frames_in_this_feature ,
227
237
num_common_frames )
238
+ if per_feature_l2_norm :
239
+ feature_matrix = tf .math .l2_normalize (feature_matrix , axis = - 1 )
228
240
feature_matrices [i ] = feature_matrix
229
241
230
242
for i in range (num_features ):
@@ -347,14 +359,15 @@ def __init__(
347
359
self ._num_sample_frames = input_params .num_sample_frames
348
360
self ._max_quantized_value = max_quantized_value
349
361
self ._min_quantized_value = min_quantized_value
362
+ self ._input_per_feature_l2_norm = input_params .input_per_feature_l2_norm
350
363
351
364
def _parse_train_data (self , decoded_tensors ):
352
365
"""Parses data for training."""
353
366
# loads (potentially) different types of features and concatenates them
354
367
video_matrix , num_frames = _concat_features (
355
368
decoded_tensors , self ._feature_names , self ._feature_sizes ,
356
369
self ._feature_dtypes , self ._max_frames , self ._max_quantized_value ,
357
- self ._min_quantized_value )
370
+ self ._min_quantized_value , self . _input_per_feature_l2_norm )
358
371
if not self ._include_video_id and "id" in decoded_tensors :
359
372
del decoded_tensors ["id" ]
360
373
@@ -383,7 +396,7 @@ def _parse_eval_data(self, decoded_tensors):
383
396
video_matrix , num_frames = _concat_features (
384
397
decoded_tensors , self ._feature_names , self ._feature_sizes ,
385
398
self ._feature_dtypes , self ._max_frames , self ._max_quantized_value ,
386
- self ._min_quantized_value )
399
+ self ._min_quantized_value , self . _input_per_feature_l2_norm )
387
400
if not self ._include_video_id and "id" in decoded_tensors :
388
401
del decoded_tensors ["id" ]
389
402
0 commit comments