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

module 'tensorflow' has no attribute 'reset_default_graph' #100

Open
keenhl opened this issue Feb 27, 2023 · 4 comments
Open

module 'tensorflow' has no attribute 'reset_default_graph' #100

keenhl opened this issue Feb 27, 2023 · 4 comments

Comments

@keenhl
Copy link

keenhl commented Feb 27, 2023

I have Tensorflow installed. When I check the version, it is 2.12.

tensorflow::tf_config()

2023-02-27 15:55:21.780906: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.

To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
TensorFlow v2.12.0-rc0 (/opt/miniconda3/envs/tf/lib/python3.11/site-packages/tensorflow)
Python v3.11 (
/opt/miniconda3/envs/tf/bin/python)

When I try to run

fit <- cellassign(exprs_obj = gexp,
marker_gene_info = markers,
s = s,
learning_rate = 1e-2,
shrinkage = TRUE,
verbose = FALSE)

I get this error.

Error in py_get_attr_impl(x, name, silent) : AttributeError: module 'tensorflow' has no attribute 'reset_default_graph'

Thank you for your help trying to figure out this error.

@keenhl
Copy link
Author

keenhl commented Feb 28, 2023

I redid with a different configuration of of TensorFlow and Python thinking that might help. I still get the same error.

TensorFlow v2.11.0 (/opt/miniconda3/envs/tf3/lib/python3.7/site-packages/tensorflow)
Python v3.7 (
/opt/miniconda3/envs/tf3/bin/python)

Error in py_get_attr_impl(x, name, silent) : AttributeError: module 'tensorflow' has no attribute 'reset_default_graph'

@keenhl
Copy link
Author

keenhl commented Feb 28, 2023

If I do this as suggested at the link.
tf$reset_default_graph <- tf$compat$v1$reset_default_graph

https://github.com/rstudio/keras/issues/890

I get the following error

AttributeError: module 'tensorflow' has no attribute 'contrib'

@keenhl
Copy link
Author

keenhl commented Feb 28, 2023

I redid with a third different configuration of of TensorFlow and Python thinking that might help. I still get the same error.

TensorFlow v2.1.0 ()
Python v3.6 (~/Library/r-miniconda/envs/r-reticulate/bin/python)

Error in py_get_attr_impl(x, name, silent) : AttributeError: module 'tensorflow' has no attribute 'reset_default_graph'

@AlphaLX
Copy link

AlphaLX commented Apr 21, 2023

I added the two commands and the error was fixed.

tf$reset_default_graph <- tf$compat$v1$reset_default_graph 
tf$contrib <- tf$compat$v1$estimator 

But now I meet new issues,
fit <- cellassign(exprs_obj = sce[rownames(rho),], marker_gene_info = rho, learning_rate = 1e-2, s = s, shrinkage = TRUE, verbose = FALSE)
Error in py_get_attr_impl(x, name, silent): AttributeError: module 'tensorflow._api.v2.compat.v2.__internal__' has no attribute 'monitoring'

Traceback:

  1. cellassign(exprs_obj = sce[rownames(rho), ], marker_gene_info = rho,
    . learning_rate = 0.01, s = s, shrinkage = TRUE, verbose = FALSE)
  2. lapply(seq_len(num_runs), function(i) {
    . res <- inference_tensorflow(Y = Y, rho = rho, s = s, X = X,
    . G = G, C = C, N = N, P = P, B = B, shrinkage = shrinkage,
    . verbose = verbose, n_batches = n_batches, rel_tol_adam = rel_tol_adam,
    . rel_tol_em = rel_tol_em, max_iter_adam = max_iter_adam,
    . max_iter_em = max_iter_em, learning_rate = learning_rate,
    . min_delta = min_delta, dirichlet_concentration = dirichlet_concentration)
    . return(structure(res, class = "cellassign_fit"))
    . })
  3. FUN(X[[i]], ...)
  4. inference_tensorflow(Y = Y, rho = rho, s = s, X = X, G = G, C = C,
    . N = N, P = P, B = B, shrinkage = shrinkage, verbose = verbose,
    . n_batches = n_batches, rel_tol_adam = rel_tol_adam, rel_tol_em = rel_tol_em,
    . max_iter_adam = max_iter_adam, max_iter_em = max_iter_em,
    . learning_rate = learning_rate, min_delta = min_delta, dirichlet_concentration = dirichlet_concentration)
  5. tf$contrib$distributions
  6. `$.python.builtin.module`(tf$contrib, "distributions")
  7. `$.python.builtin.object`(x, name)
  8. py_get_attr_or_item(x, name, TRUE)
  9. py_get_attr(x, name)
  10. py_get_attr_impl(x, name, silent)

My tensorflow version is 2.4.1, the numpy version is 1.23 and tensorflow-probability version is 1.12.0. All the packages are installed under the website's guide, and I don't know where is the problem?

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

No branches or pull requests

2 participants