BjornNyberg / Geometric-Attributes-Toolbox

The Geometric Attributes toolbox is a set of QGIS tools designed for the geometric attribute and shape characterization of modern depositional elements
GNU General Public License v3.0
67 stars 8 forks source link

Qgis problem instalation of SAM #17

Open ANDYAGUIRRE10 opened 1 year ago

ANDYAGUIRRE10 commented 1 year ago

Hello to everyone!

Environment Information samgeo version: 0.8.1 Python version: 3.11 Operating System: windows 8.1

Description I have installed the "Geometric Attributes" and I have followed the documentation. But this problem appears: image Then I tried to install it manually but in my windows terminal this was the problem: image

What I Did I tried to solve this upgrading "pip" in the terminal but the problem persists. So then I tried in pyhton.exe but I think I am not writing correctly the code: image

ANDYAGUIRRE10 commented 1 year ago

Then @BjornNyberg advised me that "This is a windows specific problem for the cython compiler. Make sure that you have updated microsoft visual studio to greater than 14 >. See here for more help.

What I Did First of all my windows system version es 8.1. So when I downloaded the microsoft visual studio, it warning me that I could have some problems. Making this clarification I continued, I could install it. But when I go to "Geometric Attributes" to continue with the process in Qgis (v. 3.28-Firenze) it presents the next problems: image

Greetings from Argentina!

Today I tried again to install SAM in QGIS with the option "Configure Segment Anything Model", and a new text box appears: image

BjornNyberg commented 1 year ago

@ANDYAGUIRRE10

I believe this error is related to the installation of the samgeo python package rather than anything to do with the plugin/QGIS. What error do you get if you try to manually install samgeo e.g.,

pip install segment-geospatial==0.5.0

One alternative here is to utilize Anaconda which will resolve a lot of the environmental issues in installing samgeo. However, this means that the execution will be python code based. I could try to implement this within the geometric attributes toolbox but im not sure what is the most feasible - user friendly approach here.

ANDYAGUIRRE10 commented 1 year ago

I am attaching some images to demonstrate that there were no problems with the manual installation. It seems that everything was fine. image image image

After this I go to the plugin but I get the same problem: image

It seems that I was not able to install samgeo correctly but no problem appears

What do you think @BjornNyberg? I could try the other approach you recommend. Thanks for the help!

BjornNyberg commented 1 year ago

@ANDYAGUIRRE10

Thanks for reporting. So it would appear that you have no trouble installing samgeo on your local python version, however the QGIS python version appears to be the issue?

If you try to manually pip install samgeo on the QGIS python version - do you get the same error?

ANDYAGUIRRE10 commented 1 year ago

Hello @BjornNyberg! I am trying now to resolve the issue now. The QGIS pyhton version that you refer is the Pyhton Console in Qgis, PyQgis? And other question, what Qgis version you recommend to install SAMGeo. Thanks!

jonasmumu commented 1 year ago

i have the same issue on windows. I have only c++ 2015+ installed. Someone can help me?

BjornNyberg commented 1 year ago

Hi both,

This appears to be an issue related the installation of the pycocotools module whereby a fatal python.h error is received. The underlying cause of this error is not know to me as I cannot seem to replicate it on my computer. I will try an investigate the issue further or potentially add an error bug on the main QGIS github for further clarification.

sanderllan commented 11 months ago

hi @BjornNyberg , any news about the installation problem in qgis linked to Python.h ?

image
BjornNyberg commented 11 months ago

@sanderllan Unfortunately the python.h error remains unresolved. I am open to suggestions as I cant seem to reproduce the problem myself.

ANDYAGUIRRE10 commented 11 months ago

Hi @BjornNyberg! I am trying again with the new geosam version (0.8.5). I just want to ask if the "source distribution" or "bult distribution" could be an element to solve this situation. I will download the source distribution from this page: https://pypi.org/project/segment-geospatial/#modal-close I will let you know how the process turns out. Thanks four your help and your work!

BjornNyberg commented 11 months ago

Hi again @ANDYAGUIRRE10

I do not believe that the source distribution is the cause of this error, but let me know what you find.

ANDYAGUIRRE10 commented 11 months ago

Well I just put the “segment-geospatial-0.8.5.tar” file in my “OS (C:)” folder. I don’t know if is neccesary to put this file in an specific folder and if unzip it too.

I tried again to install samgeo throuh Windows terminal. It asked me to upgrade pip: image Before I had some problems with this because several times it didn’t found the folder like this screenshot shows: image But then trying and trying with “pip install segment-geospatial” it let me to upgrade pip like first screenshot shows. So from the update done I typed again "pip install segment-geospatial" and it seems everything was fine: image

So I went to Qgis to taste de SAM plugin. Firts thing to note is that parameters in the window are not the same as you show in github, this is what appears. image I have not “Kernel size X” and “Kernel size Y”. Despite that, I tried to run the plugin but the error was the warning that you make, @BjornNyberg , about the rgb image. I can’t find the way to transform my image. It has a 30m x 30m spatial resolution and with 6 bands.

BjornNyberg commented 11 months ago

Hi @ANDYAGUIRRE10

Regarding the image, the input has to be a 3-band 8-bit image as requried by the ML input. Your 6-band image wont work im afraid. One way to fix this is to use the 'rearrange bands' tool available within the processing toolbar and select only 3 bands that you want to work with.

image

Alternatively, if you want to simply test the SAM installation, you can use the original image examples from META available here.

However, based on the screenshots that you have provided, im not sure if you have installed segment-geospatial on the QGIS python version or the windows python version? The kernel size x and y have been removed since version 0.4 of segment-geosptial and hence are not needed - the user guide is not up to date here but the remaining paramters should be the same.

BjornNyberg commented 11 months ago

@ANDYAGUIRRE10

I have been able to replicate the problem on another PC. I was able to resolve the problem by downloading QGIS 3.20.3-1.msi from here and using the configure tool. Can you confirm if this works for you? I have been unable to test 3.22, 3.24 or 3.26 at this time.

Another alternative to try is to open OSGeo4W from the start menu and installing via 'pip3 install segment-geospatial'

ANDYAGUIRRE10 commented 11 months ago

Hello @BjornNyberg !!! Thanks for your work! I will show you what I have done with your tips and tricks

1) I have tried with the first help you gave me. I could use the 'rearrange bands' tool correctly but this windows appeared. image

This first red line rememdered me the another issue open in GitHub “SAM – “WRNING! No GPU detected, reverting to CPU which may be slow”. Then this code appeared and it says several times that there is a problema with “torch”.

WARNING! No GPU detected, reverting to CPU which may be slow... Traceback (most recent call last): File "C:\Users/USER/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\geometric_attributes\SAM.py", line 248, in processAlgorithm sam.generate(source=inRaster, output=outputRaster,batch=batch) File "C:\Users\USER\AppData\Roaming\Python\Python39\site-packages\samgeo\samgeo.py", line 198, in generate masks = mask_generator.generate(image) # Segment the input image File "C:\Users\USER\AppData\Roaming\Python\Python39\site-packages\torch\utils_contextlib.py", line 115, in decorate_context return func(*args, *kwargs) File "C:\Users\USER\AppData\Roaming\Python\Python39\site-packages\segment_anything\automatic_mask_generator.py", line 163, in generate mask_data = self._generate_masks(image) File "C:\Users\USER\AppData\Roaming\Python\Python39\site-packages\segment_anything\automatic_mask_generator.py", line 206, in _generate_masks crop_data = self._process_crop(image, crop_box, layer_idx, orig_size) File "C:\Users\USER\AppData\Roaming\Python\Python39\site-packages\segment_anything\automatic_mask_generator.py", line 245, in _process_crop batch_data = self._process_batch(points, cropped_im_size, crop_box, orig_size) File "C:\Users\USER\AppData\Roaming\Python\Python39\site-packages\segment_anything\automatic_mask_generator.py", line 279, in _process_batch masks, ioupreds, = self.predictor.predict_torch( File "C:\Users\USER\AppData\Roaming\Python\Python39\site-packages\torch\utils_contextlib.py", line 115, in decorate_context return func(args, **kwargs) File "C:\Users\USER\AppData\Roaming\Python\Python39\site-packages\segment_anything\predictor.py", line 238, in predict_torch masks = self.model.postprocess_masks(low_res_masks, self.input_size, self.original_size) File "C:\Users\USER\AppData\Roaming\Python\Python39\site-packages\segment_anything\modeling\sam.py", line 161, in postprocess_masks masks = F.interpolate(masks, original_size, mode="bilinear", align_corners=False) File "C:\Users\USER\AppData\Roaming\Python\Python39\site-packages\torch\nn\functional.py", line 3959, in interpolate return torch._C._nn.upsample_bilinear2d(input, output_size, align_corners, scale_factors) RuntimeError: [enforce fail at C:\actions-runner_work\pytorch\pytorch\builder\windows\pytorch\c10\core\impl\alloc_cpu.cpp:72] data. DefaultCPUAllocator: not enough memory: you tried to allocate 75420812544 bytes. Execution failed after 455.84 segundos (7 minutos 36 segundos)

2) With the image you provided this was the result. I could charge the image in Qgis, maybe there is a problema with the SRC but it is not improtant now. SAM took 24 minutes to process the image and it generated a mask as a raster. It also generated a polygon vector with 129 elements and two columns (fid – value) but these elements doesn’t appear. image image

So it looks that it is working, but with the satellite image didn’t work.

Now I am trying with the other options that yo recommend, 3) installed segment-geospatial on the QGIS python version or the windows python versión and 4) taste QGIS 3.20.3-1.msi and finally 5) OSGeo4W like an another way.

BjornNyberg commented 11 months ago

Hi @ANDYAGUIRRE10

Great that you got the segment-geospatial module installed - no need to install any other QGIS version! The warning that you receive is telling you that your GPU is not compatible and therefore uses the CPU. As you mention this may be a bug - check to see if your GPU is CUDA 11.7+ compatiable from the NVIDIA documentation.

  1. Regarding the problem with torch - you are trying to use 70GB of ram! This is likely because your satellite image is big and the algorithm is trying to process the image as one big raster. Try to implement the batch processing option and/or use a low "Points Per Batch:" and "Points Per Side" value.
  2. The dog image shows that the tool is working. However, as you state it does not have a coordinate system and hence the polygonization fails.
ANDYAGUIRRE10 commented 11 months ago

Thank you @BjornNyberg. 4) Before your answer I just want to add that I have installed Qgis 3.20.3-1.msi in another computer, But the installation of SAMGEO from Geometric Atributes failed too. I wanted to install through cmd. and terminal but it doesn't recognize the code (pip install segment-geospatial) image

NOW, if the plugin is working I will try your recomendations about GPU and to work with an smaller image.

About GPU, I really doesn't know much about this, but searching on internet I tried to find my GPU here but it doesn't appear I think: image

BjornNyberg commented 11 months ago

@ANDYAGUIRRE10

Good to know that the installation of QGIS 3.20 may not be a solution.

Regarding the GPU - based on the image that you have provided it would seem that your computer does not have a graphics card. If it did it would look a little bit like this.

image

This means that your processing capabilities will be severely reduced. One option is to create a virtual machine on the cloud that does have a GPU.

ANDYAGUIRRE10 commented 11 months ago

Hello @BjornNyberg I have some great news! I had to work in another computer to solve my problem. It has a GPU memory but I don't know if it is compatible with CUDA 11.7+. Attached an screenshot of this other equipment: image

The geo-sam installation was successful when I did it manually. Not the case fom QGIS because it frozed. Despite that, as I said I was able to install it: image

So I tried the plugin and it worked!!! What I am seeing is that I am having issues with large images and in those cases the plugin fails. So if I clip the image to 3 mb for example it works as shown in these images: image image

Really, is too neccesary to have this GPU and a good memory because on my computer this process is too long, one hour or more with the same image.

Thanks for all your help @BjornNyberg. I just have some questions, for example, how to use the different parameters because as you can see there are elements that weren't vectorized, or that the shape of the edges is like a square because of the pixels that make up the satellite image.

Your work is awesome. I will continue exploring the parameters to improve the segmentation. I will also be ttentive to the improvements you make in QGIS. Thanks a lot!

BjornNyberg commented 11 months ago

@ANDYAGUIRRE10

To check your CUDA compatibility check out this link or use the NVIDIA Control panel and press system information.

senaygor commented 1 month ago

I am facing an issue while running SAM in QGIS, even after downloading the checkpoint and manually placing it in the folder

Versão do QGIS: 3.36.1-Maidenhead Código de revisão do QGIS: 3e589453 Versão do Qt: 5.15.3 Versão do Python: 3.9.18 Versão do GDAL: 3.8.4 Versão do GEOS: 3.12.1-CAPI-1.18.1 Versão do PROJ: Rel. 9.3.1, December 1st, 2023 Versão PDAL: 2.6.0 (git-version: 3fced5) Algoritmo iniciado as: 2024-05-04T22:32:57 Algoritmo 'Segment Anything Model (SAM)' iniciando… Entrada de parâmetros: { 'Checkpoints' : 0, 'Mask' : 'TEMPORARY_OUTPUT', 'Polygons' : 'TEMPORARY_OUTPUT', 'Raster' : 'C:/Users/Intelligeo/Documents/PUB - SAM/Rasters/Morro da Baleia/MorrodaBaleia_RGB.tif', 'batch' : False, 'box_nms_thresh' : None, 'crop_n_layers' : None, 'crop_n_points_downscale_factor' : None, 'crop_nms_thresh' : None, 'crop_overlap_ratio' : None, 'min_mask_region_area' : None, 'points_per_batch' : None, 'points_per_side' : None, 'pred_iou_thresh' : None, 'stability_score_offset' : None, 'stability_score_thresh' : None, 'unique' : True }

Failed to load python modules for SAM predictions. Try using the configure tool or manually install the segment-geospatial package using pip install segment-geospatial. Execution completed in 0.03 segundos