ann_creation_helper.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:ChessAI 作者: SamRagusa 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号