tf.contrib.training.HParams在tensorflow2.0版本以上失效的解决

news2024/11/17 10:26:31

tf.contrib.training.HParams在tensorflow2.0版本以上失效的解决_我也想学习的博客-CSDN博客

1.

 


# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Hyperparameter values."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
 
import json
import numbers
import re
 
import six
 
## from tensorflow.contrib.training.python.training import hparam_pb2
## from tensorflow.python.framework import ops
## from tensorflow.python.util import compat
## from tensorflow.python.util import deprecation
 
# Define the regular expression for parsing a single clause of the input
# (delimited by commas).  A legal clause looks like:
#   <variable name>[<index>]? = <rhs>
# where <rhs> is either a single token or [] enclosed list of tokens.
# For example:  "var[1] = a" or "x = [1,2,3]"
PARAM_RE = re.compile(r"""
  (?P<name>[a-zA-Z][\w\.]*)      # variable name: "var" or "x"
  (\[\s*(?P<index>\d+)\s*\])?  # (optional) index: "1" or None
  \s*=\s*
  ((?P<val>[^,\[]*)            # single value: "a" or None
   |
   \[(?P<vals>[^\]]*)\])       # list of values: None or "1,2,3"
  ($|,\s*)""", re.VERBOSE)
 
 
def _parse_fail(name, var_type, value, values):
  """Helper function for raising a value error for bad assignment."""
  raise ValueError(
      'Could not parse hparam \'%s\' of type \'%s\' with value \'%s\' in %s' %
      (name, var_type.__name__, value, values))
 
 
def _reuse_fail(name, values):
  """Helper function for raising a value error for reuse of name."""
  raise ValueError('Multiple assignments to variable \'%s\' in %s' % (name,
                                                                      values))
 
 
def _process_scalar_value(name, parse_fn, var_type, m_dict, values,
                          results_dictionary):
  """Update results_dictionary with a scalar value.
  Used to update the results_dictionary to be returned by parse_values when
  encountering a clause with a scalar RHS (e.g.  "s=5" or "arr[0]=5".)
  Mutates results_dictionary.
  Args:
    name: Name of variable in assignment ("s" or "arr").
    parse_fn: Function for parsing the actual value.
    var_type: Type of named variable.
    m_dict: Dictionary constructed from regex parsing.
      m_dict['val']: RHS value (scalar)
      m_dict['index']: List index value (or None)
    values: Full expression being parsed
    results_dictionary: The dictionary being updated for return by the parsing
      function.
  Raises:
    ValueError: If the name has already been used.
  """
  try:
    parsed_value = parse_fn(m_dict['val'])
  except ValueError:
    _parse_fail(name, var_type, m_dict['val'], values)
 
  # If no index is provided
  if not m_dict['index']:
    if name in results_dictionary:
      _reuse_fail(name, values)
    results_dictionary[name] = parsed_value
  else:
    if name in results_dictionary:
      # The name has already been used as a scalar, then it
      # will be in this dictionary and map to a non-dictionary.
      if not isinstance(results_dictionary.get(name), dict):
        _reuse_fail(name, values)
    else:
      results_dictionary[name] = {}
 
    index = int(m_dict['index'])
    # Make sure the index position hasn't already been assigned a value.
    if index in results_dictionary[name]:
      _reuse_fail('{}[{}]'.format(name, index), values)
    results_dictionary[name][index] = parsed_value
 
 
def _process_list_value(name, parse_fn, var_type, m_dict, values,
                        results_dictionary):
  """Update results_dictionary from a list of values.
  Used to update results_dictionary to be returned by parse_values when
  encountering a clause with a list RHS (e.g.  "arr=[1,2,3]".)
  Mutates results_dictionary.
  Args:
    name: Name of variable in assignment ("arr").
    parse_fn: Function for parsing individual values.
    var_type: Type of named variable.
    m_dict: Dictionary constructed from regex parsing.
      m_dict['val']: RHS value (scalar)
    values: Full expression being parsed
    results_dictionary: The dictionary being updated for return by the parsing
      function.
  Raises:
    ValueError: If the name has an index or the values cannot be parsed.
  """
  if m_dict['index'] is not None:
    raise ValueError('Assignment of a list to a list index.')
  elements = filter(None, re.split('[ ,]', m_dict['vals']))
  # Make sure the name hasn't already been assigned a value
  if name in results_dictionary:
    raise _reuse_fail(name, values)
  try:
    results_dictionary[name] = [parse_fn(e) for e in elements]
  except ValueError:
    _parse_fail(name, var_type, m_dict['vals'], values)
 
 
def _cast_to_type_if_compatible(name, param_type, value):
  """Cast hparam to the provided type, if compatible.
  Args:
    name: Name of the hparam to be cast.
    param_type: The type of the hparam.
    value: The value to be cast, if compatible.
  Returns:
    The result of casting `value` to `param_type`.
  Raises:
    ValueError: If the type of `value` is not compatible with param_type.
      * If `param_type` is a string type, but `value` is not.
      * If `param_type` is a boolean, but `value` is not, or vice versa.
      * If `param_type` is an integer type, but `value` is not.
      * If `param_type` is a float type, but `value` is not a numeric type.
  """
  fail_msg = (
      "Could not cast hparam '%s' of type '%s' from value %r" %
      (name, param_type, value))
 
  # Some callers use None, for which we can't do any casting/checking. :(
  if issubclass(param_type, type(None)):
    return value
 
  # Avoid converting a non-string type to a string.
  if (issubclass(param_type, (six.string_types, six.binary_type)) and
      not isinstance(value, (six.string_types, six.binary_type))):
    raise ValueError(fail_msg)
 
  # Avoid converting a number or string type to a boolean or vice versa.
  if issubclass(param_type, bool) != isinstance(value, bool):
    raise ValueError(fail_msg)
 
  # Avoid converting float to an integer (the reverse is fine).
  if (issubclass(param_type, numbers.Integral) and
      not isinstance(value, numbers.Integral)):
    raise ValueError(fail_msg)
 
  # Avoid converting a non-numeric type to a numeric type.
  if (issubclass(param_type, numbers.Number) and
      not isinstance(value, numbers.Number)):
    raise ValueError(fail_msg)
 
  return param_type(value)
 
 
def parse_values(values, type_map):
  """Parses hyperparameter values from a string into a python map.
  `values` is a string containing comma-separated `name=value` pairs.
  For each pair, the value of the hyperparameter named `name` is set to
  `value`.
  If a hyperparameter name appears multiple times in `values`, a ValueError
  is raised (e.g. 'a=1,a=2', 'a[1]=1,a[1]=2').
  If a hyperparameter name in both an index assignment and scalar assignment,
  a ValueError is raised.  (e.g. 'a=[1,2,3],a[0] = 1').
  The hyperparameter name may contain '.' symbols, which will result in an
  attribute name that is only accessible through the getattr and setattr
  functions.  (And must be first explicit added through add_hparam.)
  WARNING: Use of '.' in your variable names is allowed, but is not well
  supported and not recommended.
  The `value` in `name=value` must follows the syntax according to the
  type of the parameter:
  *  Scalar integer: A Python-parsable integer point value.  E.g.: 1,
     100, -12.
  *  Scalar float: A Python-parsable floating point value.  E.g.: 1.0,
     -.54e89.
  *  Boolean: Either true or false.
  *  Scalar string: A non-empty sequence of characters, excluding comma,
     spaces, and square brackets.  E.g.: foo, bar_1.
  *  List: A comma separated list of scalar values of the parameter type
     enclosed in square brackets.  E.g.: [1,2,3], [1.0,1e-12], [high,low].
  When index assignment is used, the corresponding type_map key should be the
  list name.  E.g. for "arr[1]=0" the type_map must have the key "arr" (not
  "arr[1]").
  Args:
    values: String.  Comma separated list of `name=value` pairs where
      'value' must follow the syntax described above.
    type_map: A dictionary mapping hyperparameter names to types.  Note every
      parameter name in values must be a key in type_map.  The values must
      conform to the types indicated, where a value V is said to conform to a
      type T if either V has type T, or V is a list of elements of type T.
      Hence, for a multidimensional parameter 'x' taking float values,
      'x=[0.1,0.2]' will parse successfully if type_map['x'] = float.
  Returns:
    A python map mapping each name to either:
    * A scalar value.
    * A list of scalar values.
    * A dictionary mapping index numbers to scalar values.
    (e.g. "x=5,L=[1,2],arr[1]=3" results in {'x':5,'L':[1,2],'arr':{1:3}}")
  Raises:
    ValueError: If there is a problem with input.
    * If `values` cannot be parsed.
    * If a list is assigned to a list index (e.g. 'a[1] = [1,2,3]').
    * If the same rvalue is assigned two different values (e.g. 'a=1,a=2',
      'a[1]=1,a[1]=2', or 'a=1,a=[1]')
  """
  results_dictionary = {}
  pos = 0
  while pos < len(values):
    m = PARAM_RE.match(values, pos)
    if not m:
      raise ValueError('Malformed hyperparameter value: %s' % values[pos:])
    # Check that there is a comma between parameters and move past it.
    pos = m.end()
    # Parse the values.
    m_dict = m.groupdict()
    name = m_dict['name']
    if name not in type_map:
      raise ValueError('Unknown hyperparameter type for %s' % name)
    type_ = type_map[name]
 
    # Set up correct parsing function (depending on whether type_ is a bool)
    if type_ == bool:
 
      def parse_bool(value):
        if value in ['true', 'True']:
          return True
        elif value in ['false', 'False']:
          return False
        else:
          try:
            return bool(int(value))
          except ValueError:
            _parse_fail(name, type_, value, values)
 
      parse = parse_bool
    else:
      parse = type_
 
    # If a singe value is provided
    if m_dict['val'] is not None:
      _process_scalar_value(name, parse, type_, m_dict, values,
                            results_dictionary)
 
    # If the assigned value is a list:
    elif m_dict['vals'] is not None:
      _process_list_value(name, parse, type_, m_dict, values,
                          results_dictionary)
 
    else:  # Not assigned a list or value
      _parse_fail(name, type_, '', values)
 
  return results_dictionary
 
 
class HParams(object):
  """Class to hold a set of hyperparameters as name-value pairs.
  A `HParams` object holds hyperparameters used to build and train a model,
  such as the number of hidden units in a neural net layer or the learning rate
  to use when training.
  You first create a `HParams` object by specifying the names and values of the
  hyperparameters.
  To make them easily accessible the parameter names are added as direct
  attributes of the class.  A typical usage is as follows:
  ```python
  # Create a HParams object specifying names and values of the model
  # hyperparameters:
  hparams = HParams(learning_rate=0.1, num_hidden_units=100)
  # The hyperparameter are available as attributes of the HParams object:
  hparams.learning_rate ==> 0.1
  hparams.num_hidden_units ==> 100
  ```
  Hyperparameters have type, which is inferred from the type of their value
  passed at construction type.   The currently supported types are: integer,
  float, boolean, string, and list of integer, float, boolean, or string.
  You can override hyperparameter values by calling the
  [`parse()`](#HParams.parse) method, passing a string of comma separated
  `name=value` pairs.  This is intended to make it possible to override
  any hyperparameter values from a single command-line flag to which
  the user passes 'hyper-param=value' pairs.  It avoids having to define
  one flag for each hyperparameter.
  The syntax expected for each value depends on the type of the parameter.
  See `parse()` for a description of the syntax.
  Example:
  ```python
  # Define a command line flag to pass name=value pairs.
  # For example using argparse:
  import argparse
  parser = argparse.ArgumentParser(description='Train my model.')
  parser.add_argument('--hparams', type=str,
                      help='Comma separated list of "name=value" pairs.')
  args = parser.parse_args()
  ...
  def my_program():
    # Create a HParams object specifying the names and values of the
    # model hyperparameters:
    hparams = tf.HParams(learning_rate=0.1, num_hidden_units=100,
                         activations=['relu', 'tanh'])
    # Override hyperparameters values by parsing the command line
    hparams.parse(args.hparams)
    # If the user passed `--hparams=learning_rate=0.3` on the command line
    # then 'hparams' has the following attributes:
    hparams.learning_rate ==> 0.3
    hparams.num_hidden_units ==> 100
    hparams.activations ==> ['relu', 'tanh']
    # If the hyperparameters are in json format use parse_json:
    hparams.parse_json('{"learning_rate": 0.3, "activations": "relu"}')
  ```
  """
 
  _HAS_DYNAMIC_ATTRIBUTES = True  # Required for pytype checks.
 
  def __init__(self, hparam_def=None, model_structure=None, **kwargs):
    """Create an instance of `HParams` from keyword arguments.
    The keyword arguments specify name-values pairs for the hyperparameters.
    The parameter types are inferred from the type of the values passed.
    The parameter names are added as attributes of `HParams` object, so they
    can be accessed directly with the dot notation `hparams._name_`.
    Example:
    ```python
    # Define 3 hyperparameters: 'learning_rate' is a float parameter,
    # 'num_hidden_units' an integer parameter, and 'activation' a string
    # parameter.
    hparams = tf.HParams(
        learning_rate=0.1, num_hidden_units=100, activation='relu')
    hparams.activation ==> 'relu'
    ```
    Note that a few names are reserved and cannot be used as hyperparameter
    names.  If you use one of the reserved name the constructor raises a
    `ValueError`.
    Args:
      hparam_def: Serialized hyperparameters, encoded as a hparam_pb2.HParamDef
        protocol buffer. If provided, this object is initialized by
        deserializing hparam_def.  Otherwise **kwargs is used.
      model_structure: An instance of ModelStructure, defining the feature
        crosses to be used in the Trial.
      **kwargs: Key-value pairs where the key is the hyperparameter name and
        the value is the value for the parameter.
    Raises:
      ValueError: If both `hparam_def` and initialization values are provided,
        or if one of the arguments is invalid.
    """
    # Register the hyperparameters and their type in _hparam_types.
    # This simplifies the implementation of parse().
    # _hparam_types maps the parameter name to a tuple (type, bool).
    # The type value is the type of the parameter for scalar hyperparameters,
    # or the type of the list elements for multidimensional hyperparameters.
    # The bool value is True if the value is a list, False otherwise.
    self._hparam_types = {}
    self._model_structure = model_structure
    if hparam_def:
##       self._init_from_proto(hparam_def)
##       if kwargs:
##         raise ValueError('hparam_def and initialization values are '
##                          'mutually exclusive')
      raise ValueError('hparam_def has been disabled in this version')
    else:
      for name, value in six.iteritems(kwargs):
        self.add_hparam(name, value)
 
##   def _init_from_proto(self, hparam_def):
##     """Creates a new HParams from `HParamDef` protocol buffer.
## 
##     Args:
##       hparam_def: `HParamDef` protocol buffer.
##     """
##     assert isinstance(hparam_def, hparam_pb2.HParamDef)
##     for name, value in hparam_def.hparam.items():
##       kind = value.WhichOneof('kind')
##       if kind.endswith('_value'):
##         # Single value.
##         if kind.startswith('int64'):
##           # Setting attribute value to be 'int' to ensure the type is compatible
##           # with both Python2 and Python3.
##           self.add_hparam(name, int(getattr(value, kind)))
##         elif kind.startswith('bytes'):
##           # Setting attribute value to be 'str' to ensure the type is compatible
##           # with both Python2 and Python3. UTF-8 encoding is assumed.
##           self.add_hparam(name, compat.as_str(getattr(value, kind)))
##         else:
##           self.add_hparam(name, getattr(value, kind))
##       else:
##         # List of values.
##         if kind.startswith('int64'):
##           # Setting attribute value to be 'int' to ensure the type is compatible
##           # with both Python2 and Python3.
##           self.add_hparam(name, [int(v) for v in getattr(value, kind).value])
##         elif kind.startswith('bytes'):
##           # Setting attribute value to be 'str' to ensure the type is compatible
##           # with both Python2 and Python3. UTF-8 encoding is assumed.
##           self.add_hparam(
##               name, [compat.as_str(v) for v in getattr(value, kind).value])
##         else:
##           self.add_hparam(name, [v for v in getattr(value, kind).value])
 
  def add_hparam(self, name, value):
    """Adds {name, value} pair to hyperparameters.
    Args:
      name: Name of the hyperparameter.
      value: Value of the hyperparameter. Can be one of the following types:
        int, float, string, int list, float list, or string list.
    Raises:
      ValueError: if one of the arguments is invalid.
    """
    # Keys in kwargs are unique, but 'name' could the name of a pre-existing
    # attribute of this object.  In that case we refuse to use it as a
    # hyperparameter name.
    if getattr(self, name, None) is not None:
      raise ValueError('Hyperparameter name is reserved: %s' % name)
    if isinstance(value, (list, tuple)):
      if not value:
        raise ValueError(
            'Multi-valued hyperparameters cannot be empty: %s' % name)
      self._hparam_types[name] = (type(value[0]), True)
    else:
      self._hparam_types[name] = (type(value), False)
    setattr(self, name, value)
 
  def set_hparam(self, name, value):
    """Set the value of an existing hyperparameter.
    This function verifies that the type of the value matches the type of the
    existing hyperparameter.
    Args:
      name: Name of the hyperparameter.
      value: New value of the hyperparameter.
    Raises:
      ValueError: If there is a type mismatch.
    """
    param_type, is_list = self._hparam_types[name]
    if isinstance(value, list):
      if not is_list:
        raise ValueError(
            'Must not pass a list for single-valued parameter: %s' % name)
      setattr(self, name, [
          _cast_to_type_if_compatible(name, param_type, v) for v in value])
    else:
      if is_list:
        raise ValueError(
            'Must pass a list for multi-valued parameter: %s.' % name)
      setattr(self, name, _cast_to_type_if_compatible(name, param_type, value))
 
  def del_hparam(self, name):
    """Removes the hyperparameter with key 'name'.
    Args:
      name: Name of the hyperparameter.
    """
    if hasattr(self, name):
      delattr(self, name)
      del self._hparam_types[name]
 
  def parse(self, values):
    """Override hyperparameter values, parsing new values from a string.
    See parse_values for more detail on the allowed format for values.
    Args:
      values: String.  Comma separated list of `name=value` pairs where
        'value' must follow the syntax described above.
    Returns:
      The `HParams` instance.
    Raises:
      ValueError: If `values` cannot be parsed.
    """
    type_map = dict()
    for name, t in self._hparam_types.items():
      param_type, _ = t
      type_map[name] = param_type
 
    values_map = parse_values(values, type_map)
    return self.override_from_dict(values_map)
 
  def override_from_dict(self, values_dict):
    """Override hyperparameter values, parsing new values from a dictionary.
    Args:
      values_dict: Dictionary of name:value pairs.
    Returns:
      The `HParams` instance.
    Raises:
      ValueError: If `values_dict` cannot be parsed.
    """
    for name, value in values_dict.items():
      self.set_hparam(name, value)
    return self
 
##   @deprecation.deprecated(None, 'Use `override_from_dict`.')
  def set_from_map(self, values_map):
    """DEPRECATED. Use override_from_dict."""
    return self.override_from_dict(values_dict=values_map)
 
  def set_model_structure(self, model_structure):
    self._model_structure = model_structure
 
  def get_model_structure(self):
    return self._model_structure
 
  def to_json(self, indent=None, separators=None, sort_keys=False):
    """Serializes the hyperparameters into JSON.
    Args:
      indent: If a non-negative integer, JSON array elements and object members
        will be pretty-printed with that indent level. An indent level of 0, or
        negative, will only insert newlines. `None` (the default) selects the
        most compact representation.
      separators: Optional `(item_separator, key_separator)` tuple. Default is
        `(', ', ': ')`.
      sort_keys: If `True`, the output dictionaries will be sorted by key.
    Returns:
      A JSON string.
    """
    return json.dumps(
        self.values(),
        indent=indent,
        separators=separators,
        sort_keys=sort_keys)
 
  def parse_json(self, values_json):
    """Override hyperparameter values, parsing new values from a json object.
    Args:
      values_json: String containing a json object of name:value pairs.
    Returns:
      The `HParams` instance.
    Raises:
      ValueError: If `values_json` cannot be parsed.
    """
    values_map = json.loads(values_json)
    return self.override_from_dict(values_map)
 
  def values(self):
    """Return the hyperparameter values as a Python dictionary.
    Returns:
      A dictionary with hyperparameter names as keys.  The values are the
      hyperparameter values.
    """
    return {n: getattr(self, n) for n in self._hparam_types.keys()}
 
  def get(self, key, default=None):
    """Returns the value of `key` if it exists, else `default`."""
    if key in self._hparam_types:
      # Ensure that default is compatible with the parameter type.
      if default is not None:
        param_type, is_param_list = self._hparam_types[key]
        type_str = 'list<%s>' % param_type if is_param_list else str(param_type)
        fail_msg = ("Hparam '%s' of type '%s' is incompatible with "
                    'default=%s' % (key, type_str, default))
 
        is_default_list = isinstance(default, list)
        if is_param_list != is_default_list:
          raise ValueError(fail_msg)
 
        try:
          if is_default_list:
            for value in default:
              _cast_to_type_if_compatible(key, param_type, value)
          else:
            _cast_to_type_if_compatible(key, param_type, default)
        except ValueError as e:
          raise ValueError('%s. %s' % (fail_msg, e))
 
      return getattr(self, key)
 
    return default
 
  def __contains__(self, key):
    return key in self._hparam_types
 
  def __str__(self):
    return str(sorted(self.values().items()))
 
  def __repr__(self):
    return '%s(%s)' % (type(self).__name__, self.__str__())
 
  @staticmethod
  def _get_kind_name(param_type, is_list):
    """Returns the field name given parameter type and is_list.
    Args:
      param_type: Data type of the hparam.
      is_list: Whether this is a list.
    Returns:
      A string representation of the field name.
    Raises:
      ValueError: If parameter type is not recognized.
    """
    if issubclass(param_type, bool):
      # This check must happen before issubclass(param_type, six.integer_types),
      # since Python considers bool to be a subclass of int.
      typename = 'bool'
    elif issubclass(param_type, six.integer_types):
      # Setting 'int' and 'long' types to be 'int64' to ensure the type is
      # compatible with both Python2 and Python3.
      typename = 'int64'
    elif issubclass(param_type, (six.string_types, six.binary_type)):
      # Setting 'string' and 'bytes' types to be 'bytes' to ensure the type is
      # compatible with both Python2 and Python3.
      typename = 'bytes'
    elif issubclass(param_type, float):
      typename = 'float'
    else:
      raise ValueError('Unsupported parameter type: %s' % str(param_type))
 
    suffix = 'list' if is_list else 'value'
    return '_'.join([typename, suffix])
 
##   def to_proto(self, export_scope=None):  # pylint: disable=unused-argument
##     """Converts a `HParams` object to a `HParamDef` protocol buffer.
## 
##     Args:
##       export_scope: Optional `string`. Name scope to remove.
## 
##     Returns:
##       A `HParamDef` protocol buffer.
##     """
##     hparam_proto = hparam_pb2.HParamDef()
##     for name in self._hparam_types:
##       # Parse the values.
##       param_type, is_list = self._hparam_types.get(name, (None, None))
##       kind = HParams._get_kind_name(param_type, is_list)
## 
##       if is_list:
##         if kind.startswith('bytes'):
##           v_list = [compat.as_bytes(v) for v in getattr(self, name)]
##         else:
##           v_list = [v for v in getattr(self, name)]
##         getattr(hparam_proto.hparam[name], kind).value.extend(v_list)
##       else:
##         v = getattr(self, name)
##         if kind.startswith('bytes'):
##           v = compat.as_bytes(getattr(self, name))
##         setattr(hparam_proto.hparam[name], kind, v)
## 
##     return hparam_proto
 
##   @staticmethod
##   def from_proto(hparam_def, import_scope=None):  # pylint: disable=unused-argument
##     return HParams(hparam_def=hparam_def)
 
 
## ops.register_proto_function(
##     'hparams',
##     proto_type=hparam_pb2.HParamDef,
##     to_proto=HParams.to_proto,
##     from_proto=HParams.from_proto)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/728452.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

学习matplotlib第一步

下边代码会画出一个ycos(x)的图像&#xff1a; import numpy as np import matplotlib.pyplot as pltx np.linspace(-2,2,100) ynp.cos(np.pi*x)plt.plot(x,y,go) plt.title(r"$y\cos(\pi | time x$") plt.show()在Jupyter lab运行的时候&#xff0c;发现报错如下&…

干货-卷起来,企业级web自动化测试实战落地(一)

目录&#xff1a;导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09; 前言 开始前-项目讨论 …

18 SAR图像和光学图像的配准算法(matlab程序)

1.简述 合成孔径雷达(synthetic aperture radar,SAR)图像配准的主要目标是对同一或不同传感器在不同时间、不同视点捕获的SAR图像进行配准。SAR因具有全天候成像能力和地物穿透能力&#xff0c;因此具有非常广泛的应用&#xff0c;如变化检测[1]、图像融合[2]、目标检测与识别[…

提取背景音乐去掉人声的方法是什么?这几个方法简单做到!

当制作视频或音频时&#xff0c;我们常常需要提取背景音乐并去掉人声。这一过程并不简单&#xff0c;需要一些专业的技巧和工具。相信有些新手小伙伴也不知道该如何操作&#xff0c;下面我们将分享三个方法&#xff0c;希望能够帮助到你。 方法一&#xff1a;使用记灵在线工具…

gma 2 教程(二)数据操作:1. 相关模块组成

考虑到数据读写是地理空间数据分析和应用的基础&#xff0c;因此将本章作为正文第一部分&#xff0c;以便为后续章节应用提供基础支持。本章以gma栅格/矢量数据输入输出模块&#xff08;io&#xff09;栅格/矢量数据的读取、创建、变换等主要操作为基础&#xff0c;配合gma地理…

【达摩院OpenVI】开源CVPR快速实例分割FasInst模型

团队模型、论文、博文、直播合集&#xff0c;点击此处浏览 一、论文&代码 论文&#xff1a;https://arxiv.org/abs/2303.08594 模型&代码&#xff1a;https://modelscope.cn/models/damo/cv_resnet50_fast-instance-segmentation_coco/summary 二、背景 实例分割旨…

2023-7-8-第十四式策略模式

&#x1f37f;*★,*:.☆(&#xffe3;▽&#xffe3;)/$:*.★* &#x1f37f; &#x1f4a5;&#x1f4a5;&#x1f4a5;欢迎来到&#x1f91e;汤姆&#x1f91e;的csdn博文&#x1f4a5;&#x1f4a5;&#x1f4a5; &#x1f49f;&#x1f49f;喜欢的朋友可以关注一下&#xf…

axios拦截器

在请求或响应被 then 或 catch 处理前拦截它们。 // 添加请求拦截器 axios.interceptors.request.use(function (config) {// 在发送请求之前做些什么return config;}, function (error) {// 对请求错误做些什么return Promise.reject(error);});// 添加响应拦截器 axios.inte…

PMSG永磁风机VSG网侧虚拟同步控制一次调频四机两区域系统,离散模型。

PMSGM永磁同步风机VSG虚拟同步机调频两区域系统&#xff0c;离散模型&#xff0c;非无穷大电网。 风机为网侧VSG控制。四机两区域系统&#xff0c;渗透率可调。当前渗透率为区域1&#xff0c;一台900MW同步机&#xff0c;区域2一台900MW同步机&#xff0c;永磁同步风电场容量5…

minio 升级相关问题

系列文章目录 文章目录 系列文章目录前言一、集群部署二、单机部署三、写一个启动脚本四、性能方面 前言 minio版本升级&#xff0c;目的主要是为了解决由 Direct buffer memory 引发的附件下载优化方案 minio version RELEASE.2021-01-16T02-19-44Z > minio version RELEA…

60题学会动态规划系列:动态规划算法第四讲

买卖股票相关的动态规划题目 文章目录 1.买卖股票的最佳时机含冷冻期2.买卖股票的最佳时期含⼿续费3.买卖股票的最佳时机III4.买卖股票的最佳时机IV 1.最佳买卖股票时机含冷冻期 力扣链接&#xff1a;力扣 给定一个整数数组prices&#xff0c;其中第 prices[i] 表示第 i 天的…

Delphi XE编写OCX控件

1、new->other 2、Active libary 3、再次New->Other,才出现ActiveX组件内容 设置类名及参数

在 Vue 3 中使用阿里巴巴矢量图标库

在项目中基本会用到图标&#xff0c;比较常见的就是阿里图标库。这篇文章主要介绍如何在vue3中使用图标库。 下载并全局注册自定义图标库 手动下载阿里巴巴矢量图标库的字体文件&#xff1a; 在阿里巴巴矢量图标库网站上选择您需要的图标&#xff0c;并将其添加到购物车。然后…

CMake之CPack

文章目录 一、CPack1.用CPack打包成为deb包2.如何确定的Depends依赖包?3.如何确定编译Build-Depends&#xff1f;4.Cpakc打包RPM包 二、deb的简单使用三、deb包相关文件说明1.control文件2.preinst文件3.postinst文件4.prerm文件5.postrm文件 一、CPack CPack 是 CMake 2.4.2…

SpringBoot 集成 EasyExcel 3.x 实现 Excel 导出

目录 EasyExcel官方文档 EasyExcel是什么&#xff1f; EasyExcel注解 springboot集成EasyExcel 简单入门导出 &#xff1a; 实体类 自定义转换类 测试一下 复杂表头一对多导出 &#xff1a; 自定义注解 定义实体类 自定义单元格合并策略 测试一下 EasyExcel官方文档 …

The Sandbox 展示泰国 2023 年元宇宙生态系统

The Sandbox 举办了 2023 年泰国合作伙伴日活动&#xff0c;宣布创建泰国元宇宙生态系统&#xff0c;并对泰国创客社区的巨大合作和发展表示认可。 The Sandbox 联合创始人兼首席运营官 Sebastien BORGET 说&#xff1a;“我们很高兴见证 The Sandbox 泰国生态系统的发展&#…

第七章 网络安全【计算机网络】

第七章 网络安全【计算机网络】 前言推荐第7章 网络安全7.1网络安全问题概述7.1.1计算机网络面临的安全性威胁7.1.2安全的计算机网络7.1.3数据加密模型 7.2两类密码体制7.2.1对称密钥密码体制7.2.2公钥密码体制 7.3鉴别7.3.1报文鉴别7.3.2实体鉴别 7.4密钥分配7.4.1 对称密钥的…

银行软开能干到退休吗?

大家好&#xff0c;我是熊哥。 21世纪了好像不躺平对不起自己&#xff1f;很多读者都关心哪些企业适合躺平&#xff0c;做程序员是不是在银行可以舒舒服服干一辈子&#xff1f;银行招软开&#xff08;软件开发&#xff09;有哪些要求&#xff1f; 现在就来详细讲一讲。 擦亮…

数据结构--二叉树的线索化

数据结构–二叉树的线索化 用土办法找到中序前驱 typedef struct BiTNode {ElemType data; //数据域struct BiTNode *lchild, *rchild; //左、右孩子指针struct BiTnode *parent; //父节点指针 }BiTNode, *BiTree;BiTNode *p; // p指向目标结点 BiTNode *pre NULL; //指向当前…

用Postman和jmeter做接口测试有什么区别吗?

目录 1.创建接口用例集&#xff08;没区别&#xff09; 2.步骤的实现&#xff08;有区别&#xff09; 3数据用例的实现 4断言的实现 5执行 6其他 总结&#xff1a; 1.创建接口用例集&#xff08;没区别&#xff09; Postman是Collections&#xff0c;Jmeter是线程组&am…