tensorflow-datasets

Convert tfrecords to image

Convert tfrecords to image Question: I found a training dataset which is a set of tfrecords files,im trying to convert them into images but with no results,is it possible to convert them to images ? Asked By: jonah || Source Answers: To find out what is inside a tf.record use tf.data.TFRecordDataset and tf.train.Example: import tensorflow …

Total answers: 2

About tensorflow map function with ifelse statement

About tensorflow map function with ifelse statement Question: I would like to cut the image which are stored as tensorflow dataset to squared image. But it seems that the tensorflow could not allow the map function with ifelse statement. I hope to know whether I could solve this problem. Many thanks in advance. def tf_resize(img, …

Total answers: 2

Is it possible to split a tensorflow dataset into train, validation AND test datasets when using image_dataset_from_directory?

Is it possible to split a tensorflow dataset into train, validation AND test datasets when using image_dataset_from_directory? Question: I am using tf.keras.utils.image_dataset_from_directory to load a dataset of 4575 images. While this function allows to split the data into two subsets (with the validation_split parameter), I want to split it into training, testing, and validation subsets. …

Total answers: 2

How to attach or get filenames from MapDataset from image_dataset_from_directory() in Keras?

How to attach or get filenames from MapDataset from image_dataset_from_directory() in Keras? Question: I am training convolutional autoencoder and I have this code for loading data (images): train_ds = tf.keras.preprocessing.image_dataset_from_directory( ‘path/to/images’, image_size=image_size ) normalization_layer = layers.experimental.preprocessing.Rescaling(1./255) def adjust_inputs(images, labels): return normalization_layer(images), normalization_layer(images) normalized_train_ds = train_ds.map(adjust_inputs) As I don’t need class labels but images itself as …

Total answers: 3

Using Datasets from large numpy arrays in Tensorflow

Using Datasets from large numpy arrays in Tensorflow Question: I’m trying to load a dataset, stored in two .npy files (for features and ground truth) on my drive, and use it to train a neural network. print("loading features…") data = np.load("[…]/features.npy") print("loading labels…") labels = np.load("[…]/groundtruth.npy") / 255 dataset = tf.data.Dataset.from_tensor_slices((data, labels)) throws a tensorflow.python.framework.errors_impl.InternalError: …

Total answers: 2

Tensorflow – how to create a Dataset which is an array of tuples

Tensorflow – how to create a Dataset which is an array of tuples Question: Question Dataset can be a collection of tuples with different types. I can create a dataset from a tuple. tf.data.Dataset.from_tensors( ([1, 2, 3], ‘A’) ) —– <TensorDataset shapes: ((3,), ()), types: (tf.int32, tf.string)> How can I create a dataset from an …

Total answers: 1

U net Multiclass segmentation image input dataset error

U net Multiclass segmentation image input dataset error Question: I am trying to do multiclass segmentation with U-net. In the previous trials I tried the binary segmentation and it works. But when I try to do multiclass I am facing this error. ValueError: ‘generator yielded an element of shape (128,192,1) where an element of shape …

Total answers: 1

Loading grayscale pngs with image_dataset_from_directory returns a 3-channel tensor

Loading grayscale pngs with image_dataset_from_directory returns a 3-channel tensor Question: I have a set of grayscale png images split over 2 directories. I have used image_dataset_from_directory to load them as a Dataset object, as per documentation. When I use element_spec to inspect what has been loaded, it says the images have 3 channels: from tensorflow.keras.preprocessing …

Total answers: 1

How do you save a Tensorflow dataset to a file?

How do you save a Tensorflow dataset to a file? Question: There are at least two more questions like this on SO but not a single one has been answered. I have a dataset of the form: <TensorSliceDataset shapes: ((512,), (512,), (512,), ()), types: (tf.int32, tf.int32, tf.int32, tf.int32)> and another of the form: <BatchDataset shapes: …

Total answers: 6

How to print one example of a dataset from tf.data?

How to print one example of a dataset from tf.data? Question: I have a dataset in tf.data. How can I easily print (or grab) one element in my dataset? Similar to: print(dataset[0]) Asked By: Nicky Feller || Source Answers: In TF 1.x you can use the following. There are different iterators provided (some might be …

Total answers: 3