tensorflow-datasets

Extract only a portion of a numpy array from tf.data

Extract only a portion of a numpy array from tf.data Question: I have a NumPy array of shape 500,36,24,72. Now I want to create a data pipeline for a problem using tf.data. For every iteration, only a subset of the array is required, for example, first the model is trained over [500,x:y,24,72], wherein only a …

Total answers: 1

Dataset.batch doesn't work as expected with a zipped dataset

Dataset.batch doesn't work as expected with a zipped dataset Question: I have a dataset like this: a = tf.data.Dataset.range(1, 16) b = tf.data.Dataset.range(16, 32) zipped = tf.data.Dataset.zip((a, b)) list(zipped.as_numpy_iterator()) # output: [(0, 16), (1, 17), (2, 18), (3, 19), (4, 20), (5, 21), (6, 22), (7, 23), (8, 24), (9, 25), (10, 26), (11, 27), …

Total answers: 2

tf.data.Dataset does not fetch images from file path using function map

tf.data.Dataset does not fetch images from file path using function map Question: Tensorflow throws an error if I use tf.data.Dataset and .map to retrieve images from a file path. Reproducible example on Google colab below. I have also attached notebook if anyone wants (you’d have to copy to your drive) import tensorflow as tf import …

Total answers: 1

filter dataset by label in tensorflow

filter dataset by label in tensorflow Question: I’m new to tensorflow (and python in general) and I’m having hard time wrapping my head around so features of tensors. I am usings tf.keras.utils.image_dataset_from_directory() to get a dataset of images and labels(classes). I want to filter the imgaes by the class, using filter(). Something like, full_ds = …

Total answers: 1

cannot fit the model using data loaded from tfds ImageFolder

cannot fit the model using data loaded from tfds ImageFolder Question: I am trying to use VGG16 in a model but I got an error when calling fit. ValueError: Input 0 of layer "sequential_1" is incompatible with the layer: expected shape=(None, 363, 360, 3), found shape=(363, 360, 3) I am using tfds to load images …

Total answers: 1

Input 0 is incompatible with layer model_2

Input 0 is incompatible with layer model_2 Question: i have a generator rev_generator that yields a tuple of two elements (numpyarray of shape (1279,300,1) , int value: 0 or 1) then i pass it to: train_ds = tf.data.Dataset.from_generator(rev_generator, output_signature=(tf.TensorSpec(shape=(1279,300,1),dtype=tf.float32), tf.TensorSpec(shape=(), dtype=tf.int32))) and then a simple model inputs=tf.keras.Input(shape=(1279,300,1,)) x=tf.keras.layers.Conv2D(16, 3, padding=’same’, activation=’relu’)(inputs) x=tf.keras.layers.MaxPooling2D()(x) x=tf.keras.layers.Flatten()(x) x=tf.keras.layers.Dense(64, activation=’relu’)(x) …

Total answers: 1

How to train on a tensorflow_datasets dataset

How to train on a tensorflow_datasets dataset Question: I’m playing around with tensorflow to become a bit more familiar with the overall workflow. To do this I thought I should start with creating a simple classifier for the well known Iris dataset. I load the dataset using: ds = tfds.load(‘iris’, split=’train’, shuffle_files=True, as_supervised=True) I use …

Total answers: 1

Convert folder of images with labels in CSV file into a tensorflow Dataset

Convert folder of images with labels in CSV file into a tensorflow Dataset Question: This clothing dataset (from Kaggle) when downloaded looks something like the below: Labels inside a .csv file Images in a subdirectory +-dataset/ | +-images.csv | +-images/ | +-d7ed1d64-2c65-427f-9ae4-eb4aaa3e2389.jpg | +-5c1b7a77-1fa3-4af8-9722-cd38e45d89da.jpg | +-… <additional files> I would like to load this into …

Total answers: 2

Using tf.keras.utils.image_dataset_from_directory with label list

Using tf.keras.utils.image_dataset_from_directory with label list Question: I have list of labels corresponding numbers of files in directory example: [1,2,3] train_ds = tf.keras.utils.image_dataset_from_directory( train_path, label_mode=’int’, labels = train_labels, # validation_split=0.2, # subset="training", shuffle=False, seed=123, image_size=(img_height, img_width), batch_size=batch_size) I get error: ValueError: Expected the lengths of `labels` to match the number of files in the target directory. …

Total answers: 2