def process_line_as_2d_input_with_ep(the_str):
"""
NOTES:
1) I likely won't be using this, opting to instead use the onehot implementation
"""
with tf.name_scope("process_data_2d"):
# with tf.device("/cpu:0"):
# A tensor referenced when getting indices of characters for the the_values array
mapping_strings = tf.constant(["0", "1", "K", "Q", "R", "B", "N", "P", "C", "k", "q", "r", "b", "n", "p", "c"])
the_values = tf.constant(
[[0, 0, 0, 0, 0, 0, 0, 0], # 0
[0, 0, 0, 0, 0, 0, 1, 0], # 1
[1, 0, 0, 0, 0, 0, 0, 0], # K
[0, 1, 0, 0, 0, 0, 0, 0], # Q
[0, 0, 1, 0, 0, 0, 0, 0], # R
[0, 0, 0, 1, 0, 0, 0, 0], # B
[0, 0, 0, 0, 1, 0, 0, 0], # N
[0, 0, 0, 0, 0, 1, 0, 0], # P
[0, 0, 0, 0, 0, 0, 0, 1], # C
[-1, 0, 0, 0, 0, 0, 0, 0], # k
[0, -1, 0, 0, 0, 0, 0, 0], # q
[0, 0, -1, 0, 0, 0, 0, 0], # r
[0, 0, 0, -1, 0, 0, 0, 0], # b
[0, 0, 0, 0, -1, 0, 0, 0], # n
[0, 0, 0, 0, 0, -1, 0, 0], # p
[0, 0, 0, 0, 0, 0, 0, -1], # c
], dtype=tf.float32)
# Create the table for getting indices (for the_values) from the information about the board
the_table = tf.contrib.lookup.index_table_from_tensor(mapping=mapping_strings, name="index_lookup_table")
data = tf.reshape(
# Get the values at the given indices
tf.gather(
the_values,
# Get an array of indices corresponding to the array of characters
the_table.lookup(
# Split the string into an array of characters
tf.string_split(
[the_str],
delimiter="").values)),
[3, 64, 8])
return data
评论列表
文章目录