简体   繁体   English

如何插入 mnist 数字集的数据?

[英]How to interpolate data of mnist digits set?

I want to reshape the MNIST digits dataset from (28, 28) to (32, 32).我想将 MNIST 数字数据集从 (28, 28) 重塑为 (32, 32)。 One way is to interpolate the data.一种方法是插入数据。 I use custom Radial Basis Function for interpolation.我使用自定义径向基函数进行插值。 How to do it??怎么做??

Here is the RBF function这是 RBF 函数

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

where x is the actual value, c is the centre(assumed as mean) and s is standard deviation.其中 x 是实际值,c 是中心(假设为平均值),s 是标准偏差。

Here is how I load the data from tensorflow这是我从 tensorflow 加载数据的方法

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

You can use, tf.image.resize_with_pad which resizes the image to a target width and height by keeping the aspect ration the same without distortion.您可以使用tf.image.resize_with_pad通过保持纵横比不变而将图像调整为目标宽度和高度。

Below is the code for the same.下面是相同的代码。

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)) 

Original Image:原图:

在此处输入图片说明

Resized Image:调整大小的图像:

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

在此处输入图片说明

You can see the scale range in both the images and the aspect ratio is also maintained.您可以看到图像中的比例范围和纵横比也保持不变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM