[英]How can I explore and modify the created dataset from tf.keras.preprocessing.image_dataset_from_directory()?
[英]Changing label_mode of tf.keras.preprocessing.image_dataset_from_directory after setting it once
我正在使用此代码加载必须传递给卷积变分自动编码器的图像:
import tensorflow as tf
train = tf.keras.preprocessing.image_dataset_from_directory(
data_dir + 'Train/', label_mode=None,
image_size=(img_height, img_width),
batch_size=batch_size)
为了能够将其传递给自动编码器,我必须设置label_mode = None
。 此外,在解码器接收到的图像将进一步传递到 CNN 进行分类,我需要标签。
当最初的label_mode=None
时,我怎样才能让train
稍后也为 CNN 返回标签。
您可以加载带有标签的图像,然后创建另一个没有标签的数据集。
import tensorflow as tf
train = tf.keras.preprocessing.image_dataset_from_directory(
data_dir + 'Train/', label_mode='categorical',
image_size=(img_height, img_width),
batch_size=batch_size)
X = np.array([])
for x, y in testData:
if X.size == 0:
X = x.numpy()
continue
X = np.concatenate([X, x.numpy()])
dataset = tf.data.Dataset.from_tensor_slices(X)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.