【问题标题】:Add a row to mnist images dataset向 mnist 图像数据集添加一行
【发布时间】:2021-10-05 00:24:10
【问题描述】:

我必须向 mnist 图像数据集添加一行,该数据集被批处理为 32 个样本。代码如下:

(mnist_images, mnist_labels), _ = tf.keras.datasets.mnist.load_data()
dataset = tf.data.Dataset.from_tensor_slices(
(tf.cast(mnist_images[...,tf.newaxis]/255, tf.float32),
 tf.cast(mnist_labels,tf.int64)))
 dataset = dataset.shuffle(1000).batch(32)

for images,labels in dataset.take(1):
   print("Logits: ", mnist_model(images[0:1]).numpy())

b =tf.reshape(images, [784,32], tf.float32)
c = tf.concat(b,tf.ones([1,32], tf.float32),0)

我收到以下错误,但都是 dtype float 32,

ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: <tf.Tensor: 
shape=(1, 32), dtype=float32, numpy= array([[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,1., 1., 1., 1.,
    1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]],
  dtype=float32)>

还有其他方法可以在图像张量中添加一行吗?

【问题讨论】:

    标签: tensorflow mnist


    【解决方案1】:

    您似乎刚刚忘记使用括号 - [ ] 。

    使用:

    c = tf.concat([b,tf.ones([1,32], tf.float32)],0)
    

    而不是:

    c = tf.concat(b,tf.ones([1,32], tf.float32),0)
    

    【讨论】:

      猜你喜欢
      • 2017-01-10
      • 2016-10-23
      • 1970-01-01
      • 2018-08-06
      • 1970-01-01
      • 2011-03-08
      • 1970-01-01
      • 2020-02-09
      • 2017-12-29
      相关资源
      最近更新 更多