動作環境
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 16.04 LTS desktop amd64
TensorFlow v1.1.0
cuDNN v5.1 for Linux
CUDA v8.0
Python 3.5.2
IPython 6.0.0 -- An enhanced Interactive Python.
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
関連: TensorFlow > 複数のTFRecordsファイルを1つにまとめる v0.1,v0.2
概要
This article is related to ADDA (light scattering simulator based on the discrete dipole approximation).
- TFRecordsを読込んで学習する
- input: 5 nodes
- output: 6 nodes
- サンプル数: 223,872
- 学習データ: ADDAにより計算した値
- #input
- x,y,z: dipole position
- refractive index: real and imaginary part
- #output
- initial values for linear equation solution for (x,y,z),(real,imaginary)
5次元の補間関数をTensorFlowを用いて学習させようとしている。
TensorFlow | ADDA > 線形方程式の初期値用データの学習 (TFRecords版) > 出力層を1ノードにした場合のlossの経過 | データの正規化が必要?
で確認したところ、出力層の一つのパラメータの範囲が適正ではないため、「データの標準化」が必要になりそうだ。
EXR, EXI, EYR, EYI, EZR, EZIに関してそれぞれ(mean, stddev)を計算してみる。
code
読込みファイル: combined_IntField-Y_170722.tfrecords
calc_mean_std_170812.py
import numpy as np
import tensorflow as tf
import sys
"""
v0.1 Aug. 12, 2017
- calculate [mean], [stddev]
=== branched from [test_readCombined_170722.py] ===
v0.2 Jul. 09, 2017
- read [mr] and [mi]
v0.1 Jul. 09, 2017
- read position and Ex, Ey, Ez
+ add get_feature_float32()
"""
# on
# Ubuntu 16.04 LTS
# TensorFlow v1.1
# Python 3.5.2
# codingrule: PEP8
def print_mean_stddev(xs, label):
print('%s mean:%f std:%f' % (label, xs.mean(), xs.std()))
def get_feature_float32(example, feature_name):
wrk_raw = (example.features.feature[feature_name]
.bytes_list
.value[0])
wrk_1d = np.fromstring(wrk_raw, dtype=np.float32)
wrk_org = wrk_1d.reshape([1, -1])
return wrk_org
INP_FILE = 'combined_IntField-Y_170722.tfrecords'
record_iterator = tf.python_io.tf_record_iterator(path=INP_FILE)
exrs, exis = np.array([]), np.array([])
eyrs, eyis = np.array([]), np.array([])
ezrs, ezis = np.array([]), np.array([])
for record in record_iterator:
example = tf.train.Example()
example.ParseFromString(record)
xpos_org = get_feature_float32(example, 'xpos_raw')
ypos_org = get_feature_float32(example, 'ypos_raw')
zpos_org = get_feature_float32(example, 'zpos_raw')
mr_org = get_feature_float32(example, 'mr_raw')
mi_org = get_feature_float32(example, 'mi_raw')
exr_org = get_feature_float32(example, 'exr_raw')
exi_org = get_feature_float32(example, 'exi_raw')
eyr_org = get_feature_float32(example, 'eyr_raw')
eyi_org = get_feature_float32(example, 'eyi_raw')
ezr_org = get_feature_float32(example, 'ezr_raw')
ezi_org = get_feature_float32(example, 'ezi_raw')
exrs, exis = np.append(exrs, exr_org), np.append(exis, exi_org)
eyrs, eyis = np.append(eyrs, eyr_org), np.append(eyis, eyi_org)
ezrs, ezis = np.append(ezrs, ezr_org), np.append(ezis, ezi_org)
print_mean_stddev(exrs, 'exr')
print_mean_stddev(exis, 'exi')
print_mean_stddev(eyrs, 'eyr')
print_mean_stddev(eyis, 'eyi')
print_mean_stddev(ezrs, 'ezr')
print_mean_stddev(ezis, 'ezi')
$ python3 calc_mean_std_170812.py
exr mean:0.000000 std:0.108670
exi mean:0.000000 std:0.079414
eyr mean:-0.018333 std:0.704788
eyi mean:0.011257 std:0.579868
ezr mean:-0.000000 std:0.167189
ezi mean:0.000000 std:0.271590
これらの値を用いて、TensorFlowでの学習時にデータの正規化をしてみる。