I'm trying to transplant RocAlphaGo to play Game of Amazons, and there are problems when trying to implement supervised policy trainer.
from keras.models import Sequential, Model
from keras.layers.core import Activation, Flatten
from keras.layers import convolutional
defaults = {
"board": 10,
"filters_per_layer": 128,
"layers": 12,
"filter_width_1": 5
}
# copy defaults, but override with anything in kwargs
params = defaults
network = Sequential()
# create first layer
network.add(convolutional.Convolution2D(
input_shape=(6, 10, 10),
nb_filter=128,
nb_row=5,
nb_col=5,
init='uniform',
activation='relu',
border_mode='same'))
# create all other layers
for i in range(2, 13):
# use filter_width_K if it is there, otherwise use 3
filter_key = "filter_width_%d" % i
filter_width = params.get(filter_key, 3)
# use filters_per_layer_K if it is there, otherwise use default value
filter_count_key = "filters_per_layer_%d" % i
filter_nb = params.get(filter_count_key, 128)
network.add(convolutional.Convolution2D(
nb_filter=filter_nb,
nb_row=filter_width,
nb_col=filter_width,
init='uniform',
activation='relu',
border_mode='same'))
# the last layer maps each <filters_per_layer> feature to a number
network.add(convolutional.Convolution2D(
nb_filter=1,
nb_row=1,
nb_col=1,
init='uniform',
border_mode='same'))
# reshape output to be board x board
network.add(Flatten())
# softmax makes it into a probability distribution
network.add(Activation('softmax'))
- keras 1.2.0
- python 2.7
Gives the following exception:
ValueError: Error when checking model target: expected activation_1 to have shape (None, 60) but got array with shape (10, 100)
The training data set is a (10, 6, 10, 10) array, 10 x 6 layers , each layer is a 10x10 array(chess board), why model need (None, 60) ?
if chagne input_shape=(6, 10, 10) to input_shape=(10, 10, 10), will get:
ValueError: Error when checking model input: expected convolution2d_input_1 to have shape (None, 10, 10, 10) but got array with shape (10, 6, 10, 10)
All the code is here