kpcoleman / SpaDecon

MIT License
6 stars 1 forks source link

'keras.src.engine.functional' has no attribute 'Functional' #1

Open jamesboot opened 11 months ago

jamesboot commented 11 months ago

Hello,

Thanks for creating this package. I've installed and trying to run the tutorial data before starting on my own data. My script is as follows:

# This is a Python script for running SpaDecon

# Load packages
import SpaDecon as spd
import scanpy as sc
import pandas as pd
import numpy as np
from skimage import io
import os

# set working directory to spadecon_tutorial_data using os.chdir()
os.chdir('/path/to/spadecon_tutorial_data')

#Read annotated scRNA-seq GE data (observations = cells, variables = genes, cell types in adata_sc.obs.celltype)
adata_sc = sc.read('bc_sc.h5ad')

# Read SRT GE data (observations = spots, variables = genes)
adata_srt = sc.read_10x_h5('V1_Breast_Cancer_Block_A_Section_1_filtered_feature_bc_matrix.h5')
adata_srt.var_names_make_unique()

#Read SRT histology image
histology = io.imread("V1_Breast_Cancer_Block_A_Section_1_image.tif")

#Read file with SRT spatial locations
locations = pd.read_csv("tissue_positions_list.csv",header=None,index_col=0)
locations = locations.loc[adata_srt.obs.index]

clf = spd.SpaDecon()
clf.deconvolution(source_data=adata_sc, target_data=adata_srt, histology_image=histology, spatial_locations=locations)
spadecon_proportions = clf.props
spadecon_proportions.to_csv('spadecon_proportions.csv')

#Run SpaDecon
clf = spd.SpaDecon()
clf.deconvolution(source_data=adata_sc, target_data=adata_srt, histology_image=histology, spatial_locations=locations)
spadecon_proportions = clf.props
spadecon_proportions.to_csv('spadecon_proportions.csv')

The error I am getting is:

AttributeError: partially initialized module 'keras.src.engine.functional' has no attribute 'Functional' (most likely due to a circular import)

Further traceback showed:

File "/anaconda3/envs/SpaDecon/lib/python3.11/site-packages/keras/src/engine/sequential.py", line 48, in <module>
    class Sequential(functional.Functional):
                     ^^^^^^^^^^^^^^^^^^^^^
AttributeError: partially initialized module 'keras.src.engine.functional' has no attribute 'Functional' (most likely due to a circular import)

Any help would be greatly appreciated! Cheers

kpcoleman commented 11 months ago

Hi James,

Thank you for your interest in SpaDecon. Could you please let me know which version of keras you have installed?

Best, Kyle

jamesboot commented 11 months ago

Hi Kyle,

I have 2.13.1 installed.

Cheers James

kpcoleman commented 11 months ago

Hi James,

I think this may be an issue with the version of keras installed. Can you install keras version 2.2.4 and the versions of the other dependencies listed in the README file and see if this solves the problem? The versions are also listed here:

keras==2.2.4 pandas==1.2.4 numpy==1.20.1 scipy==1.6.2 scanpy==1.7.0 anndata==0.7.6 sklearn==1.0.2 tensorflow==1.14.0

Best, Kyle

jamesboot commented 11 months ago

Unfortunately I'm having trouble installing these versions of the packages. For numpy and pandas I'm getting the following error:

ERROR: Failed building wheel for pandas / numpy

And when I specify version 1.14.0 for tensorflow:

ERROR: No matching distribution found for tensorflow==1.14.0

I'll keep trying

jamesboot commented 11 months ago

Rolled back to python version 3.8. Install of all package versions was fine, but no version found for tensorflow 1.14.0

kpcoleman commented 11 months ago

Looks like tensorflow 1.14.0 isn't compatible with python 3.8. Can you try installing python 3.7 instead?

jamesboot commented 11 months ago

Tried with 3.7 but no matching distribution found for pandas==1.2.4, same problem with python 3.6

kpcoleman commented 11 months ago

Which release of python 3.7 are you using? pandas 1.2.4 should be compatible with any python version of at least 3.7.1. I would recommend installing 3.7.11, since that is the release used for obtaining the results in the tutorial.

jamesboot commented 11 months ago

3.7.11 did the trick! All installed. I'll try running the tutorial script and confirm its all working but I imagine that should be it. Thanks for your patience.