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

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

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

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

2102閲覧

データの共分散行列には影響しないとは?

退会済みユーザー

退会済みユーザー

総合スコア0

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2017/04/26 01:03

データの共分散行列には影響しないとはどのような意味なのでしょうか?
TensorFlowの本を読んで勉強しています。
訓練データを加工する、という章の、白色化のインデックスを読んでいるのですが、
その内容の中に、
TensorFlowの白色化は、個別の画像に対する平均値除去のみで、データの共分散行列には影響しない
という文章が出てきました。ここでいう、”データの共分散行列”とはどのような意味なのでしょうか?(共分散行列を調べてもよくわからず...分散(散らばり具合を表す指標)の概念を多次元確率変数に拡張して行列としたもの...?http://mathtrain.jp/varcovmatrix )
コード全体は以下のようです。

# coding: UTF-8 from __future__ import absolute_import from __future__ import division from __future__ import print_function import os import time import tensorflow as tf import model as model import numpy as np from reader import Cifar10Reader FLAGS = tf.app.flags.FLAGS tf.app.flags.DEFINE_integer('epoch', 30, "訓練するEpoch数") tf.app.flags.DEFINE_string('data_dir', './cifar-10-batches-bin 2/', "訓練データのディレクトリ") tf.app.flags.DEFINE_string('checkpoint_dir', './checkpoints/', "チェックポイントを保存するディレクトリ") tf.app.flags.DEFINE_string('test_data', None, "テストデータのパス") tf.app.flags.DEFINE_string('graph_dir','./graphs',"グラフを保存するディレクトリ") def _export_graph(sess,epoch): constant_graph_def = graph_util.convert_variables_to_constants( sess,sess.graph_def,["output/logits"] ) file_path = os.path.join(FLAGS.graph_dir,'graph_%02d_epoch.pb'%epoch) with gfile.FastGFile(file_path,'wb') as f: f.write(constant_graph_def.SerializaToString()) with tf.gfile.FastGFile(graph_file,'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) _= tf.import_graph_def(graph_def,name='') def _restore(saver,sess): checkpoint = tf.train.get_checkpoint_state(FLAGS.checkpoint_dir) if checkpoint and checkpoint.model_checkpoint_path: saver.restore(sess,checkpoint.model_checkpoint_path) def _loss(logits, label): labels = tf.cast(label, tf.int64) cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits( logits=logits, labels=labels,name='cross_entropy_per_example') cross_entropy_mean = tf.reduce_mean(cross_entropy, name='cross_entropy') return cross_entropy_mean def _train(total_loss, global_step): opt = tf.train.GradientDescentOptimizer(learning_rate=0.001) grads = opt.compute_gradients(total_loss) train_op = opt.apply_gradients(grads, global_step=global_step) return train_op filenames = [ os.path.join( FLAGS.data_dir, 'data_batch_%d.bin' % i) for i in range(1, 6) ] def main(argv=None): global_step = tf.Variable(0,trainable=False) train_placeholder = tf.placeholder(tf.float32, shape=[32, 32, 3], name='train_image') label_placeholder = tf.placeholder(tf.int32,shape=[1],name='label') distorted_image = _distort(train_placeholder) #eval用のエントリポイント input_image = tf.placeholder_with_default(distorted_image,[32,32,3],name="input_image") whiten_image = tf.image.per_image_whitening(input_image) # (width, height, depth) -> (batch, width, height, depth) image_node = tf.expand_dims(whiten_image, 0) logits = model.inference(image_node) total_loss = _loss(logits,label_placeholder) train_op = _train(total_loss,global_step) top_k_op = tf.nn.in_top_k(logits,label_placeholder,1) saver = tf.train.Saver(tf.all_variable()) with tf.Session() as sess: sess.run(tf.initialize_all_variables()) total_duration = 0 for epoch in range(1, FLAGS.epoch + 1): start_time = time.time() for file_index in range(5): print('Epoch %d: %s' % (epoch, filenames[file_index])) reader = Cifar10Reader(filenames[file_index]) for index in range(10000): image = reader.read(index) logits_value = sess.run([logits], feed_dict={ train_placeholder: image.byte_array }) _,loss_value = sess.run([train_op,total_loss], feed_dict={ train_placeholder: image.byte_array, label_placeholder: image.label } ) if index % 1000 == 0: print('[%d]: %r' % (image.label, logits_value)) assert not np.isnan(loss_value), \ 'Model diverged with loss = NaN' reader.close() duration = time.time() - start_time total_duration += duration prediction = _eval(sess,top_k_op,train_placeholder,label_placeholder) print('epoch %d duration = %d sec' % (epoch, duration)) tf.train.SummaryWriter(FLAGS.checkpoint_dir, sess.graph) saver.save(sess,FLAGS.checkpoint_dir,global_step=epoch) print('Total duration = %d sec' % total_duration) def _eval(sess,top_k_op,train_placeholder,label_placeholder): if not FLAGS.test_data: return np.nan image_reader = Cifar10Reader(FLAGS.test_data) true_count = 0 for index in range(10000): image = image_reader.read(index) predictions = sess.run([top_k_op], feed_dict={ 'input_image:0': image.byte_array, label_placeholder:image.label } ) true_count += np.sum(predictions) image_reader.close() if __name__ == '__main__': tf.app.run()

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

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

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

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

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

guest

回答1

0

ベストアンサー

質問者さんはwikipediaなどに記載されている共分散行列の解説をお読みなのだろうと思いました。自分には共分散行列の意味やその応用については暗く(というより知らないw;)その点は質問者さんと近い立場なのですが・・・

wikipediaに載っている式をみると「各要素i,jの計算式は確率変数Xi,Xjの共分散でありi==jならXiの分散である」ことはうかがえます。なので、「個別の画像に対する平均値除去」が意味することが「画像全体の明度の平均値を各ピクセルから差し引いた画像にする」あるいはそれに近いことなのだろうと想像すると、「画像全体での明度の平均値は下がるが、共分散行列は変わらない=各ピクセル間の相関に変化はない」といえると思います。

投稿2017/04/26 06:09

KSwordOfHaste

総合スコア18394

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問