本文整理汇总了Python中utils.product方法的典型用法代码示例。如果您正苦于以下问题:Python utils.product方法的具体用法?Python utils.product怎么用?Python utils.product使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils
的用法示例。
在下文中一共展示了utils.product方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_onehot
# 需要导入模块: import utils [as 别名]
# 或者: from utils import product [as 别名]
def make_onehot(feature, planes):
onehot_features = np.zeros(feature.shape + (planes,), dtype=np.uint8)
capped = np.minimum(feature, planes)
onehot_index_offsets = np.arange(0, product(
onehot_features.shape), planes) + capped.ravel()
# A 0 is encoded as [0,0,0,0], not [1,0,0,0], so we'll
# filter out any offsets that are a multiple of $planes
# A 1 is encoded as [1,0,0,0], not [0,1,0,0], so subtract 1 from offsets
nonzero_elements = (capped != 0).ravel()
nonzero_index_offsets = onehot_index_offsets[nonzero_elements] - 1
onehot_features.ravel()[nonzero_index_offsets] = 1
return onehot_features
示例2: make_onehot
# 需要导入模块: import utils [as 别名]
# 或者: from utils import product [as 别名]
def make_onehot(feature, planes):
onehot_features = np.zeros(feature.shape + (planes,), dtype=np.uint8)
capped = np.minimum(feature, planes)
onehot_index_offsets = np.arange(0, product(onehot_features.shape), planes) + capped.ravel()
# A 0 is encoded as [0,0,0,0], not [1,0,0,0], so we'll
# filter out any offsets that are a multiple of $planes
# A 1 is encoded as [1,0,0,0], not [0,1,0,0], so subtract 1 from offsets
nonzero_elements = (capped != 0).ravel()
nonzero_index_offsets = onehot_index_offsets[nonzero_elements] - 1
onehot_features.ravel()[nonzero_index_offsets] = 1
return onehot_features
示例3: make_onehot
# 需要导入模块: import utils [as 别名]
# 或者: from utils import product [as 别名]
def make_onehot(feature, planes):
onehot_features = np.zeros(feature.shape + (planes,), dtype=np.uint8)
capped = np.minimum(feature, planes)
onehot_index_offsets = np.arange(0, utils.product(
onehot_features.shape), planes) + capped.ravel()
# A 0 is encoded as [0,0,0,0], not [1,0,0,0], so we'll
# filter out any offsets that are a multiple of $planes
# A 1 is encoded as [1,0,0,0], not [0,1,0,0], so subtract 1 from offsets
nonzero_elements = (capped != 0).ravel()
nonzero_index_offsets = onehot_index_offsets[nonzero_elements] - 1
onehot_features.ravel()[nonzero_index_offsets] = 1
return onehot_features
示例4: few_liberties_feature
# 需要导入模块: import utils [as 别名]
# 或者: from utils import product [as 别名]
def few_liberties_feature(position):
feature = position.get_liberties()
onehot_features = np.zeros(feature.shape + (3,), dtype=np.uint8)
onehot_index_offsets = np.arange(0, utils.product(
onehot_features.shape), 3) + feature.ravel()
nonzero_elements = ((feature != 0) & (feature <= 3)).ravel()
nonzero_index_offsets = onehot_index_offsets[nonzero_elements] - 1
onehot_features.ravel()[nonzero_index_offsets] = 1
return onehot_features
示例5: set_up_network
# 需要导入模块: import utils [as 别名]
# 或者: from utils import product [as 别名]
def set_up_network(self):
# a global_step variable allows epoch counts to persist through multiple training sessions
global_step = tf.Variable(0, name="global_step", trainable=False)
x = tf.placeholder(tf.float32, [None, go.N, go.N, self.num_input_planes])
y = tf.placeholder(tf.float32, shape=[None, go.N ** 2])
#convenience functions for initializing weights and biases
def _weight_variable(shape, name):
# If shape is [5, 5, 20, 32], then each of the 32 output planes
# has 5 * 5 * 20 inputs.
number_inputs_added = utils.product(shape[:-1])
stddev = 1 / math.sqrt(number_inputs_added)
# http://neuralnetworksanddeeplearning.com/chap3.html#weight_initialization
return tf.Variable(tf.truncated_normal(shape, stddev=stddev), name=name)
def _conv2d(x, W):
return tf.nn.conv2d(x, W, strides=[1,1,1,1], padding="SAME")
# initial conv layer is 5x5
W_conv_init = _weight_variable([5, 5, self.num_input_planes, self.k], name="W_conv_init")
h_conv_init = tf.nn.relu(_conv2d(x, W_conv_init), name="h_conv_init")
# followed by a series of 3x3 conv layers
W_conv_intermediate = []
h_conv_intermediate = []
_current_h_conv = h_conv_init
for i in range(self.num_int_conv_layers):
with tf.name_scope("layer"+str(i)):
W_conv_intermediate.append(_weight_variable([3, 3, self.k, self.k], name="W_conv"))
h_conv_intermediate.append(tf.nn.relu(_conv2d(_current_h_conv, W_conv_intermediate[-1]), name="h_conv"))
_current_h_conv = h_conv_intermediate[-1]
W_conv_final = _weight_variable([1, 1, self.k, 1], name="W_conv_final")
b_conv_final = tf.Variable(tf.constant(0, shape=[go.N ** 2], dtype=tf.float32), name="b_conv_final")
h_conv_final = _conv2d(h_conv_intermediate[-1], W_conv_final)
logits = tf.reshape(h_conv_final, [-1, go.N ** 2]) + b_conv_final
output = tf.nn.softmax(logits)
log_likelihood_cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=y))
train_step = tf.train.AdamOptimizer(1e-4).minimize(log_likelihood_cost, global_step=global_step)
was_correct = tf.equal(tf.argmax(logits, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(was_correct, tf.float32))
weight_summaries = tf.summary.merge([
tf.summary.histogram(weight_var.name, weight_var)
for weight_var in [W_conv_init] + W_conv_intermediate + [W_conv_final, b_conv_final]],
name="weight_summaries"
)
activation_summaries = tf.summary.merge([
tf.summary.histogram(act_var.name, act_var)
for act_var in [h_conv_init] + h_conv_intermediate + [h_conv_final]],
name="activation_summaries"
)
saver = tf.train.Saver()
# save everything to self.
for name, thing in locals().items():
if not name.startswith('_'):
setattr(self, name, thing)