0
嘿,大家好,我一直在做一個tensorflow項目,我想從MNIST數據庫的測試圖像中拿走。下面是我的代碼原始數據(UBYTE?)轉換成2D numpy的要點:如何生成適當的MNIST圖像?
from PIL import Image
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data', one_hot = True)
def gen_image(arr):
two_d = np.reshape(arr, (28, 28))
img = Image.fromarray(two_d, 'L')
return img
batch_xs, batch_ys = mnist.test.next_batch(1)
gen_image(batch_xs[0]).show()
然而,當IMG獲得展示here,它看上去一點也不像一個正常的數字,所以我想我一定是搞砸了某處,但除了當[numpy array]從[784]重構爲[28,28]時無法查明它。任何線索?
編輯:由255
的可能的複製[TensorFlow - 顯示從數據集MNIST圖像](http://stackoverflow.com/questions/38308378/tensorflow-show-image-from-mnist-dataset) –
我閱讀這篇文章,但它並沒有真正解釋我的圖像看起來不像一個數字? – dzeng
嗯,很明顯,如果我使用matplotlib而不是PIL,圖像將顯示正確...我不知道爲什麼。無論如何,我會使用matplotlib爲momen – dzeng