動作環境
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)
概要
This article is related to ADDA (light scattering simulator based on the discrete dipole approximation).
ADDA | TensorFlow > TFRecordsへのIntField-Y格納と試し読み v0.2 > 5次元のinput node: [mr], [mi]追加
にて作成したPythonスクリプトを実際にTFRecords化したいディレクトリに対して実行するためのbashスクリプトを作成した。
ディレクトリ内構成
(追記 2017/07/29)
以下のスクリプトで計算したADDAの結果を含んでいる。
run_adda_170701.py
import subprocess as sb
# on Python 3.5.2
# codingrule: PEP8
RUN_PARAM = "-store_int_field -grid 26"
# RUN_PARAM = "-store_int_field" # for test
# real part of refractive index
mrs = 1.33, 1.4, 1.45, 1.5
# imaginary part of refractive index
mis = 0.0001, 0.001, 0.01, 0.03, 0.05, 0.1
for amr in mrs:
for ami in mis:
cmd = "./adda -m %f %f %s" % (amr, ami, RUN_PARAM)
print(cmd)
sb.run(cmd.split(), stdout=sb.DEVNULL)
$ ls ../run376_sphere_g26_m1.5/
CrossSec-Y IntField-Y log mueller
ADDAによる計算直後は上記のファイルがある。
- IntField-Y: 対象とするデータが入ったファイル
- log: refractive indexの情報を含むログファイル
対象ディレクトリ
$ ls ../run3
run353_sphere_g26_m1.33/ run358_sphere_g26_m1.33/ run363_sphere_g26_m1.4/ run368_sphere_g26_m1.45/ run373_sphere_g26_m1.5/
run354_sphere_g26_m1.33/ run359_sphere_g26_m1.4/ run364_sphere_g26_m1.4/ run369_sphere_g26_m1.45/ run374_sphere_g26_m1.5/
run355_sphere_g26_m1.33/ run360_sphere_g26_m1.4/ run365_sphere_g26_m1.45/ run370_sphere_g26_m1.45/ run375_sphere_g26_m1.5/
run356_sphere_g26_m1.33/ run361_sphere_g26_m1.4/ run366_sphere_g26_m1.45/ run371_sphere_g26_m1.5/ run376_sphere_g26_m1.5/
run357_sphere_g26_m1.33/ run362_sphere_g26_m1.4/ run367_sphere_g26_m1.45/ run372_sphere_g26_m1.5/
処理の概要
- 各ディレクトリに対して対象ファイルのシンボリックリンクを貼る
- logからrefractive indexの情報を取得
- IntField-YをTFRecordsファイルに変換
- 結果ファイルを対象ディレクトリにコピーする
code
group_run_toTfrecords_170722_exec
#!/usr/bin/env bash
# v0.1 Jul. 22, 2017
# - process using [toTFRecords_InitFieldY_170709.py]
# - add get_imaginary_m()
# - add get_real_m()
# - add get_refractive_index()
# - process for all the directories with names starting with [../run]
#
#-----
# Settings and functions
LIST_FILE="LIST.170722"
LOG_ADDA_FILE="log" # input
LOG_TFR_FILE="log.toTFRecords" #output
get_refractive_index () {
#arg : e.g. "refractive index 1.33+0.0i"
echo $@ | awk '{print $3}' | tr "+i" " "
}
get_real_m () {
#arg : e.g. "refractive index 1.33+0.0i"
echo $(get_refractive_index $@) | awk '{print $1}'
}
get_imaginary_m () {
#arg : e.g. "refractive index 1.33+0.0i"
echo $(get_refractive_index $@) | awk '{print $2}'
}
#-----
# Main
ls -d ../run* > $LIST_FILE
len=$(wc $LIST_FILE | awk '{print $1}')
trap exit SIGINT # to exit for Ctrl+c
for idx in $(seq 1 $len);do
trgtdir=$(head -n $idx $LIST_FILE | tail -n 1) # target directory
echo -n "$trgtdir - "
refidx=$(grep refractive $trgtdir/$LOG_ADDA_FILE) #refractive index string
realm=$(get_real_m $refidx) # real part of refractive index
imagm=$(get_imaginary_m $refidx) # imaginary part of refractive index
echo $realm $imagm
#
ln -fs $trgtdir/IntField-Y .
#ls -l IntField-Y # for debug
python3 toTFRecords_InitFieldY_170709.py --mr $realm --mi $imagm > $LOG_TFR_FILE
#
mv IntField-Y_170709.tfrecords $trgtdir
mv $LOG_TFR_FILE $trgtdir
done
実行
$ bash group_run_toTfrecords_170722_exec
../run353_sphere_g26_m1.33 - 1.33 0.0001
../run354_sphere_g26_m1.33 - 1.33 0.001
../run355_sphere_g26_m1.33 - 1.33 0.01
../run356_sphere_g26_m1.33 - 1.33 0.03
../run357_sphere_g26_m1.33 - 1.33 0.05
../run358_sphere_g26_m1.33 - 1.33 0.1
../run359_sphere_g26_m1.4 - 1.4 0.0001
../run360_sphere_g26_m1.4 - 1.4 0.001
../run361_sphere_g26_m1.4 - 1.4 0.01
../run362_sphere_g26_m1.4 - 1.4 0.03
../run363_sphere_g26_m1.4 - 1.4 0.05
../run364_sphere_g26_m1.4 - 1.4 0.1
../run365_sphere_g26_m1.45 - 1.45 0.0001
../run366_sphere_g26_m1.45 - 1.45 0.001
../run367_sphere_g26_m1.45 - 1.45 0.01
../run368_sphere_g26_m1.45 - 1.45 0.03
../run369_sphere_g26_m1.45 - 1.45 0.05
../run370_sphere_g26_m1.45 - 1.45 0.1
../run371_sphere_g26_m1.5 - 1.5 0.0001
../run372_sphere_g26_m1.5 - 1.5 0.001
../run373_sphere_g26_m1.5 - 1.5 0.01
../run374_sphere_g26_m1.5 - 1.5 0.03
../run375_sphere_g26_m1.5 - 1.5 0.05
../run376_sphere_g26_m1.5 - 1.5 0.1
$ ls ../run353_sphere_g26_m1.33/
CrossSec-Y IntField-Y IntField-Y_170709.tfrecords log log.toTFRecords mueller
各ディレクトリにおいて2つのファイル(IntField-Y_170709.tfrecords, log.toTFRecords)が追加された。