Irrationone / cellassign

Automated, probabilistic assignment of cell types in scRNA-seq data
Other
191 stars 79 forks source link

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

Open keenhl opened 1 year ago

keenhl commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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?