def full_onehot_process_line_as_2d_input(the_str, num_samples=-1):
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"])
number_of_mapping_strings = 16 # len(mapping_strings)
the_values = tf.constant(
[[1 if i == j else 0 for i in range(number_of_mapping_strings)] for j in range(number_of_mapping_strings)],
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)),
[num_samples, 64, number_of_mapping_strings]) #THIS SHOULD REALLY BE [3x8x8,num_mapping_strings]
return data
评论列表
文章目录