coolzhao / Geo-SAM

A QGIS plugin tool using Segment Anything Model (SAM) to accelerate segmenting or delineating landforms in geospatial raster images.
MIT License
199 stars 26 forks source link

encode doesnt use cuda #8

Open 4del-Yousefi opened 11 months ago

4del-Yousefi commented 11 months ago

Hello, I have cuda installed however when I use the encode it uses CPU how to correctly install it for qgis?

it says:

SAM model initialized. SAM model type: vit_l Device type: cpu Patch size: (1024, 1024) Batch size: 1 Patch sample num: 4 Total batch num: 4

Fanchengyan commented 11 months ago

Hi, I think you may not install the python dependencies for the CUDA version. You can try to reinstall the torch torchvision torchaudio for the CUDA version following the readme. After installation, you can enter the following content in the Python terminal in QGIS to check if the GPU is available.

import torch
torch.cuda.is_available()
coolzhao commented 11 months ago

When installing gpu version PyTorch, add --force-reinstall if you installed the cpu version before.

shizurumaya commented 10 months ago

I encountered the same issue where the OSGeo4W Shell doesn't recognize my CUDA Windows system variable.

Executing the command "nvcc --version" works seamlessly in my standard Windows terminal and within environments like Conda/Mamba. However, it fails in OSGeo4W.

Solution: To resolve this, execute the following command in the OSGeo4W terminal. After doing so, you should be able to successfully run "nvcc --version":

set PATH=%PATH%;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.X\bin

(Please replace vX.X with your specific version of CUDA.)

For an automatic path load, I incorporated this command into the "C:\Program Files\QGIS 3.32.1\OSGeo4W.bat" file:

@echo off
rem Set the root OSGEO4W home directory to the directory where this script is located
call "%~dp0\bin\o4w_env.bat"

set PATH=%PATH%;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\bin
set PATH=%PATH%;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\libnvvp

rem List all available O4W programs
rem But only if osgeo4w is invoked without parameters
@echo on
@if [%1]==[] (echo Run o-help for a list of available commands & cd /d "%~dp0" & cmd.exe /k) else (cmd /c "%*")

Then I uninstall torch and torchvision and reinstall them :

pip uninstall torch torchvision
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117

(https://pytorch.org/ to get the command for installation)

It works for me.