Skip to content

Instantly share code, notes, and snippets.

View tgamauf's full-sized avatar

Thomas Gamauf tgamauf

View GitHub Profile
@tgamauf
tgamauf / tf_feature_lists.py
Last active March 17, 2018 18:54
Use of tf.train.BytesList, tf.train.FloatList, tf.train.Int64List
movie_name_list = tf.train.BytesList(value=[b'The Shawshank Redemption', b'Fight Club'])
movie_rating_list = tf.train.FloatList(value=[9.0, 9.7])
@tgamauf
tgamauf / tf_feature.py
Last active March 17, 2018 18:54
Use of tf.train.Feature
movie_names = tf.train.Feature(bytes_list=movie_name_list)
movie_ratings = tf.train.Feature(float_list=movie_rating_list)
@tgamauf
tgamauf / tf_features.py
Last active March 17, 2018 18:54
Use of tf.train.Features
movie_dict = {
'Movie Names': movie_names,
'Movie Ratings': movie_ratings
}
movies = tf.train.Features(feature=movie_dict)
@tgamauf
tgamauf / tf_example.py
Last active March 17, 2018 18:55
Use of tf.train.Example
example = tf.train.Example(features=movies)
@tgamauf
tgamauf / tf_featurelist.py
Last active March 17, 2018 18:59
Use of tf.train.FeatureList
movie_1_actors = tf.train.Feature(
bytes_list=tf.train.BytesList(
value=[b'Tim Robbins', b'Morgan Freeman']))
movie_2_actors = tf.train.Feature(
bytes_list=tf.train.BytesList(
value=[b'Brad Pitt', b'Edward Norton', b'Helena Bonham Carter']))
movie_actors_list = [movie_1_actors, movie_2_actors]
movie_actors = tf.train.FeatureList(feature=movie_actors_list)
# Short form
@tgamauf
tgamauf / tf_featurelists.py
Last active March 17, 2018 18:59
Use of tf.train.FeatureLists
movies_dict = {
'Movie Names': movie_names,
'Movie Ratings': movie_ratings,
'Movie Actors': movie_actors
}
movies = tf.train.FeatureLists(feature_list=movies_dict)
@tgamauf
tgamauf / tf_sequenceexample.py
Last active March 17, 2018 19:00
Use of tf.train.SequenceExample
# We can also add context features (short form)
customer = tf.train.Features(feature={
'Age': tf.train.Feature(int64_list=tf.train.Int64List(value=[19])),
})
example = tf.train.SequenceExample(
context=customer,
feature_lists=movies)
@tgamauf
tgamauf / tf_tfrecordwriter.py
Last active March 4, 2018 12:20
Use of tf.python_io.TFRecordWriter
# "example" is of type tf.train.Example.
with tf.python_io.TFRecordWriter('movie_ratings.tfrecord') as writer:
writer.write(example.SerializeToString())
@tgamauf
tgamauf / write_tfrecord_with_example.ipynb
Last active October 28, 2019 17:51
Write movie ratings to TFRecord file, then read it back
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.