aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xextract.sh30
-rw-r--r--include/weights.c25
-rw-r--r--src/train5.py29
3 files changed, 50 insertions, 34 deletions
diff --git a/extract.sh b/extract.sh
index 7fc66a6..a359c61 100755
--- a/extract.sh
+++ b/extract.sh
@@ -5,8 +5,8 @@ db_file=games_anon.db
query() {
query="(size == $1) and (result != '1-0') and (result != '0-1') and (result != '0-0')"
selct=""
- for player in rabbitboy84 fwwwwibib archvenison Simmon AaaarghBot; do
- # for player in; do
+ # for player in rabbitboy84 fwwwwibib archvenison Simmon AaaarghBot; do
+ for player in; do
selct="$selct(player_black == '$player') or (player_white == '$player') or "
done;
if [ -n "$selct" ]; then
@@ -37,25 +37,27 @@ process() {
echo -en "Done.\n\tGenerating training data... "
./pptdb "$size" "data/smalltak-$size" generate
echo -en "\tShuffling $(wc -l data/training-$size.csv | cut -d\ -f1) samples... "
- head -n 1 "data/training-$size.csv" > "data/shuf-$size.csv"
- tail -n+2 "data/training-$size.csv" | shuf >> "data/shuf-$size.csv"
- mv "data/shuf-$size.csv" "data/training-$size.csv"
+ # head -n 1 "data/training-$size.csv" > "data/shuf-$size.csv"
+ # tail -n+2 "data/training-$size.csv" | shuf >> "data/shuf-$size.csv"
+ # mv "data/shuf-$size.csv" "data/training-$size.csv"
echo -en "Done.\n\tCompressing data... "
- if [ -f "data/training-$size.csv.gz" ]; then
- rm "data/training-$size.csv.gz"
+ # if [ -f "data/training-$size.csv.gz" ]; then
+ # rm "data/training-$size.csv.gz"
+ # fi
+ # gzip "data/training-$size.csv"
+ # echo "Done, available in data/training-$size.csv.gz"
+ if [ -f "data/validation-$size.csv.gz" ]; then
+ rm "data/validation-$size.csv.gz"
fi
- gzip "data/training-$size.csv"
- echo "Done, available in data/training-$size.csv.gz"
- # mv "data/training-$size.csv" "data/validation-$size.csv"
- # gzip "data/validation-$size.csv"
- # echo "Done, available in data/validation-$size.csv.gz"
+ mv "data/training-$size.csv" "data/validation-$size.csv"
+ gzip "data/validation-$size.csv"
+ echo "Done, available in data/validation-$size.csv.gz"
}
-
make pptdb
for size in 5 6; do
echo
extract $size notation,result
- process $size 300000
+ process $size 50000
done
diff --git a/include/weights.c b/include/weights.c
index c128ff7..9eeba07 100644
--- a/include/weights.c
+++ b/include/weights.c
@@ -1,7 +1,7 @@
#include "weights.h"
const float conv2d_weights[KERN_NUM][KERN_SIZE][KERN_SIZE][KERN_CHAN] =
- {{{{ 2.58312970e-01, -1.57649890e-02, -1.00786142e-01, 2.25934118e-01,
+{{{{ 2.58312970e-01, -1.57649890e-02, -1.00786142e-01, 2.25934118e-01,
2.03468144e-01, 3.16539735e-01, -3.03449720e-01, -9.03429747e-01},
{-7.94863030e-02, -1.58257172e-01, 3.72665450e-02, -2.03835458e-01,
-3.96497548e-01, -6.10545933e-01, 9.83448997e-02, -7.34975338e-01},
@@ -265,11 +265,11 @@ const float conv2d_weights[KERN_NUM][KERN_SIZE][KERN_SIZE][KERN_CHAN] =
5.70080839e-02, 2.49329448e-01, 4.34800774e-01, 1.90990448e-01}}}};
const float conv2d_biases[KERN_NUM] =
- {-0.5954203, -1.0255206, 0.7012269, 0.7169469, 0.20402987, 0.29087773,
- 0.5385397, 0.05127476, 0.65670264, -0.8095288, 0.57354295, -0.40450025};
+{-0.5954203, -1.0255206, 0.7012269, 0.7169469, 0.20402987, 0.29087773,
+ 0.5385397, 0.05127476, 0.65670264, -0.8095288, 0.57354295, -0.40450025};
const float dense1_weights[DENSE1_NUM][CONV_NUM+2] =
- {{-7.94511437e-01, 5.71200252e-01, -1.40879720e-01, 1.24253288e-01,
+{{-7.94511437e-01, 5.71200252e-01, -1.40879720e-01, 1.24253288e-01,
-5.10804355e-01, 5.07906437e-01, -1.88285959e+00, -7.12222338e-01,
-2.87340283e-01, 9.12622809e-01, -5.71415201e-02, 6.10791564e-01,
-6.00090921e-01, 3.95308174e-02, 5.66913188e-01, -6.05273545e-02,
@@ -523,11 +523,11 @@ const float dense1_weights[DENSE1_NUM][CONV_NUM+2] =
3.57535362e+00, 1.32344556e+00}};
const float dense1_biases[DENSE1_NUM] =
- { 0.4636547, 0.13360201, -0.9697346, -1.0855523, 1.0256653, 0.5478138,
- 0.7192499, 0.22356796, 1.3530691 };
+{ 0.4636547, 0.13360201, -0.9697346, -1.0855523, 1.0256653, 0.5478138,
+ 0.7192499, 0.22356796, 1.3530691, };
const float dense2_weights[DENSE2_NUM][DENSE1_NUM] =
- {{-0.07496518, -1.219598, -0.77743036, -0.5582114, 0.3379165, 0.38208017,
+{{-0.07496518, -1.219598, -0.77743036, -0.5582114, 0.3379165, 0.38208017,
0.7843754, 0.6464907, 0.4145456, },
{-1.2022296, -1.0770698, -0.28290233, 0.9415246, -0.0248992, -0.4531845,
-0.43938553, -0.99121296, 1.058052, },
@@ -547,11 +547,12 @@ const float dense2_weights[DENSE2_NUM][DENSE1_NUM] =
0.56897026, -1.0157181, -0.41018486}};
const float dense2_biases[DENSE2_NUM] =
- {-0.65758836, 0.11515713, -1.8776059, -0.5293117, -2.9236703, -0.8128398,
- 2.5789695, -1.0744314, 0.810859, };
+{-0.65758836, 0.11515713, -1.8776059, -0.5293117, -2.9236703, -0.8128398,
+ 2.5789695, -1.0744314, 0.810859, };
const float output_weights[DENSE2_NUM] =
- { 0.20715837, 0.4751412, 0.14602005, 0.24578023, -0.44211808, 0.22129269,
- -0.8266294, -0.22375038, -0.35583553};
+{ 0.20715837, 0.4751412, 0.14602005, 0.24578023, -0.44211808, 0.22129269,
+ -0.8266294, -0.22375038, -0.35583553};
-const float output_bias = -0.9296964;
+const float output_bias =
+-0.9296964;
diff --git a/src/train5.py b/src/train5.py
index adb81a5..71a8652 100644
--- a/src/train5.py
+++ b/src/train5.py
@@ -119,20 +119,33 @@ def write_weights(model):
string = re.sub(r'([0-9]+)\n', r'\1,\n', string)
string = re.sub(r'([0-9]+) ', r'\1, ', string)
return string
- f = open("weights.txt", "w")
+ # Prepare everything in a sane memory order
conv2d_weights = np.array(transpose(model.trainable_variables[0], perm=[3, 1, 0, 2]))
conv2d_biases = np.array(model.trainable_variables[1])
dense1_weights = np.array(transpose(model.trainable_variables[2], perm=[1, 0]))
dense1_biases = np.array(model.trainable_variables[3])
dense2_weights = np.array(transpose(model.trainable_variables[4], perm=[1, 0]))
dense2_biases = np.array(model.trainable_variables[5])
- output_weights = np.array(transpose(model.trainable_variables[6], perm=[1, 0]))
- output_biases = np.array(model.trainable_variables[7])
- for v in [conv2d_weights, conv2d_biases,
- dense1_weights, dense1_biases,
- dense2_weights, dense2_biases,
- output_weights, output_biases]:
- f.write(fix(str(v))+"\n\n")
+ output_weights = np.array(transpose(model.trainable_variables[6], perm=[1, 0])[0])
+ output_bias = np.array(model.trainable_variables[7][0])
+ # Prepare formatting
+ names = ["conv2d_weights[KERN_NUM][KERN_SIZE][KERN_SIZE][KERN_CHAN]",
+ "conv2d_biases[KERN_NUM]",
+ "dense1_weights[DENSE1_NUM][CONV_NUM+2]",
+ "dense1_biases[DENSE1_NUM]",
+ "dense2_weights[DENSE2_NUM][DENSE1_NUM]",
+ "dense2_biases[DENSE2_NUM]",
+ "output_weights[DENSE2_NUM]",
+ "output_bias"]
+ variables = [conv2d_weights, conv2d_biases,
+ dense1_weights, dense1_biases,
+ dense2_weights, dense2_biases,
+ output_weights, output_bias]
+ # Write to file
+ f = open("weights.c", "w")
+ f.write("#include \"weights.h\"\n\n")
+ for (name, val) in zip(names, variables):
+ f.write("const float "+name+" =\n"+fix(str(val))+";\n\n")
f.close()