Jupyter + Matplotlib > ADDA | TensorFlow TFRecordsファイル(IntField-Y)の描画 + 所感


動作環境
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)

関連: ADDA | TensorFlow > TFRecordsへのIntField-Y格納と試し読み v0.2 > 5次元のinput node: [mr], [mi]追加

上記において作成したIntField-Y_170709.tfrecordsを読込んでJupyterで表示する。

code v0.1

ベースcode: TensorFlow / ADDA > 線形方程式の初期値用データの学習 > 結果確認コード:v0.2, v0.3

display_TFRecords_IntField_170709.ipynb
import numpy as np
import tensorflow as tf
import math
import sys
import matplotlib.pyplot as plt
import matplotlib.cm as cm

"""
v0.1 Jul. 09, 2017
  - read from TFRecords format
     - add get_group_features()
     - add get_feature_float32()
=== branched from [check_resultmap_170429.py: v0.3] ===
"""

# on
#   Ubuntu 16.04 LTS
#   TensorFlow v1.1
#   Python 3.5.2
#   IPython 6.0.0 -- An enhanced Interactive Python.


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


def get_group_features(example):
    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')

    pos = xpos_org[0], ypos_org[0], zpos_org[0]
    ex = exr_org[0], exi_org[0]
    ey = eyr_org[0], eyi_org[0]
    ez = ezr_org[0], ezi_org[0]
    return pos + ex + ey + ez


class TARGET_IDX:
    EXR, EXI = 3, 4  # real and imaginary part of Ex
    EYR, EYI = 5, 6
    EZR, EZI = 7, 8

# parameters
SIZE_MAP_X = 30  # size of the image
SIZE_MAP_Y = 30
ZOOM_X = 15.0  #
ZOOM_Y = 15.0
SHIFT_X = 15.0  # to shift the center position
SHIFT_Y = 15.0
rmap = [[0.0 for yi in range(SIZE_MAP_Y)] for xi in range(SIZE_MAP_X)]

# targetIdx = TARGET_IDX.EXR


INP_FILE = 'IntField-Y_170709.tfrecords'

pickUpZvalue = 0.23621  # arbitrary selected

atargetIdx = TARGET_IDX.EZR  # [set this]

record_iterator = tf.python_io.tf_record_iterator(path=INP_FILE)
for record in record_iterator:
    example = tf.train.Example()
    example.ParseFromString(record)

    tpl = get_group_features(example)

    xpos_val = tpl[0]
    ypos_val = tpl[1]
    zpos_val = tpl[2]
    ax, ay, az = *xpos_val, *ypos_val, *zpos_val
    aTarget = tpl[atargetIdx]

    if abs(az - pickUpZvalue) < 1e-7:  # sys.float_info.epsilon:
        continue

    xidx = (SIZE_MAP_X * ax / ZOOM_X + SHIFT_X).astype(int)
    yidx = (SIZE_MAP_Y * ay / ZOOM_Y + SHIFT_Y).astype(int)

    if xidx < 0 or xidx >= SIZE_MAP_X:
        continue
    if yidx < 0 or yidx >= SIZE_MAP_Y:
        continue

    rmap[xidx][yidx] = aTarget  # overwrite

# draw map
wrkarr = np.array(rmap)
figmap = np.reshape(wrkarr, (SIZE_MAP_X, SIZE_MAP_Y))
plt.imshow(figmap, extent=(0, SIZE_MAP_X, 0, SIZE_MAP_Y), cmap=cm.jet)
plt.colorbar()
plt.show()

TODO

ファイル読込みしながらマップ展開するため、pickUpZvalueを自動計算できない。

優先度は高くないので固定値使用にしておく。

所感

2017/07/09

Coarse計算, Fine計算

  • dipole数を少なめでADDA計算を実施
  • 結果をDeep Learning
  • Predictionから初期値を取得, dipole数を多くしたADDA計算を実施

このシナリオなら計算を効率化できるだろうか。

5次元補間完了してからのネタ。