writer
This section contains the documentation of movinets_helper\writer.py
.
Helper to write mp4 videos to TFRecordDataset.
convert_mp4_to_tfrecord(dataset_df, target_path, n_videos_in_record=15, n_frames_per_video=10, resolution=224)
Saves videos in mp4 format to tfrecords.
It creates a new dataset of homogeneus videos, all with shape: (n_frames, resolution, resolution, channels=3), along with its label and shape features to be loaded back.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_df |
pd.DataFrame
|
Dataframe with 2 columns: classes, representing the labels, and files, with the path to the videos. |
required |
target_path |
Path
|
Path where the files will be generated. It must be already generated. |
required |
n_videos_in_record |
int
|
Number of videos per file. See the notes in https://www.tensorflow.org/tutorials/load_data/tfrecord Defaults to 10. |
15
|
n_frames_per_video |
int
|
Number of frames to select per video. Defaults to 10. |
10
|
resolution |
int
|
Try to keep to as low as possible to save space and computing time during writing. This can be updated later. Defaults to 224. |
224
|
Example
Generate a dataset of tf records
convert_mp4_to_tfrecord(dataset_df[["classes", "files"]], target_path)
Split into train/test
convert_mp4_to_tfrecord(train_dataset_df[["classes", "files"]], target_path_train) convert_mp4_to_tfrecord(test_dataset_df[["classes", "files"]], target_path_test)
Note
This data format isn't storage friendly, even after compression.
Source code in movinets_helper/writer.py
serialize_example(label, video)
Creates a tf.train.Example message ready to be written to a file.
The output can be sent to a TFRecordWriter to be written.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label |
tf.Tensor
|
int encoded label. |
required |
video |
tf.Tensor
|
video as a tensor, maybe loaded using load_video_tf. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
representation of the features to be stored as .tfrecords. |
Note
Depending on the size (i.e., videos), jupyter won't be able to show them, a javascript error will raise.