当前位置: 首页>>代码示例>>Python>>正文


Python features.extract_features方法代码示例

本文整理汇总了Python中features.extract_features方法的典型用法代码示例。如果您正苦于以下问题:Python features.extract_features方法的具体用法?Python features.extract_features怎么用?Python features.extract_features使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在features的用法示例。


在下文中一共展示了features.extract_features方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_many

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def run_many(self, positions, use_random_symmetry=True):
        processed = list(map(features.extract_features, positions))
        if use_random_symmetry:
            syms_used, processed = symmetries.randomize_symmetries_feat(
                processed)

        outputs = self.sess.run(self.inference_output,
                                feed_dict={self.inference_input: processed})
        if not self.inference:
            probabilities, value = outputs['policy_output'], outputs['value_output']
        else:
            probabilities, value = outputs[0], outputs[1]
        if use_random_symmetry:
            probabilities = symmetries.invert_symmetries_pi(
                syms_used, probabilities)
        return probabilities, value 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:18,代码来源:dual_net.py

示例2: analyze_symmetries

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def analyze_symmetries(sgf_file, load_file):
    with open(sgf_file) as f:
        sgf_contents = f.read()
    iterator = sgf_wrapper.replay_sgf(sgf_contents)
    net = dual_net.DualNetwork(load_file)
    for i, pwc in enumerate(iterator):
        if i < 200:
            continue
        feats = features.extract_features(pwc.position)
        variants = [symmetries.apply_symmetry_feat(s, feats) for s in symmetries.SYMMETRIES]
        values = net.sess.run(
            net.inference_output['value_output'],
            feed_dict={net.inference_input['pos_tensor']: variants})
        mean = np.mean(values)
        stdev = np.std(values)
        all_vals = sorted(zip(values, symmetries.SYMMETRIES))

        print("{:3d} {:.3f} +/- {:.3f} min {:.3f} {} max {:.3f} {}".format(
            i, mean, stdev, *all_vals[0], *all_vals[-1])) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:21,代码来源:inspect_game.py

示例3: test_make_dataset_from_sgf

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def test_make_dataset_from_sgf(self):
        with tempfile.NamedTemporaryFile() as sgf_file, \
                tempfile.NamedTemporaryFile() as record_file:
            sgf_file.write(TEST_SGF.encode('utf8'))
            sgf_file.seek(0)
            preprocessing.make_dataset_from_sgf(
                sgf_file.name, record_file.name)
            recovered_data = self.extract_data(record_file.name)
        start_pos = go.Position()
        first_move = coords.from_sgf('fd')
        next_pos = start_pos.play_move(first_move)
        second_move = coords.from_sgf('cf')
        expected_data = [
            (
                features.extract_features(start_pos),
                preprocessing._one_hot(coords.to_flat(first_move)),
                -1
            ), (
                features.extract_features(next_pos),
                preprocessing._one_hot(coords.to_flat(second_move)),
                -1
            )]
        self.assertEqualData(expected_data, recovered_data) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:25,代码来源:test_preprocessing.py

示例4: test_make_dataset_from_sgf

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def test_make_dataset_from_sgf(self):
    with tempfile.NamedTemporaryFile() as sgf_file, \
        tempfile.NamedTemporaryFile() as record_file:
      sgf_file.write(TEST_SGF.encode('utf8'))
      sgf_file.seek(0)
      preprocessing.make_dataset_from_sgf(
          utils_test.BOARD_SIZE, sgf_file.name, record_file.name)
      recovered_data = self.extract_data(record_file.name)
    start_pos = go.Position(utils_test.BOARD_SIZE)
    first_move = coords.from_sgf('fd')
    next_pos = start_pos.play_move(first_move)
    second_move = coords.from_sgf('cf')
    expected_data = [
        (
            features.extract_features(utils_test.BOARD_SIZE, start_pos),
            preprocessing._one_hot(utils_test.BOARD_SIZE, coords.to_flat(
                utils_test.BOARD_SIZE, first_move)), -1
        ),
        (
            features.extract_features(utils_test.BOARD_SIZE, next_pos),
            preprocessing._one_hot(utils_test.BOARD_SIZE, coords.to_flat(
                utils_test.BOARD_SIZE, second_move)), -1
        )
    ]
    self.assertEqualData(expected_data, recovered_data) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:27,代码来源:preprocessing_test.py

示例5: run_many

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def run_many(self, positions):
        """Runs inference on a list of position."""
        processed = list(map(features_lib.extract_features, positions))
        probabilities = []
        values = []
        for state in processed:
            assert state.shape == (self.board_size, self.board_size,
                                   17), str(state.shape)
            result = self.engine.RunInference(state.flatten())
            # If needed you can get the raw inference time from the result object.
            # inference_time = result[0] # ms
            policy_output = result[1][0:self.output_policy_size]
            value_output = result[1][-1]
            probabilities.append(policy_output)
            values.append(value_output)
        return probabilities, values 
开发者ID:mlperf,项目名称:training,代码行数:18,代码来源:dual_net_edge_tpu.py

示例6: make_dataset_from_selfplay

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def make_dataset_from_selfplay(data_extracts):
    '''
    Returns an iterable of tf.Examples.
    Args:
        data_extracts: An iterable of (position, pi, result) tuples
    '''
    tf_examples = (make_tf_example(features_lib.extract_features(pos), pi, result)
                   for pos, pi, result in data_extracts)
    return tf_examples 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:11,代码来源:preprocessing.py

示例7: _make_tf_example_from_pwc

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def _make_tf_example_from_pwc(position_w_context):
    features = features_lib.extract_features(position_w_context.position)
    pi = _one_hot(coords.to_flat(position_w_context.next_move))
    value = position_w_context.result
    return make_tf_example(features, pi, value) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:7,代码来源:preprocessing.py

示例8: run

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def run(self, position):
        'Return a sorted list of (probability, move) tuples'
        processed_position = features.extract_features(position)
        probabilities = self.session.run(self.output, feed_dict={self.x: processed_position[None, :]})[0]
        return probabilities.reshape([go.N, go.N]) 
开发者ID:llSourcell,项目名称:alphago_demo,代码行数:7,代码来源:policy.py

示例9: run_many

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def run_many(self, positions, use_random_symmetry=True):
    """Compute the policy and value output for given positions.

    Args:
      positions: A list of positions for go board status
      use_random_symmetry: Apply random symmetry (defined in symmetries.py) to
        the extracted features (defined in features.py) of the given positions

    Returns:
      probabilities, value: The policy and value outputs (defined in
        dualnet_model.py)
    """
    def _extract_features(positions):
      return features.extract_features(self.hparams.board_size, positions)
    processed = list(map(_extract_features, positions))
    # processed = [
    #  features.extract_features(self.hparams.board_size, p) for p in positions]
    if use_random_symmetry:
      syms_used, processed = symmetries.randomize_symmetries_feat(processed)
    # feed_dict is a dict object to provide the input examples for the step of
    # inference. sess.run() returns the inference predictions (indicated by
    # self.inference_output) of the given input as outputs
    outputs = self.sess.run(
        self.inference_output, feed_dict={self.inference_input: processed})
    probabilities, value = outputs['policy_output'], outputs['value_output']
    if use_random_symmetry:
      probabilities = symmetries.invert_symmetries_pi(
          self.hparams.board_size, syms_used, probabilities)
    return probabilities, value 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:31,代码来源:dualnet.py

示例10: make_dataset_from_selfplay

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def make_dataset_from_selfplay(data_extracts, params):
  """Make an iterable of tf.Examples.

  Args:
    data_extracts: An iterable of (position, pi, result) tuples
    params: An object of hyperparameters

  Returns:
    An iterable of tf.Examples.
  """
  board_size = params.board_size
  tf_examples = (make_tf_example(features_lib.extract_features(
      board_size, pos), pi, result) for pos, pi, result in data_extracts)
  return tf_examples 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:16,代码来源:preprocessing.py

示例11: _make_tf_example_from_pwc

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def _make_tf_example_from_pwc(board_size, position_w_context):
  features = features_lib.extract_features(
      board_size, position_w_context.position)
  pi = _one_hot(board_size, coords.to_flat(
      board_size, position_w_context.next_move))
  value = position_w_context.result
  return make_tf_example(features, pi, value) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:9,代码来源:preprocessing.py

示例12: predict_on_multiple_board_states

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def predict_on_multiple_board_states(self, positions):
        symmetries, processed = utils.shuffle_feature_symmetries(list(map(features.extract_features, positions)))
        network_outputs = self.sess.run(self.inference_output, feed_dict={self.inference_input: processed})
        action_probs, value_pred = network_outputs['policy_output'], network_outputs['value_output']
        action_probs = utils.invert_policy_symmetries(symmetries, action_probs)
        return action_probs, value_pred 
开发者ID:PacktPublishing,项目名称:Python-Reinforcement-Learning-Projects,代码行数:8,代码来源:network.py

示例13: create_dataset_from_selfplay

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def create_dataset_from_selfplay(data_extracts):
    return (create_tf_train_example(extract_features(board_state), pi, result)
            for board_state, pi, result in data_extracts) 
开发者ID:PacktPublishing,项目名称:Python-Reinforcement-Learning-Projects,代码行数:5,代码来源:preprocessing.py

示例14: run

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def run(self, position):
        'Return a sorted list of (probability, move) tuples'
        processed_position = features.extract_features(position, features=self.features)
        probabilities = self.session.run(self.output, feed_dict={self.x: processed_position[None, :]})[0]
        return probabilities.reshape([go.N, go.N]) 
开发者ID:brilee,项目名称:MuGo,代码行数:7,代码来源:policy.py

示例15: run_many

# 需要导入模块: import features [as 别名]
# 或者: from features import extract_features [as 别名]
def run_many(self, positions):
        f = get_features()
        processed = [features_lib.extract_features(p, f) for p in positions]
        if FLAGS.use_random_symmetry:
            syms_used, processed = symmetries.randomize_symmetries_feat(
                processed)
        outputs = self.sess.run(self.inference_output,
                                feed_dict={self.inference_input: processed})
        probabilities, value = outputs['policy_output'], outputs['value_output']
        if FLAGS.use_random_symmetry:
            probabilities = symmetries.invert_symmetries_pi(
                syms_used, probabilities)
        return probabilities, value 
开发者ID:mlperf,项目名称:training,代码行数:15,代码来源:dual_net.py


注:本文中的features.extract_features方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。