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


Python errors_impl.InvalidArgumentError方法代码示例

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


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

示例1: testLoadExistingVariablesDifferentShapeDefaultDoesNotAllowReshape

# 需要导入模块: from tensorflow.python.framework import errors_impl [as 别名]
# 或者: from tensorflow.python.framework.errors_impl import InvalidArgumentError [as 别名]
def testLoadExistingVariablesDifferentShapeDefaultDoesNotAllowReshape(self):
    model_dir = tempfile.mkdtemp('load_existing_vars_no_reshape')
    if gfile.Exists(model_dir):
      gfile.DeleteRecursively(model_dir)

    init_value0 = [[10.0, 11.0]]
    init_value1 = 20.0
    var_names_to_values = {'v0': init_value0, 'v1': init_value1}

    with self.cached_session() as sess:
      model_path = self.create_checkpoint_from_values(var_names_to_values,
                                                      model_dir)
      var0 = variables_lib2.variable('my_var0', shape=[2, 1])
      var1 = variables_lib2.variable('my_var1', shape=[])

      vars_to_restore = {'v0': var0, 'v1': var1}
      init_fn = variables_lib2.assign_from_checkpoint_fn(
          model_path, vars_to_restore)

      # Initialize the variables.
      sess.run(variables_lib.global_variables_initializer())

      # Perform the assignment.
      with self.assertRaises(errors_impl.InvalidArgumentError):
        init_fn(sess) 
开发者ID:google-research,项目名称:tf-slim,代码行数:27,代码来源:variables_test.py

示例2: test_nan

# 需要导入模块: from tensorflow.python.framework import errors_impl [as 别名]
# 或者: from tensorflow.python.framework.errors_impl import InvalidArgumentError [as 别名]
def test_nan(self):
    with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
                                 'Tensor had NaN values'):
      self.eval([self.checked_nan_lt]) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:6,代码来源:ops_test.py

示例3: test_gather_nd

# 需要导入模块: from tensorflow.python.framework import errors_impl [as 别名]
# 或者: from tensorflow.python.framework.errors_impl import InvalidArgumentError [as 别名]
def test_gather_nd(self):
    if legacy_opset_pre_ver(11):
      raise unittest.SkipTest(
          "ONNX version {} doesn't support GatherND.".format(
              defs.onnx_opset_version()))

    # valid positive and negative indices for elements
    data = np.array([[0, 1], [2, 3]], dtype=np.int64)
    indices = np.array([[0, 0], [1, 1], [-1, -2]], dtype=np.int64)
    ref_output = np.array([0, 3, 2], dtype=np.int64)
    node_def = helper.make_node("GatherND", ["data", "indices"], ["outputs"])
    output = run_node(node_def, [data, indices])
    np.testing.assert_almost_equal(output["outputs"], ref_output)

    # valid positive and negative indices for slices
    data = np.arange(16, dtype=np.int32).reshape([2, 2, 4])
    indices = np.array([[0, 0], [-1, -2]], dtype=np.int64)
    ref_output = np.array([[0, 1, 2, 3], [8, 9, 10, 11]], dtype=np.int32)
    output = run_node(node_def, [data, indices])
    np.testing.assert_almost_equal(output["outputs"], ref_output)
    indices = np.array([[[0, 0]], [[-1, 0]]], dtype=np.int64)
    ref_output = np.array([[[0, 1, 2, 3]], [[8, 9, 10, 11]]], dtype=np.int32)
    output = run_node(node_def, [data, indices])
    np.testing.assert_almost_equal(output["outputs"], ref_output)

    # indices out of bounds
    indices = np.array([[5, 0], [-1, -3]], dtype=np.int64)
    with np.testing.assert_raises(tf.errors.InvalidArgumentError):
      output = run_node(node_def, [data, indices])
    indices = np.array([[1, 1, 6], [-2, -1, -9]], dtype=np.int32)
    with np.testing.assert_raises(tf.errors.InvalidArgumentError):
      output = run_node(node_def, [data, indices]) 
开发者ID:onnx,项目名称:onnx-tensorflow,代码行数:34,代码来源:test_node.py

示例4: test_scatter_elements3

# 需要导入模块: from tensorflow.python.framework import errors_impl [as 别名]
# 或者: from tensorflow.python.framework.errors_impl import InvalidArgumentError [as 别名]
def test_scatter_elements3(self):
    # indices out of bounds
    data = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], dtype=np.float32)
    indices = np.array([[0, 1, 2]], dtype=np.int64)
    updates = np.array([[1.1, 2.1, 3.1]], dtype=np.float32)

    if legacy_opset_pre_ver(11):
      node_def = helper.make_node("Scatter", ["data", "indices", "updates"],
                                  ["outputs"])
    else:
      node_def = helper.make_node("ScatterElements",
                                  ["data", "indices", "updates"], ["outputs"])
    with np.testing.assert_raises(tf.errors.InvalidArgumentError):
      output = run_node(node_def, [data, indices, updates]) 
开发者ID:onnx,项目名称:onnx-tensorflow,代码行数:16,代码来源:test_node.py

示例5: _do_call

# 需要导入模块: from tensorflow.python.framework import errors_impl [as 别名]
# 或者: from tensorflow.python.framework.errors_impl import InvalidArgumentError [as 别名]
def _do_call(self, dp):
        z = len(dp[0])
        assert len(dp) == len(self.input_vars), \
            "{} != {}".format(len(dp), len(self.input_vars))
        feed = dict(zip(self.input_vars, dp))

        try:
            output = self.session.run(self.output_vars, feed_dict=feed)
            output.append(True)
        except InvalidArgumentError:
            print("InvalidArgumentError during session.run")
            output = [[[0] * 6] * z, [0] * z, 0, False]
        return output 
开发者ID:anonymous-author1,项目名称:DDRL,代码行数:15,代码来源:base.py

示例6: _get_NN_prediction

# 需要导入模块: from tensorflow.python.framework import errors_impl [as 别名]
# 或者: from tensorflow.python.framework.errors_impl import InvalidArgumentError [as 别名]
def _get_NN_prediction(self, image, retry=False):
        if retry:
            while True:
                try:
                    res = self._get_NN_prediction_wrapped(image)
                except InvalidArgumentError as e:
                    pass
                    time.sleep(1)
        else:
            return self._get_NN_prediction_wrapped(image) 
开发者ID:anonymous-author1,项目名称:DDRL,代码行数:12,代码来源:train.py

示例7: test_gather

# 需要导入模块: from tensorflow.python.framework import errors_impl [as 别名]
# 或者: from tensorflow.python.framework.errors_impl import InvalidArgumentError [as 别名]
def test_gather(self):
    node_def = helper.make_node("Gather", ["X", "Y"], ["Z"])
    x = self._get_rnd_float32(shape=[10, 10])
    y = [[0, 1], [1, 2]]
    output = run_node(node_def, [x, y])
    test_output = np.zeros((2, 2, 10))
    for i in range(0, 2):
      for j in range(0, 10):
        test_output[0][i][j] = x[i][j]
    for i in range(0, 2):
      for j in range(0, 10):
        test_output[1][i][j] = x[i + 1][j]
    np.testing.assert_almost_equal(output["Z"], test_output)
    if defs.onnx_opset_version() >= 11:
      # test negative indices
      y = [[-10, -9], [1, -8]]
      output = run_node(node_def, [x, y])
      np.testing.assert_almost_equal(output["Z"], test_output)
      # test out of bound indices
      for y in ([[-10, 11], [1, -8]], [[-10, -11], [1, -8]]):
        try:
          output = run_node(node_def, [x, y])
          np.testing.assert_almost_equal(output["Z"], test_output)
          raise AssertionError("Expected ValueError not raised for indices %d" %
                               str(y))
        except InvalidArgumentError as e:
          assert 'Gather indices are out of bound' in str(e), str(y)
      # test non-0 and negative axis
      axis = -3
      node_def = helper.make_node("Gather", ["X", "Y"], ["Z"], axis=axis)
      x = np.reshape(np.arange(5 * 4 * 3 * 2), (5, 4, 3, 2))
      y = np.array([0, 1, 3])
      test_output = np.take(x, y, axis=axis)
      output = run_node(node_def, [x, y])
      np.testing.assert_almost_equal(output["Z"], test_output)
      # test axis attribute validation
      for axis in [-5, 4, 10]:
        try:
          node_def = helper.make_node("Gather", ["X", "Y"], ["Z"], axis=axis)
          run_node(node_def, [x, y])
          raise AssertionError(
              "Expected ValueError not raised for axis value %d" % axis)
        except ValueError as e:
          assert 'out of bounds' in str(e), str(e) + ' for axis ' + str(axis) 
开发者ID:onnx,项目名称:onnx-tensorflow,代码行数:46,代码来源:test_node.py

示例8: test_scatter_nd

# 需要导入模块: from tensorflow.python.framework import errors_impl [as 别名]
# 或者: from tensorflow.python.framework.errors_impl import InvalidArgumentError [as 别名]
def test_scatter_nd(self):
    if legacy_opset_pre_ver(11):
      raise unittest.SkipTest(
          "ONNX version {} doesn't support ScatterND.".format(
              defs.onnx_opset_version()))

    # valid positve and negative indices for elements
    data = np.array([1, 2, 3, 4, 5, 6, 7, 8], dtype=np.float32)
    indices = np.array([[4], [3], [1], [7]], dtype=np.int64)
    updates = np.array([9, 10, 11, 12], dtype=np.float32)
    ref_output = np.array([1, 11, 3, 10, 9, 6, 7, 12], dtype=np.float32)
    node_def = helper.make_node("ScatterND", ["data", "indices", "updates"],
                                ["outputs"])
    output = run_node(node_def, [data, indices, updates])
    np.testing.assert_almost_equal(output["outputs"], ref_output)

    # valid positive and negative indices for slices
    data = np.reshape(np.arange(1, 25, dtype=np.float32), [2, 3, 4])
    indices = np.array([[-2, -1], [1, 0]], dtype=np.int64)
    updates = np.array([[39, 40, 41, 42], [43, 44, 45, 46]], dtype=np.float32)
    ref_output = np.array(
        [[[1, 2, 3, 4], [5, 6, 7, 8], [39, 40, 41, 42]],
         [[43, 44, 45, 46], [17, 18, 19, 20], [21, 22, 23, 24]]],
        dtype=np.float32)
    output = run_node(node_def, [data, indices, updates])
    np.testing.assert_almost_equal(output["outputs"], ref_output)
    indices = np.array([[-1]], dtype=np.int64)
    updates = np.array([[[43, 44, 45, 46], [47, 48, 49, 50], [51, 52, 53, 54]]],
                       dtype=np.float32)
    ref_output = np.array(
        [[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]],
         [[43, 44, 45, 46], [47, 48, 49, 50], [51, 52, 53, 54]]],
        dtype=np.float32)
    output = run_node(node_def, [data, indices, updates])
    np.testing.assert_almost_equal(output["outputs"], ref_output)

    # indices out of bounds
    indices = np.array([[0, 1, 2], [-1, -1, -3], [-2, -3, -4], [0, 2, -5]],
                       dtype=np.int64)
    updates = np.array([37, 52, 30, 39], dtype=np.float32)
    with np.testing.assert_raises(tf.errors.InvalidArgumentError):
      output = run_node(node_def, [data, indices, updates])
    indices = np.array([[0, 1], [-1, -1], [-2, -4]], dtype=np.int64)
    updates = np.array([[35, 36, 37, 38], [51, 52, 53, 54], [31, 32, 33, 34]],
                       dtype=np.float32)
    with np.testing.assert_raises(tf.errors.InvalidArgumentError):
      output = run_node(node_def, [data, indices, updates]) 
开发者ID:onnx,项目名称:onnx-tensorflow,代码行数:49,代码来源:test_node.py

示例9: _random_search

# 需要导入模块: from tensorflow.python.framework import errors_impl [as 别名]
# 或者: from tensorflow.python.framework.errors_impl import InvalidArgumentError [as 别名]
def _random_search(names_train, names_valid, y_train, y_valid, parameter_space, args):
    """Perform random search over given hyper-parameter space."""

    def sample_parameters(parameter_space):
        """Sample parameters from the parameter space."""
        parameters = OrderedDict()
        for key, vals in parameter_space.items():
            parameters[key] = choice(vals)  # sample a value randomly
        return parameters

    searched_parameters = set()
    best_valid_score = np.float64('-inf')
    best_parameters = None
    count = 1

    try:
        while True:
            parameters = sample_parameters(parameter_space)
            if str(parameters) in searched_parameters:
                continue

            _LOGGER.info('---------- ({}) Start experimenting with a new parameter set ----------\n'
                         .format(count))
            _LOGGER.info('Hyper-parameters:\n{}'.format(json.dumps(parameters, indent=2)))

            # construct the model name
            model_name = _construct_model_name(parameters)
            model_path = os.path.join(args['--model-dir'], model_name)
            _LOGGER.info('Model name: {}'.format(model_name))

            _LOGGER.info('Initialize CharLSTM object with the new parameters...')
            model = CharLSTM(**parameters)

            _LOGGER.info('Started the train() method...')
            score = model.train(names_train, y_train, names_valid, y_valid, model_path,
                                int(args['--batch-size']), int(args['--patience']))
            searched_parameters.add(str(parameters))

            if score > best_valid_score:
                _LOGGER.info('Achieved best validation score so far in the search.')
                _LOGGER.info('Hyper-parameters:\n{}'.format(json.dumps(parameters, indent=2)))
                best_valid_score = score
                best_parameters = parameters

            _LOGGER.info('-------- ({}) Finished experimenting with the parameter set --------\n\n'
                         .format(count))
            count += 1

    except KeyboardInterrupt:
        _LOGGER.info('Random Search finishes because of Keyboard Interrupt.')
        _LOGGER.info('Best Validation Score: {:.3f}'.format(best_valid_score))
        _LOGGER.info('Best Hyper-parameters:\n{}'.format(json.dumps(best_parameters, indent=2)))

    except InvalidArgumentError as error:
        _LOGGER.exception(error)
        _LOGGER.info('-------- ({}) Skip the parameter set --------\n\n'.format(count)) 
开发者ID:kensk8er,项目名称:chicksexer,代码行数:58,代码来源:trainer.py


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