Git Product home page Git Product logo

yarroudh / segment-lidar Goto Github PK

View Code? Open in Web Editor NEW
322.0 322.0 35.0 25.01 MB

Python package for segmenting LiDAR data using Segment-Anything Model (SAM) from Meta AI.

Home Page: https://yarroudh.github.io/segment-lidar/

License: BSD 3-Clause "New" or "Revised" License

Python 85.76% Dockerfile 1.86% TeX 12.38%
artificial-intelligence deep-learning lidar machine-learning python segmentation

segment-lidar's Introduction

segment-lidar's People

Contributors

yarroudh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

segment-lidar's Issues

sample data?

Hi, appreciate if you could provide few sample data to test this package

where to find raster.tif and labels.tif for pointcloud.las example

hi there Yarroudh,
Can you please help me understand where should I retrieve: raster.tif and labels.tif related to the pointcloud.las example given, in order to run one of the lines from the tutorial.
labels, *_ = model.segment(points=points, view=viewpoint, image_path="raster.tif", labels_path="labeled.tif")
model.write(points=points, segment_ids=labels, save_path="segmented.las")

thank you so much

An bug in demo code

labels, *_ = model.segment(points=points, view=view, image_path="raster.tif", labels_path="labeled.tif")
the view = view should be view = viewpoint which is defined above.

specify that CSF should be installed

to run the example one needs CSF, but you don't specify it as a requirement:

this seems to be the good one? pip install cloth-simulation-filter?

Just top view?

Is it inferencing just the top view?

Screenshot 2023-06-09 at 7 06 41 PM

The results are pretty bad!

supervision

Hello,
Thank you for releasing this repository. I face this error when I tried to install it on pycharm.
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
segment-lidar 0.2.1 requires supervision==0.8.0, but you have supervision 0.6.0 which is incompatible.

[notice] A new release of pip is available: 23.2.1 -> 24.1.1
[notice] To update, run: python.exe -m pip install --upgrade pip

I would appreciate it if you please help me.

Segment anything workflow issues

While im trying to run the segment anything workflow. I ran into some issues.

TypeError: unhashable type: 'numpy.ndarray'

while trying to run the image_to_cloud function in the line :
if rgb not in unique_values:

my solution was rgb=tuple(rgb).

Another issue i was running into is when rearraring the array that rasterio returns when reading a tif.

image_rgb = image_rgb.reshape((image_rgb.shape[1], image_rgb.shape[2], image_rgb.shape[0]))

instead i use:

image_rgb = np.transpose(image_rgb, (1, 2, 0))

And finally in the part of the segment method:

with rasterio.open(labels_path, 'r') as src:
            segmented_image = src.read()
            segmented_image = np.squeeze(segmented_image)

print(f'- Generating segment IDs...')
segment_ids = image_to_cloud(points, minx, maxy, segmented_image, self.resolution)
end = time.time()

the error was that most of the points didnt pass the if stament:

if not (0 <= pixel_x < image.shape[1]) or not (0 <= pixel_y < image.shape[0]):

because rasterio arrange width, height,bands different than the classic.

so i use

 with rasterio.open(labels_path, 'r') as src:
            segmented_image = src.read()
            segmented_image = np.squeeze(segmented_image)
segmented_image=np.transpose(segmented_image, (1, 2, 0))
print(f'- Generating segment IDs...')
segment_ids = image_to_cloud(points, minx, maxy, segmented_image, self.resolution)
end = time.time()

import error with docker

hi, thanks for publishing this cool packages.
But, I am having issue with CSF module not being found in the docker image of segment-lidar.
`fw@w-Crosshair-15-A11UCK:~/lidar_segmentation$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
01cf113224e7 yarroudh/segment-lidar "python -c 'while Tr…" About an hour ago Up About an hour priceless_wu

w@w-Crosshair-15-A11UCK:~/lidar_segmentation$ docker exec 01cf113224e7 python segment.py
Traceback (most recent call last):
File "segment.py", line 1, in
from segment_lidar import samlidar, view
File "/opt/conda/lib/python3.8/site-packages/segment_lidar/samlidar.py", line 6, in
import CSF
ModuleNotFoundError: No module named 'CSF'
`
I also installed CSF inside the docker, but still CSF is not found.

the LAS file should contain RGB, or not?

It seems so since you rasterise and SAM is I believe using this, but this not clear.

You mention in the tutorial that AHN4 is used, but there is no RGB provided with AHN4?! Unless you download from geotiles.nl where RGB has been added (but derived product, not the original one).

So: can it work without RGB values? I tried and I get not very good results...

import issue

Hi I install the package as given in the guide.
ImportError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from segment_lidar import samlidar

ImportError: cannot import name 'samlidar' from 'segment_lidar' (/Users/sanjij/anaconda3/envs/geospatial_demo/lib/python3.9/site-packages/segment_lidar/init.py)

please help

Error on installation and dependecies

Hi Anass Yarroudh,
Congrats for pulling out this work! Amazing.
I was following this installation tutorial here, and when I run the following command on linux terminal (debian):
python -c "import segment_lidar; print(segment_lidar.version)"
I always get:
Traceback (most recent call last):
File "", line 1, in
AttributeError: module 'segment_lidar' has no attribute 'version'

I've installed python 3.9.0, 3.9.18 or .19 (not sure), now I've 3.11.5 and error remains the same.
Besides I always have a version conflict for supervision==0.8.0. Because by pip installing or even by git cloning the version end up supervision 0.6.0.

Is there a way to solve for this ? What do you think?
Thank you again

ValueError: could not broadcast input array from shape into shape

Any idea why I get the following error?

ValueError: could not broadcast input array from shape (3114735,) into shape (8392998,)

This is my code,

from segment_lidar import samlidar, view
import torch

device_set = 'cuda:0' if torch.cuda.is_available() else 'cpu'

model = samlidar.SamLidar(ckpt_path='segment_anything/checkpoints/sam_vit_h_4b8939.pth',
                        device=device_set, # 'cuda:0',
                        algorithm='segment-geospatial',
                        model_type = "vit_h",
                        resolution=1,
                        sam_kwargs=False) 

points = model.read("L4.las")

cloud, non_ground, ground = model.csf(points, class_threshold=0.1)

labels, *_ = model.segment(points=cloud,
                        image_path="results/raster_L4.tif",
                        labels_path="results/labeled_L4.tif")

model.write(points=points, segment_ids=labels, save_path="results/segmented_L4.las")

Below is the full output when running the script,

  • Classification value is not provided. Reading all points...
  • Reading RGB values...
    File reading is completed in 0.96 seconds. The point cloud contains 8392998 points.

Applying CSF algorithm...
[0] Configuring terrain...
[0] Configuring cloth...
[0] - width: 5004 height: 5004
[0] Rasterizing...
[0] Simulating...
CSF algorithm is completed in 552.40 seconds. The filtered non-ground cloud contains 8392998 points.

  • Generating raster image...
  • Saving raster image...
  • Applying segment-geospatial to raster image...
  • Saving segmented image...
  • Generating segment IDs...
    Segmentation is completed in 305.05 seconds. Number of instances: 212

Writing the segmented point cloud to results/segmented_L4.las...
Traceback (most recent call last):
File "/samlidar/segmentLiDAR_playground_nv.py", line 73, in
model.write(points=points, segment_ids=labels, save_path="results/segmented_L4.las")
File "/samlidar/lib/python3.10/site-packages/segment_lidar/samlidar.py", line 454, in write
lidar.segment_id = segment_ids
File "/samlidar/lib/python3.10/site-packages/laspy/lasdata.py", line 403, in setattr
self[key] = value
File "/samlidar/lib/python3.10/site-packages/laspy/lasdata.py", line 435, in setitem
self.points[key] = value
File "/samlidar/lib/python3.10/site-packages/laspy/point/record.py", line 222, in setitem
self[key][:] = value
ValueError: could not broadcast input array from shape (3114735,) into shape (8392998,)

CUDA out of memory error

Hello,

I've been trying to use your segment-lidar project and followed the instructions as per the documentation. However, I encountered a CUDA out of memory error that suggests I need about 130GB of GPU memory, which seems unusually high.
image

Here are the steps I took:

from segment_lidar import samlidar, view

viewpoint = view.TopView()

model = samlidar.SamLidar(ckpt_path="./sam_vit_b_01ec64.pth")
points = model.read("./point_cloud.las")
labels, *_ = model.segment(points=points, view=viewpoint, image_path="./raster.tif", labels_path="./labeled.tif")
model.write(points=points, segment_ids=labels, save_path="segmented.las")

I would like to know if there's something wrong with my setup or if I missed any configuration step that's leading to this issue. Is it expected to require this much GPU memory, or could there be a potential issue or bug?

Thank you for your help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.