如何将cifar100图像数据集转换为(128,128,3)并将其传递给模型?
(x_train, y_train), (x_test, y_test)=tensworflow.keras.datasets.cifar100.load_data()我想转换上面的x_train, x_test。
x_train. shaping(50000,128,128,3)无效
func = lambda x : tf.image.resize(x , (128 , 128))
x_train = tf.py_function(func, [x_train], tf.float32)
print(x_train.shape)
输出:
(50000, 128, 128, 3)
上面的方法是一种缓慢而低效的方法,但是对于来说,是最佳性能试试这个
func = lambda x , y : (tf.image.resize(x , (128 , 128)), y)
train_examples = tf.data.Dataset.from_tensor_slices((x_train,y_train))
train_examples = train_examples.map(func, num_parallel_calls=tf.data.AUTOTUNE)
train_examples.take(1)
输出:
<TakeDataset element_spec=(TensorSpec(shape=(128, 128, 3), dtype=tf.float32, name=None), TensorSpec(shape=(1,), dtype=tf.uint8, name=None))>