tensorflow-datasets

Shapes for training data and labels

Shapes for training data and labels Question: I am trying to train a convolutional neural network using Conv1D and sparse_categorical_crossentropy as a loss function but I keep having problems related to the shapes of the data. Here is the network: model=models.Sequential() model=tf.keras.models.Sequential([ tf.keras.layers.Conv1D(16, 24, input_shape=(1000, 4), activation="relu"), tf.keras.layers.MaxPooling1D(pool_size=24, strides=24), tf.keras.layers.Conv1D(8, 8, activation="relu"), tf.keras.layers.MaxPooling1D(pool_size=8, strides=8), tf.keras.layers.Flatten(), …

Total answers: 1

Which metrics are printed (train or validation) when validation_split and validation_data is not specified in the keras model.fit function?

Which metrics are printed (train or validation) when validation_split and validation_data is not specified in the keras model.fit function? Question: I have a TF neural network and I am using the tf.data API to create the dataset using a generator. I am not passing validation_split and validation_data into the model.fit() function of keras. The default …

Total answers: 1

How to split data into x_train and y_train

How to split data into x_train and y_train Question: I’m trying to access EMNIST data from here: https://www.tensorflow.org/datasets/splits with this code: train_ds, test_ds = tfds.load(’emnist’, split=[‘train’, ‘test’], shuffle_files=True) I tried doing this: x_train = train_ds[‘image’] y_train = train_ds[‘label’] x_test = test_ds[‘image’] y_test = test_ds[‘label’] But I get the error TypeError: ‘PrefetchDataset’ object is not subscriptable …

Total answers: 2

Merging two tensorflow Datasets, albeit at a different pace

Merging two tensorflow Datasets, albeit at a different pace Question: I am looking for a way to merge a Dataset with another, but by drawing samples from it only occasionally. For example, given these two Datasets ds1 = tf.data.Dataset.range(1, 10).repeat() ds10 = tf.data.Dataset.range(10, 100, 10).repeat() I would like to add samples from ds10 to those …

Total answers: 2

Apply preprocessing only to images , not to masks

Apply preprocessing only to images , not to masks Question: I have a dataset which has images and masks. images_p = tf.keras.utils.image_dataset_from_directory( path_imgs, batch_size=None, shuffle=False, label_mode=None) masks_p = tf.keras.utils.image_dataset_from_directory( path_masks, batch_size=None, shuffle=False, label_mode=None, color_mode=’grayscale’) dataset = tf.data.Dataset.zip((images_p, masks_p)) Now, I want to apply some preprocessing. But, it will be different for images and masks. For …

Total answers: 1

How to Save a Tensorflow Dataset

How to Save a Tensorflow Dataset Question: As the title says I’m trying to save a TensorSliceDataset object to file. Viewing tensorflow’s website it seems that the tf.data.Dataset class has a save function but it is not implemented for TensorSliceDataset objects. Pickling also did not work for me. Example code import tensorflow as tf t …

Total answers: 3

create tensorflow dataset from list_files

create tensorflow dataset from list_files Question: I am trying to create tensroflow dataset : path_imgs = (‘./images/train/*.jpg’) path_masks =(‘./masks/train/*.jpg’ images = tf.data.Dataset.list_files(path_imgs, shuffle=False) masks = tf.data.Dataset.list_files(path_masks, shuffle=False) dataset = tf.data.Dataset.from_tensor_slices((tf.constant(path_imgs), tf.constant(path_masks))) and I am receiving: Unbatching a tensor is only supported for rank >= 1 Asked By: George || Source Answers: Try something like this: …

Total answers: 1

How do you convert the pandas DataFrame to tensorflow.python.data.ops.dataset_ops.PrefetchDataset

How do you convert the pandas DataFrame to tensorflow.python.data.ops.dataset_ops.PrefetchDataset Question: Given that I have the below Tensorflow Dataset: import tensorflow_datasets as tfds (raw_train_ds, raw_val_ds, raw_test_ds), info = tfds.load(‘ag_news_subset’, split=[‘train[:90%]’, ‘train[-90%:]’, ‘test’], with_info=True) The type of raw_train_ds is tensorflow.python.data.ops.dataset_ops.PrefetchDataset I need to apply the below remove_stop_words() method to the description features of the dataset, so i …

Total answers: 1

Tensorflow dataset pipeline with specific classes

Tensorflow dataset pipeline with specific classes Question: I would like to use a dataset pipeline with specific class indexes. For example: if I use CIFAR-10 Dataset. I can load the dataset as follows: (x_train, y_train), (x_test, y_test) = tf.keras.datasets.cifar10.load_data() Which load all the class labels (10 Classes). I can create a pipeline using the following …

Total answers: 1

Changes to Dataset in for loop don't work

Changes to Dataset in for loop don't work Question: I’m trying to augment my dataset by randomly changing the hue of its images within a for loop but the changes do not persist outside of the loop. I imported the dataset with tf.keras.utils.image_dataset_from_directory. The rest of the code looks as follows: def augment(image, label, counter): …

Total answers: 3