Posts

Showing posts with the label Preprocessing

TensorFlow Tutorial: tf.data for TFRecord

In this tutorial, we'll explore how to use TensorFlow's tf.data API to efficiently load and process TFRecord data for training deep learning models. The tf.data API provides a powerful and flexible way to build high-performance data input pipelines for TensorFlow. Code Examples 1. Importing Libraries import tensorflow as tf 2. Reading TFRecord Files # Define the list of TFRecord files tfrecord_files = [ "file1.tfrecord" , "file2.tfrecord" , "file3.tfrecord" ] # Define the feature description for parsing feature_description = { "image" : tf.io.FixedLenFeature([], tf.string), "label" : tf.io.FixedLenFeature([], tf.int64), } # Define a function to parse the TFRecord def parse_tfrecord(example_proto): return tf.io.parse_single_example(example_proto, feature_description) # Create a dataset from the TFRecord files dataset = tf.data.TFRecordDataset(tfrecord_files) # Map the parsing function to the datas...

PyTorch Tutorial: ImageFolder with Code Examples

In this tutorial, we'll explore how to use the ImageFolder dataset in PyTorch, a popular deep learning library, to load and preprocess image data for training a neural network. The ImageFolder dataset is useful when dealing with image data organized in a specific folder structure, where each class has its own folder containing images. Dataset Structure Before diving into code examples, let's understand the required folder structure for using ImageFolder : data/ ├── train/ | ├── class_1/ | | ├── image_1.jpg | | └── image_2.jpg | ├── class_2/ | | ├── image_3.jpg | | └── image_4.jpg | └── ... ├── val/ | ├── class_1/ | | ├── image_5.jpg | | └── image_6.jpg | ├── class_2/ | | ├── image_7.jpg | | └── image_8.jpg | └── ... In this example, the images are categorized into classes, and the train and validation sets are organized in separate folders. Code Exampl...