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

ImportError: DLL load failed while importing _version #841

Open
wqfcv opened this issue Nov 28, 2024 · 9 comments
Open

ImportError: DLL load failed while importing _version #841

wqfcv opened this issue Nov 28, 2024 · 9 comments
Assignees

Comments

@wqfcv
Copy link

wqfcv commented Nov 28, 2024

Install using standard conda approach:

conda create -n deepforest python=3 pytorch torchvision cudatoolkit=10.2 -c pytorch
conda activate deepforest
conda install deepforest -c conda-forge

Then do some basic stuff. I ran this, not sure exact failure point:

from deepforest import main
from deepforest import get_data
from deepforest import visualize
import matplotlib.pyplot as plt
from deepforest.visualize import plot_predictions

model = main.deepforest()
model.load_model(model_name="weecology/deepforest-tree", revision="main")
raster_path = get_data("result.tif")
predicted_raster = model.predict_tile(raster_path, patch_size=300, patch_overlap=0.25,return_plot=True)
PS C:\Users\18774> & D:/anaconda/envs/deepforest/python.exe d:/treeDetection/tree_identify.py
Traceback (most recent call last):
  File "d:\treeDetection\tree_identify.py", line 1, in <module>
    from deepforest import main
  File "D:\anaconda\envs\deepforest\Lib\site-packages\deepforest\main.py", line 12, in <module>
    from deepforest import utilities
  File "D:\anaconda\envs\deepforest\Lib\site-packages\deepforest\utilities.py", line 10, in <module>
    import rasterio
  File "D:\anaconda\envs\deepforest\Lib\site-packages\rasterio\__init__.py", line 28, in <module>
    from rasterio._version import gdal_version, get_geos_version, get_proj_version
ImportError: DLL load failed while importing _version: 找不到指定的程序。

@bw4sz
Copy link
Collaborator

bw4sz commented Nov 28, 2024

Thanks for reporting, can you print out info from conda list, it will tell us about package versions. Rasterio interacts with gdal, this is upstream of DeepForest and definitely particular to your own install. Start by creating an env, install rasterio https://rasterio.readthedocs.io/en/stable/installation.html and confirm you can achieve that first. I'll leave this open, but i'm not convinced there is anything we can do from DeepForest perspective.

@ethanwhite ethanwhite added the Awaiting author contribution Waiting on the issue author to do something before proceeding label Dec 4, 2024
@wqfcv
Copy link
Author

wqfcv commented Dec 10, 2024

# packages in environment at D:\anaconda\envs\DeepForest:
#
# Name                    Version                   Build  Channel
affine                    2.4.0              pyhd8ed1ab_0    conda-forge
alabaster                 1.0.0              pyhd8ed1ab_0    conda-forge
aom                       3.5.0                h63175ca_0    conda-forge
attrs                     24.2.0             pyh71513ae_0    conda-forge
babel                     2.16.0             pyhd8ed1ab_0    conda-forge
blas                      1.0                         mkl    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
blosc                     1.21.3               h6c2663c_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
boost-cpp                 1.82.0               h59b6b97_2    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
bottleneck                1.4.2           py312h4b0e54e_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
branca                    0.7.2              pyhd8ed1ab_0    conda-forge
brotli                    1.0.9                hcfcfb64_9    conda-forge
brotli-bin                1.0.9                hcfcfb64_9    conda-forge
brotli-python             1.0.9           py312hd77b12b_8    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
bzip2                     1.0.8                h2bbff1b_6    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
ca-certificates           2024.9.24            haa95532_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
cairo                     1.16.0            hb19e0ff_1008    conda-forge
certifi                   2024.8.30          pyhd8ed1ab_0    conda-forge
cfitsio                   3.470                h0af3d06_7    conda-forge
charls                    2.2.0                h39d44d4_0    conda-forge
charset-normalizer        3.3.2              pyhd3eb1b0_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
click                     8.1.7           win_pyh7428d3b_0    conda-forge
click-plugins             1.1.1                      py_0    conda-forge
cligj                     0.7.2              pyhd8ed1ab_1    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
commonmark                0.9.1                      py_0    conda-forge
contourpy                 1.3.1           py312h214f63a_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
cudatoolkit               10.2.89              h74a9793_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
cycler                    0.12.1             pyhd8ed1ab_0    conda-forge
dav1d                     1.2.1                hcfcfb64_0    conda-forge
deepforest                1.1.3              pyh8a188c0_0    conda-forge
docutils                  0.21.2             pyhd8ed1ab_0    conda-forge
exceptiongroup            1.2.2              pyhd8ed1ab_0    conda-forge
expat                     2.6.3                h5da7b33_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
filelock                  3.13.1          py312haa95532_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
fiona                     1.9.5           py312hc7c4135_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
folium                    0.18.0             pyhd8ed1ab_0    conda-forge
fontconfig                2.14.1               hb33846d_3    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
fonttools                 4.55.0             pyhe1237c8_0    conda-forge
freetype                  2.12.1               ha860e81_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
freexl                    2.0.0                h8276f4a_0    conda-forge
fsspec                    2024.10.0          pyhff2d567_0    conda-forge
future                    1.0.0              pyhd8ed1ab_0    conda-forge
gdal                      3.6.2           py312h8827949_7    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
geopandas                 0.14.4             pyhd8ed1ab_0    conda-forge
geopandas-base            0.14.4             pyha770c72_0    conda-forge
geos                      3.8.0                he025d50_1    conda-forge
geotiff                   1.7.0                h4545760_3    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
giflib                    5.2.2                h7edc060_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
h5py                      3.12.1          py312h3b2c811_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
hdf4                      4.2.13            h0e5069d_1005    conda-forge
hdf5                      1.12.1               h51c971a_3    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
icc_rt                    2022.1.0             h6049295_2    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
icu                       68.2                 h0e60522_0    conda-forge
idna                      3.7             py312haa95532_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
imagecodecs               2023.1.23       py312hd5bf116_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
imagesize                 1.4.1              pyhd8ed1ab_0    conda-forge
iniconfig                 2.0.0              pyhd8ed1ab_0    conda-forge
intel-openmp              2023.1.0         h59b6b97_46320    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
jinja2                    3.1.4           py312haa95532_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
joblib                    1.4.2              pyhd8ed1ab_0    conda-forge
jpeg                      9e                   h827c3e9_3    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
kealib                    1.5.0                hde4a422_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
kiwisolver                1.4.4           py312hd77b12b_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
krb5                      1.20.1               heb0366b_0    conda-forge
lcms2                     2.12                 h83e58a3_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
lerc                      3.0                  hd77b12b_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libaec                    1.1.3                h63175ca_0    conda-forge
libavif                   0.11.1               ha7b97ba_2    conda-forge
libboost                  1.82.0               h3399ecb_2    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libbrotlicommon           1.0.9                hcfcfb64_9    conda-forge
libbrotlidec              1.0.9                hcfcfb64_9    conda-forge
libbrotlienc              1.0.9                hcfcfb64_9    conda-forge
libcurl                   8.9.1                h0416ee5_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libdeflate                1.17                 h2bbff1b_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libexpat                  2.6.3                he0c23c2_0    conda-forge
libffi                    3.4.4                hd77b12b_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libgdal                   3.6.2                h0e70117_7    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libglib                   2.78.4               ha17d25a_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libiconv                  1.17                 hcfcfb64_2    conda-forge
libjpeg-turbo             2.0.0                h196d8e1_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libkml                    1.3.0                h63940dd_7    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libnetcdf                 4.8.1                h6685c40_4    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libpng                    1.6.39               h8cc25b3_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libpq                     17.0                 h70ee33d_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libspatialindex           1.9.3                h5a68840_5    conda-forge
libspatialite             5.1.0                h25d3e1c_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libssh2                   1.10.0               h9a1e1f7_2    conda-forge
libtiff                   4.5.1                hd77b12b_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libuv                     1.48.0               h827c3e9_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libwebp                   1.3.2                hbc33d0d_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libwebp-base              1.3.2                h3d04722_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libxml2                   2.13.5               h24da03e_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
libzip                    1.8.0                h519de47_1    conda-forge
libzopfli                 1.0.3                h0e60522_0    conda-forge
lightning-utilities       0.11.9             pyhff2d567_0    conda-forge
lz4-c                     1.9.4                h2bbff1b_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
mapclassify               2.8.1              pyhd8ed1ab_0    conda-forge
markupsafe                2.1.3           py312h2bbff1b_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
matplotlib-base           3.9.2           py312he19b0ae_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
minizip                   4.0.3                hb68bac4_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
mkl                       2023.1.0         h6b88ed4_46358    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
mkl-service               2.4.0           py312h2bbff1b_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
mkl_fft                   1.3.11          py312h827c3e9_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
mkl_random                1.2.8           py312h0158946_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
mpmath                    1.3.0           py312haa95532_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
networkx                  3.2.1           py312haa95532_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
numexpr                   2.10.1          py312h4cd664f_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
numpy                     1.26.4          py312hfd52020_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
numpy-base                1.26.4          py312h4dde369_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
numpydoc                  1.8.0              pyhd8ed1ab_0    conda-forge
openjpeg                  2.5.2                hae555c5_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
openssl                   3.4.0                h2466b09_0    conda-forge
packaging                 24.2               pyhff2d567_1    conda-forge
pandas                    2.2.3           py312h5da7b33_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
pcre2                     10.42                h0ff8eda_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
pillow                    11.0.0          py312hb5480e2_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
pip                       24.2            py312haa95532_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
pixman                    0.43.4               h63175ca_0    conda-forge
pluggy                    1.5.0              pyhd8ed1ab_0    conda-forge
poppler                   24.09.0              h4f47ea2_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
poppler-data              0.4.12               hd8ed1ab_0    conda-forge
proj                      9.3.1                ha107b6e_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
psutil                    5.9.0           py312h2bbff1b_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
pygments                  2.18.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.2.0              pyhd8ed1ab_1    conda-forge
pyproj                    3.6.1           py312h8115771_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
pysocks                   1.7.1           py312haa95532_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
pytest                    8.3.3              pyhd8ed1ab_0    conda-forge
python                    3.12.7               h14ffc60_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
python-dateutil           2.9.0.post0        pyhff2d567_0    conda-forge
python-tzdata             2024.2             pyhd8ed1ab_0    conda-forge
pytorch                   2.5.1              py3.12_cpu_0    pytorch
pytorch-lightning         2.4.0              pyhd8ed1ab_0    conda-forge
pytorch-mutex             1.0                         cpu    pytorch
pytz                      2024.2             pyhd8ed1ab_0    conda-forge
pyyaml                    6.0.2           py312h827c3e9_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
qhull                     2020.2               hc790b64_5    conda-forge
rasterio                  1.3.10          py312hca534e7_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
recommonmark              0.7.1              pyhd8ed1ab_0    conda-forge
requests                  2.32.3          py312haa95532_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
rtree                     1.0.1           py312h2eaa2aa_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
scikit-learn              1.5.1           py312h0158946_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
scipy                     1.14.1          py312h9d85e7c_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
setuptools                72.1.0          py312haa95532_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
shapely                   2.0.5           py312h4059a34_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
six                       1.16.0             pyh6c4a22f_0    conda-forge
slidingwindow             0.0.14             pyh9f0ad1d_0    conda-forge
snappy                    1.2.1                h23299a8_0    conda-forge
snowballstemmer           2.2.0              pyhd8ed1ab_0    conda-forge
snuggs                    1.4.7              pyhd8ed1ab_1    conda-forge
sphinx                    8.1.3              pyhd8ed1ab_0    conda-forge
sphinxcontrib-applehelp   2.0.0              pyhd8ed1ab_0    conda-forge
sphinxcontrib-devhelp     2.0.0              pyhd8ed1ab_0    conda-forge
sphinxcontrib-htmlhelp    2.1.0              pyhd8ed1ab_0    conda-forge
sphinxcontrib-jsmath      1.0.1              pyhd8ed1ab_0    conda-forge
sphinxcontrib-qthelp      2.0.0              pyhd8ed1ab_0    conda-forge
sphinxcontrib-serializinghtml 1.1.10             pyhd8ed1ab_0    conda-forge
sqlite                    3.45.3               h2bbff1b_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
sympy                     1.13.2          py312haa95532_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
tabulate                  0.9.0              pyhd8ed1ab_1    conda-forge
tbb                       2021.8.0             h59b6b97_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
threadpoolctl             3.5.0              pyhc1e730c_0    conda-forge
tiledb                    2.3.3                hd8964de_3    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
tk                        8.6.14               h0416ee5_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
tomli                     2.1.0              pyhff2d567_0    conda-forge
torchmetrics              1.5.2              pyhe5570ce_0    conda-forge
torchvision               0.20.1                py312_cpu    pytorch
tqdm                      4.67.1             pyhd8ed1ab_0    conda-forge
typing-extensions         4.11.0          py312haa95532_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
typing_extensions         4.11.0          py312haa95532_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
tzdata                    2024b                h04d1e81_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
ucrt                      10.0.22621.0         h57928b3_1    conda-forge
unicodedata2              15.1.0          py312h2bbff1b_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
uriparser                 0.9.8                h5a68840_0    conda-forge
urllib3                   2.2.3           py312haa95532_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
vc                        14.40                h2eaa2aa_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
vc14_runtime              14.42.34433         he29a5d6_23    conda-forge
vs2015_runtime            14.42.34433         hdffcdeb_23    conda-forge
wheel                     0.44.0          py312haa95532_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
win_inet_pton             1.1.0           py312haa95532_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
xerces-c                  3.2.5                he0c23c2_2    conda-forge
xmltodict                 0.14.2             pyhd8ed1ab_0    conda-forge
xyzservices               2024.9.0           pyhd8ed1ab_0    conda-forge
xz                        5.4.6                h8cc25b3_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
yaml                      0.2.5                he774522_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
zfp                       1.0.1                he0c23c2_2    conda-forge
zlib                      1.2.13               h8cc25b3_1    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
zstd                      1.5.6                h8880b57_0    https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main

@github-actions github-actions bot removed the Awaiting author contribution Waiting on the issue author to do something before proceeding label Dec 10, 2024
@henrykironde
Copy link
Contributor

@wqfcv, thank you for reaching out! Could you please run the following commands and share the output with us? This will help us diagnose the issue more effectively:

python -c "import rasterio; print(rasterio.__version__)"
gdalinfo --version

Looking forward to your response!

@wqfcv
Copy link
Author

wqfcv commented Dec 11, 2024

(deepForest) C:\Users\18774>python -c "import rasterio; print(rasterio.__version__)"
1.3.10

(deepForest) C:\Users\18774>gdalinfo --version
GDAL 3.6.2, released 2023/01/02

@henrykironde
Copy link
Contributor

@wqfcv The issue likely stems from your environment, particularly how GDAL and Rasterio are installed. To resolve this, I recommend updating Conda and creating a fresh environment. Then, install DeepForest using pip instead of Conda. Here's how:

conda create -n new_deepforest python=3.9
conda activate new_deepforest
conda install -c pytorch pytorch torchvision cudatoolkit=10.2
conda install -c conda-forge rasterio gdal
pip install deepforest

Once the setup is complete, try the example provided in the DeepForest documentation:
Predicting Large Tiles Tutorial

Also raster_path = get_data("result.tif") should be used for inbuilt data https://github.com/weecology/DeepForest/tree/main/src/deepforest/data .

@wqfcv
Copy link
Author

wqfcv commented Dec 12, 2024

Thank you for your help. I have successfully installed DeepForest. But there seems to be an issue in the example code. Here's code:

from deepforest import main
from deepforest import get_data
import matplotlib.pyplot as plt


def main_program():
    # Initialize the model class
    model = main.deepforest()

    # Load a pretrained tree detection model from Hugging Face
    model.load_model(model_name="weecology/deepforest-tree", revision="main")

    # Predict on large geospatial tiles using overlapping windows
    raster_path = get_data("OSBS_029.tif")
    predicted_raster = model.predict_tile(raster_path, patch_size=300, patch_overlap=0.25)

    # Optional: Visualize or save the predicted raster (add your plotting or saving logic here)
    print(predicted_raster)
    plot_results(results)


if __name__ == '__main__':
    main_program()

Here's error:

Traceback (most recent call last):
  File "D:\treeDetection\test.py", line 23, in <module>
    main_program()
  File "D:\treeDetection\test.py", line 19, in main_program
    plot_results(results)
NameError: name 'plot_results' is not defined

@henrykironde
Copy link
Contributor

You are using and old version. Use pip uninstall deepforeset and then pip install deepforest -U

@wqfcv
Copy link
Author

wqfcv commented Dec 16, 2024

Thank you for your help. I can now use plot_results normally. But after running the following code, no image was displayed in pycharm.

from deepforest import main
from deepforest import get_data
import matplotlib.pyplot as plt
from deepforest.visualize import plot_results
import rasterio

def main_program():

    savedir = r'D:\\treeDetection\\test.tif'
    # Initialize the model class
    model = main.deepforest()


    # Load a pretrained tree detection model
    model.load_model(model_name="weecology/deepforest-tree", revision="main")

    # Input raster path
    raster_path = get_data("OSBS_029.tif")
    print(f"Raster Path: {raster_path}")

    # Open the raster image using rasterio
    with rasterio.open(raster_path) as src:
        image = src.read([1, 2, 3]).transpose(1, 2, 0)  # Read RGB channels

    # Generate predictions
    predicted_raster = model.predict_tile(raster_path, patch_size=300, patch_overlap=0.25)
    print(predicted_raster)

    # Visualize predictions on the image
    # plot_results(predicted_raster,savedir=savedir)
    plot_results(predicted_raster)
    # plt.show()

if __name__ == '__main__':
    main_program()

@henrykironde
Copy link
Contributor

@wqfcv I don't think PyCharm will display the images. The images usually pop up as their own Gui window trying to look for any extra icon / application on the task bar.

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

4 participants