質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%

Q&A

解決済

1回答

1880閲覧

MNISTのデータをプログラム中で画像表示させたい

knght

総合スコア14

0グッド

0クリップ

投稿2018/06/25 08:51

tensorflowでmnistのデータをオートエンコーダに使い、
その出力結果を、元のデータと比べる際に画像として比べたいと思っています。

mnistのデータ、また、得られた結果の画像への変化、表示方法を教えていただけると嬉しいです。

https://gist.github.com/tomokishii/7ddde510edb1c4273438ba0663b26fc6
こちらのシンプルなオートエンコーダを参考にさせてもらっているのですが、

TensorFlow

1 # generate decoded image with test data 2 test_fd = {x: mnist.test.images, y_: mnist.test.labels} 3 decoded_imgs = decoded.eval(test_fd) 4 print('loss (test) = ', loss.eval(test_fd)) 5 6x_test = mnist.test.images 7 8n = 10 # how many digits we will display 9plt.figure(figsize=(20, 4)) 10for i in range(n): 11 # display original 12 ax = plt.subplot(2, n, i + 1) 13 plt.imshow(x_test[i].reshape(28, 28)) 14 plt.gray() 15 ax.get_xaxis().set_visible(False) 16 ax.get_yaxis().set_visible(False) 17 18 # display reconstruction 19 ax = plt.subplot(2, n, i + 1 + n) 20 plt.imshow(decoded_imgs[i].reshape(28, 28)) 21 plt.gray() 22 ax.get_xaxis().set_visible(False) 23 ax.get_yaxis().set_visible(False) 24 25plt.savefig('mnist_ae1.png') 26

最後のこちらの部分がどういう処理を行っているのか理解できません。。。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

質問は最後の部分のコードを理解したいということでしょうか?

python

1 # generate decoded image with test data 2 test_fd = {x: mnist.test.images, y_: mnist.test.labels} 3 decoded_imgs = decoded.eval(test_fd) 4 print('loss (test) = ', loss.eval(test_fd)) 5ここまででx_testをエンコーダに通した結果がdecoded_imgsに入ります。 6 7x_test = mnist.test.images 8もとの画像をx_testに。 9 10n = 10 # how many digits we will display 11うち何個画像を表示するのか。今は10枚。 12plt.figure(figsize=(20, 4)) 13for i in range(n): 14n枚の画像の元画像と変換後画像を書くためのループ文 15 # display original 16 ax = plt.subplot(2, n, i + 1) 17 plt.imshow(x_test[i].reshape(28, 28)) 18 plt.gray() 19 ax.get_xaxis().set_visible(False) 20 ax.get_yaxis().set_visible(False) 21もと画像を白黒で書いて、軸はなし。 22plt.subplotの引数の意味は、https://matplotlib.org/api/_as_gen/matplotlib.pyplot.subplot.html 23わからなかったら中身をいじってプロットしてみること。 24たまにドキュメントの行と列が逆の場合あり。 25場所指定 26http://bicycle1885.hatenablog.com/entry/2014/02/14/023734 27軸消し 28https://www.google.co.jp/amp/s/shocksolution.com/2011/08/17/removing-an-axis-or-both-axes-from-a-matplotlib-plot/amp/ 29 30 # display reconstruction 31 ax = plt.subplot(2, n, i + 1 + n) 32 plt.imshow(decoded_imgs[i].reshape(28, 28)) 33 plt.gray() 34 ax.get_xaxis().set_visible(False) 35 ax.get_yaxis().set_visible(False) 36変換後画像を白黒で書いて、軸はなし 37 38plt.savefig('mnist_ae1.png') 39文字列内の名前の画像ファイルとして保存

投稿2018/06/25 11:00

編集2018/06/25 11:01
mkgrei

総合スコア8560

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問