Skip to content

Instantly share code, notes, and snippets.

@wael34218
Last active December 16, 2021 16:22
Show Gist options
  • Save wael34218/8c1cec2965c6dbe8d7fda2a82225fdbf to your computer and use it in GitHub Desktop.
Save wael34218/8c1cec2965c6dbe8d7fda2a82225fdbf to your computer and use it in GitHub Desktop.

TensorFlow

TFRecords

To create a TF Record:

  1. Open a TFRecords file using tf.python_io.TFRecordWriter
  2. Convert your data into the proper data type of the feature using tf.train.Int64List, tf.train.BytesList, or tf.train.FloatList
  3. Create a feature using tf.train.Feature and pass the converted data to it
  4. Create an Example protocol buffer using tf.train.Example and pass the feature to it
  5. Serialize the Example to string using example.SerializeToString()
  6. Write the serialized example to TFRecords file using writer.write

Source: http://machinelearninguru.com/deep_learning/data_preparation/tfrecord/tfrecord.html

Dataset API

  1. Importing Data. Create a Dataset instance from some data
  2. Create an Iterator. By using the created dataset to make an Iterator instance to iterate thought the dataset
  3. Consuming Data. By using the created iterator we can get the elements from the dataset to feed the model

https://towardsdatascience.com/how-to-use-dataset-in-tensorflow-c758ef9e4428

https://medium.com/@TalPerry/getting-text-into-tensorflow-with-the-dataset-api-ffb832c8bec6

List all available devices (CPU/GPU):

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment