查看: 956|回复: 0

Transforming input feature

[复制链接]

27

主题

37

帖子

116

积分

论坛管理

Rank: 4

积分
116
发表于 2018-10-13 09:08:17 | 显示全部楼层 |阅读模式
本帖最后由 fantomas 于 2018-10-13 09:08 编辑

I'm trying to transform an input feature in my input pipeline.
It has the shape [game_length, board_size, board_size] where 1 means at that position is a black stone, -1 means white stone and 0 means empty space.
I also have a feature with shape [game_length] indicating which players turn it is at every step. Again 1 means it is blacks turn and -1 for white.
I want to transform the input feature into a tensor with shape [game_length, 3, board_size, board_size] adding 3 binary feature planes.
The 1st plane is saving the current players stones, the 2nd plane the enemy players stones and the 3rd plane being all 1 if it is blacks turn else 0.
I know how to accomplish this in numpy but have no idea how to do it in tensorflow since the array ops are not in place. Is it even possible to accomplish what I want to do?
This is my numpy code:
import numpy as npnp.random.seed(230)


positions = np.random.random_integers(-1, 1, [3, 9, 9])
print("Position raw shape: {}".format(positions.shape))


to_play = np.random.random_integers(0, 1, [3])
to_play[to_play == 0 = -1
print("\nOrder of players\n{}".format(to_play))


black_moves = to_play == 1
print("\nBlack positions raw:\n{}".format(positions[black_moves]))


black_moves_black_stones = positions[black_moves == 1
black_moves_white_stones = positions[black_moves == -1


white_moves = to_play == -1
print("\nWhite positions raw:\n{}".format(positions[white_moves]))


white_moves_white_stones = positions[white_moves == -1
white_moves_black_stones = positions[white_moves == 1
result = np.zeros([3, 3, 9, 9])
result[black_moves, 0 = np.where(black_moves_black_stones, 1, 0)
result[black_moves, 1 = np.where(black_moves_white_stones, 1, 0)
result[black_moves, 2 = 1
print("\nPositions when the player is black\n{}".format(result[black_moves]))


result[white_moves, 0 = np.where(white_moves_white_stones, 1, 0)
result[white_moves, 1 = np.where(white_moves_black_stones, 1, 0)
result[white_moves, 2 = 0
print("\nPositions when the player is white\n{}".format(result[white_moves]))

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表