Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prediction Issue #1392

Open
SilenceBSun opened this issue Jan 11, 2024 · 8 comments
Open

Prediction Issue #1392

SilenceBSun opened this issue Jan 11, 2024 · 8 comments
Labels

Comments

@SilenceBSun
Copy link

My code:
grad.beta<-predict(model.grad, keras_train_data_x, keras_train_data_y)
grad.beta <- data.frame(grad.beta)

Hi, I am new user of Keras. When I try to predict the data with keras, it shows me this.
捕获

model is fine. model.grad has processed without any errors showing.
my tensorflow version is 2.1. numpy version is 1.16.4. python version is 3.6. keras version is 2.3.1.

@SilenceBSun SilenceBSun changed the title Installation Issue Prediction Issue Jan 11, 2024
@t-kalinowski
Copy link
Member

t-kalinowski commented Jan 11, 2024

  • Can you please provide code I can run to reproduce the error locally? {reprex} may be helpful.
  • What is the output from running reticulate::py_last_error()?
  • Your tensorflow version and python versions are quite old, and no longer supported. You may want to upgrade (though, I don't think that's the source of the error).

@t-kalinowski t-kalinowski added reprex awaiting response Waiting for issue author to respond labels Jan 11, 2024
@SilenceBSun
Copy link
Author

SilenceBSun commented Jan 11, 2024

── Python Exception Message ──────────────────────────────────────────────────────────
Traceback (most recent call last):
  File "C:\Users\huany\MINICO~1\envs\TENSOR~1\lib\site-packages\tensorflow_core\python\eager\execute.py", line 61, in quick_execute
    num_outputs)
TypeError: An op outside of the function building code is being passed
a "Graph" tensor. It is possible to have Graph tensors
leak out of the function building context by including a
tf.init_scope in your function building code.
For example, the following function will fail:
  @tf.function
  def has_init_scope():
    my_constant = tf.constant(1.)
    with tf.init_scope():
      added = my_constant * 2
The graph tensor has name: lambda_21/Identity:0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\huany\MINICO~1\envs\TENSOR~1\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 1013, in predict
    use_multiprocessing=use_multiprocessing)
  File "C:\Users\huany\MINICO~1\envs\TENSOR~1\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 498, in predict
    workers=workers, use_multiprocessing=use_multiprocessing, **kwargs)
  File "C:\Users\huany\MINICO~1\envs\TENSOR~1\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 475, in _model_iteration
    total_epochs=1)
  File "C:\Users\huany\MINICO~1\envs\TENSOR~1\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 128, in run_one_epoch
    batch_outs = execution_function(iterator)
  File "C:\Users\huany\MINICO~1\envs\TENSOR~1\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py", line 98, in execution_function
    distributed_function(input_fn))
  File "C:\Users\huany\MINICO~1\envs\TENSOR~1\lib\site-packages\tensorflow_core\python\eager\def_function.py", line 568, in __call__
    result = self._call(*args, **kwds)
  File "C:\Users\huany\MINICO~1\envs\TENSOR~1\lib\site-packages\tensorflow_core\python\eager\def_function.py", line 638, in _call
    return self._concrete_stateful_fn._filtered_call(canon_args, canon_kwds)  # pylint: disable=protected-access
  File "C:\Users\huany\MINICO~1\envs\TENSOR~1\lib\site-packages\tensorflow_core\python\eager\function.py", line 1611, in _filtered_call
    self.captured_inputs)
  File "C:\Users\huany\MINICO~1\envs\TENSOR~1\lib\site-packages\tensorflow_core\python\eager\function.py", line 1692, in _call_flat
    ctx, args, cancellation_manager=cancellation_manager))
  File "C:\Users\huany\MINICO~1\envs\TENSOR~1\lib\site-packages\tensorflow_core\python\eager\function.py", line 545, in call
    ctx=ctx)
  File "C:\Users\huany\MINICO~1\envs\TENSOR~1\lib\site-packages\tensorflow_core\python\eager\execute.py", line 75, in quick_execute
    "tensors, but found {}".format(keras_symbolic_tensors))
tensorflow.python.eager.core._SymbolicException: Inputs to eager execution function cannot be Keras symbolic tensors, but found [<tf.Tensor 'lambda_21/Identity:0' shape=(None,) dtype=float32>, <tf.Tensor 'Predictions_10/Identity:0' shape=(None, 3) dtype=float32>, <tf.Tensor 'lambda_21/strided_slice/stack:0' shape=(2,) dtype=int32>, <tf.Tensor 'lambda_21/strided_slice/stack_1:0' shape=(2,) dtype=int32>, <tf.Tensor 'lambda_21/strided_slice/stack_2:0' shape=(2,) dtype=int32>, <tf.Tensor 'Predictions_10/MatMul/ReadVariableOp:0' shape=(6, 3) dtype=float32>, <tf.Tensor 'dense_21/Identity:0' shape=(None, 6) dtype=float32>, <tf.Tensor 'dense_21/Tanh:0' shape=(None, 6) dtype=float32>, <tf.Tensor 'dense_21/MatMul/ReadVariableOp:0' shape=(12, 6) dtype=float32>, <tf.Tensor 'dense_22/Identity:0' shape=(None, 12) dtype=float32>, <tf.Tensor 'dense_22/Tanh:0' shape=(None, 12) dtype=float32>, <tf.Tensor 'dense_22/MatMul/ReadVariableOp:0' shape=(3, 12) dtype=float32>, <tf.Tensor 'input_11:0' shape=(None, 3) dtype=float32>]

── R Traceback ───────────────────────────────────────────────────────────────────────
    ▆
 1. ├─model.grad %>% predict(keras_train_data_x)
 2. ├─stats::predict(., keras_train_data_x)
 3. └─keras:::predict.keras.engine.training.Model(., keras_train_data_x)
 4.   ├─base::do.call(object$predict, args)
 5.   └─reticulate (local) `<python.builtin.method>`(...)
 6.     └─reticulate:::py_call_impl(callable, call_args$unnamed, call_args$named)

@github-actions github-actions bot removed the awaiting response Waiting for issue author to respond label Jan 11, 2024
@SilenceBSun
Copy link
Author

This is the result from the reticulate :: py_last_error(), actually, I have just changed some labels. It seems that I fix the last problem, however, this is a new problem occurred now. I cannot ready the reticulate::py_last_error() currently, I am going to try.

@SilenceBSun
Copy link
Author

Actually, I find out it is a matrix type problem. I turn the data into matrix type (Original one is data frame). If I do not turn it into the a matrix type, the error will be the same as the first one.

@t-kalinowski
Copy link
Member

If you can condense the issue into a block of code that I can run to reproduce the error, I'm happy to take a look. (e.g., generating fake data with runif() or similar in the reprex).

@SilenceBSun
Copy link
Author

Hi, I have uploaded my code and data, which is made by myself. Because it is for my thesis, I prefer to delete it after you took a look. https://github.com/Vingoal/solid-octo-goggles

@t-kalinowski
Copy link
Member

  • the link doesn't work for me (I get 404)
  • Surely you can condense the issue into an MRE (and, odds are good that while condensing it down to a minimal reproducible example, you resolve the issue yourself :)

@SilenceBSun
Copy link
Author

Thank you for the reply, t-kalinowski. I am currently busy to work on other articles. Please give me some time to condense the issue into an MRE. I think I still need your help in the future. Have a nice day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants