【问题标题】:How to interpolate data of mnist digits set?如何插入 mnist 数字集的数据?
【发布时间】:2021-01-18 04:46:23
【问题描述】:

我想将 MNIST 数字数据集从 (28, 28) 重塑为 (32, 32)。一种方法是对数据进行插值。我使用自定义径向基函数进行插值。怎么办??

这是RBF函数

def RBF(x, c, s):
return np.exp(-np.sum((x-c)**2, axis=1)/(2*s**2))

其中 x 是实际值,c 是中心(假设为均值),s 是标准差。

这是我从 tensorflow 加载数据的方式

import tensorflow as tf
data = tf.contrib.learn.datasets.mnist.load_mnist()

【问题讨论】:

    标签: python tensorflow scipy mnist


    【解决方案1】:

    您可以使用tf.image.resize_with_pad,通过保持纵横比不变而不失真,将图像大小调整为目标宽度和高度。

    下面是相同的代码。

    import tensorflow as tf
    from matplotlib import pyplot as plt
    (x_train, y_train), (x_test, y_test) =tf.keras.datasets.mnist.load_data(path='mnist.npz')
    
    original_image = x_train[0].reshape(28,28,1)
    resized_image = tf.image.resize_with_pad(original_image, 32,32) 
    
    plt.imshow(original_image.reshape(28,28)) 
    

    原图:

    调整大小的图片:

    plt.imshow(resized_image.numpy().reshape(32,32))
    

    您可以在两个图像中看到比例范围,并且纵横比也保持不变。

    【讨论】:

      猜你喜欢
      • 2019-11-06
      • 2018-08-11
      • 1970-01-01
      • 2020-11-14
      • 2017-04-03
      • 1970-01-01
      • 1970-01-01
      • 2018-09-27
      • 2014-12-02
      相关资源
      最近更新 更多