bingogome / samm

A 3D Slicer integration to Meta's SAM.
https://arxiv.org/abs/2304.05622
MIT License
241 stars 34 forks source link

[bug-MacOS] ValueError: mmap length is greater than file size #28

Closed woailunhua closed 1 year ago

woailunhua commented 1 year ago

Sorry to reply to you so late, here are two of my data, you can try to split the teeth or maxillary sinuses.
My environment is Linux and my GPU is 2080TI.My 3dslicer version is 5.2.2. SAMM running on my side The error message is:"ValueError: mmap length is greater than file size.".

woailunhua commented 1 year ago

https://drive.google.com/file/d/1zqc02qs6FPB7pmfhwGhAT8OGkiloARHP/view?usp=sharing

woailunhua commented 1 year ago

https://drive.google.com/file/d/1m7q32-wLqW7Jwli7rPLAFLcCOYPAGlb1/view?usp=share_link

woailunhua commented 1 year ago

I found that SAMM works well on Windows. My host is a dual system, and the hardware resources have not changed.But why is there such a bug under Linux?

bingogome commented 1 year ago

It's interesting to know it works better on Windows than Linux for you. Our testing and development are mainly done on Linux. The support for Windows was actually a secondary priority. Not sure what happened, but I will try to use your data later when I find some more time.

I am suspecting a Numpy.mmap issue.

bingogome commented 1 year ago

Just a sanity check: by any chance you installed the newest version of the repository on Windows, but not on Linux?

woailunhua commented 1 year ago

Thanks for your reply.I reinstalled the latest SAMM version on Linux, but the problem persists. Are you testing on Linux that the data I provided is working?

bingogome commented 1 year ago

I tired your data on multiple versions and OS's, they all worked fine.

Could you share the information of your hardware? Also, could you also try to re-install SAMM (both the Slicer extension and sam_server).

rjkowalski commented 1 year ago

I am getting the same issue on macOS 12.6.5, 3D Slicer 5.2.2 and version 1.0.3 of SAMM. I'm running without a GPU on a 2.9GHz Intel i5 with 16GB RAM. I load a 2D slice into Slicer, choose the volume in Samm Base and compute embedding. I then select 3 prompts on the image and no segmentation is generated. After reloading the Samm Base module, I do the same procedure and get the following error in 3D Slicer's Python terminal:

Traceback (most recent call last): File "/Users/my_user/GitHub/samm/samm/SammBase/SammBaseLib/LogicSamm.py", line 209, in processStartMaskSync memmap = numpy.memmap(self._parameterNode._workspace + '/mask.memmap', \ File "/Applications/Slicer.app/Contents/lib/Python/lib/python3.9/site-packages/numpy/core/memmap.py", line 267, in new mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=start) ValueError: mmap length is greater than file size

bingogome commented 1 year ago

It's hard to reproduce the error on my side. Would you be interested in a Zoom meeting? Shoot me an email at yliu333@jhu.edu @rjkowalski @woailunhua

rjkowalski commented 1 year ago

@bingogome - I just got this setup on a new 14" MacBook Pro with an Apple M2 Pro. MPS was detected as expected when running the SAM Server. It only took about 60 seconds to compute embedding for one 3D volume with 40 slices. As soon as this completed, I clicked on Start Mask Sync and received the same error:

Traceback (most recent call last): File "/Users/my_user/GitHub/samm/samm/SammBase/SammBaseLib/WidgetSammBase.py", line 141, in onPushStartMaskSync self.logic.processStartMaskSync() File "/Users/my_user/GitHub/samm/samm/SammBase/SammBaseLib/LogicSamm.py", line 209, in processStartMaskSync memmap = numpy.memmap(self._parameterNode._workspace + '/mask.memmap', \ File "/Applications/Slicer.app/Contents/lib/Python/lib/python3.9/site-packages/numpy/core/memmap.py", line 267, in new mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=start) ValueError: mmap length is greater than file size

bingogome commented 1 year ago

Marking this as a [bug] entry. Looks like it is MacOS specific.

themantalope commented 1 year ago

Also getting it on Ubuntu 18.04 3D Slicer 5.1.0

bingogome commented 1 year ago

This issue should be fixed now in 5b63c7dfa120c39066215fb766f8b246be3e2414 by switching communication from memory mapping to ZMQ. I am closing this issue because MacOS would be challenging to fit the large model here, but I will add a support for the smaller model SAM provided.