![](/img/trans.png)
[英]How to interpolate temperature from a set of data using metpy.interpolate
[英]How to interpolate data of mnist digits set?
我想將 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()
您可以使用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))
您可以看到圖像中的比例范圍和縱橫比也保持不變。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.