rstudio / tensorflow

TensorFlow for R
https://tensorflow.rstudio.com
Apache License 2.0
1.33k stars 318 forks source link

Error in py_get_attr_impl(x, name, silent): AttributeError: module 'tensorflow._api.v2.compat.v2.__internal__' has no attribute 'monitoring' #570

Closed AlphaLX closed 1 year ago

AlphaLX commented 1 year ago

I meet an error when using the cellassign R package,

fit <- cellassign(exprs_obj = sce[rownames(rho),], #rows are genes, columns are cells
                    marker_gene_info = rho,
                    learning_rate = 1e-2,
                    s = s,
                    shrinkage = TRUE,
                    verbose = FALSE)

And it shows this error

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)

And my R sessionInfo is

R version 4.2.3 (2023-03-15)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS

Matrix products: default
BLAS/LAPACK: /home/user/anaconda3/envs/r423-p38/lib/libopenblasp-r0.3.21.so

locale:
 [1] LC_CTYPE=en_SG.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_SG.UTF-8        LC_COLLATE=en_SG.UTF-8    
 [5] LC_MONETARY=en_SG.UTF-8    LC_MESSAGES=en_SG.UTF-8   
 [7] LC_PAPER=en_SG.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_SG.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] tensorflow_2.11.0           SpatialAnno_1.0.0          
 [3] mclust_6.0.0                cellassign_0.99.2          
 [5] SingleCellExperiment_1.20.0 SummarizedExperiment_1.28.0
 [7] Biobase_2.58.0              GenomicRanges_1.50.0       
 [9] GenomeInfoDb_1.34.8         IRanges_2.32.0             
[11] S4Vectors_0.36.0            BiocGenerics_0.44.0        
[13] MatrixGenerics_1.10.0       matrixStats_0.63.0         
[15] psych_2.3.3                

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10            pillar_1.9.0           compiler_4.2.3        
 [4] XVector_0.38.0         zlibbioc_1.44.0        base64enc_0.1-3       
 [7] bitops_1.0-7           tools_4.2.3            digest_0.6.31         
[10] uuid_1.1-0             jsonlite_1.8.4         evaluate_0.20         
[13] lifecycle_1.0.3        nlme_3.1-162           lattice_0.21-8        
[16] png_0.1-8              rlang_1.1.0            Matrix_1.5-4          
[19] DelayedArray_0.24.0    IRdisplay_1.1          cli_3.6.1             
[22] IRkernel_1.3           parallel_4.2.3         fastmap_1.1.1         
[25] GenomeInfoDbData_1.2.9 repr_1.1.4             rappdirs_0.3.3        
[28] vctrs_0.6.1            grid_4.2.3             reticulate_1.25       
[31] glue_1.6.2             fansi_1.0.4            pbdZMQ_0.3-7          
[34] magrittr_2.0.3         whisker_0.4.1          tfruns_1.5.0          
[37] htmltools_0.5.5        mnormt_2.1.1           utf8_1.2.3            
[40] RCurl_1.98-1.12        crayon_1.5.2          

My tensorflow version is 2.4.1, not the same shown in R attached packages. And the tensorflow-probability version is 0.12.0, numpy version is 1.23.

I added the two commands to use v1 module of tensorflow, because the package is written under tensorflow1.x,

tf$reset_default_graph <- tf$compat$v1$reset_default_graph 
tf$contrib <- tf$compat$v1$estimator 
t-kalinowski commented 1 year ago

Hi, can you please provide a reprex so I could reproduce the issue locally? Ideally without the cellassign R package, only using the tensorflow.

github-actions[bot] commented 1 year ago

Automatically closed because there has not been a response for 30 days. When you're ready to work on this further, please comment here and the issue will automatically reopen.