Comments (8)
Hi @romainGuiet , thank you for trying it! The URL needs to be the complete endpoint URL including /sam/
.
Could you try putting the following URL?
from samapi.
@romainGuiet please try qupath-extension-sam-0.2.0.jar.
@petebankhead RenderedImageServer works as I expected, thank you again for your help!
from samapi.
it works on the RGB transmission ! thanks 🥳
![image](https://private-user-images.githubusercontent.com/8309560/246078753-5d721494-8713-4e08-a893-0cdcfd7432d1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIzMzg4MDAsIm5iZiI6MTcyMjMzODUwMCwicGF0aCI6Ii84MzA5NTYwLzI0NjA3ODc1My01ZDcyMTQ5NC04NzEzLTRlMDgtYTg5My0wY2RjZmQ3NDMyZDEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDczMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MzBUMTEyMTQwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ODhmZjY1MTk0NjA5ZWVjZTY3MmU5OWU3ZDEzYzM5MWI1ZjhhOGU0Mjc3ZWNiYzJhNWVmMDhjYzUyNmM1Nzc2NiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.IImfzHvatgjrTrNqvBDCGFwi5IF2XsIynibDKc5FkTI)
but on my fluorescent image with 5 channels I get an error
INFO: 127.0.0.1:64372 - "POST /sam/ HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\uvicorn\protocols\http\httptools_impl.py", line 435, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 78, in __call__
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\fastapi\applications.py", line 276, in __call__
await super().__call__(scope, receive, send)
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\starlette\applications.py", line 122, in __call__
await self.middleware_stack(scope, receive, send)
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\starlette\middleware\errors.py", line 184, in __call__
raise exc
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\starlette\middleware\errors.py", line 162, in __call__
await self.app(scope, receive, _send)
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\starlette\middleware\exceptions.py", line 79, in __call__
raise exc
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__
await self.app(scope, receive, sender)
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in __call__
raise e
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in __call__
await self.app(scope, receive, send)
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\starlette\routing.py", line 718, in __call__
await route.handle(scope, receive, send)
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\starlette\routing.py", line 276, in handle
await self.app(scope, receive, send)
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\starlette\routing.py", line 66, in app
response = await func(request)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\fastapi\routing.py", line 237, in app
raw_response = await run_endpoint_function(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\fastapi\routing.py", line 163, in run_endpoint_function
return await dependant.call(**values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\samapi\main.py", line 80, in predict_sam
image = decode_image(body.b64img)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\samapi\utils.py", line 13, in decode_image
return np.array(Image.open(io.BytesIO(base64.b64decode(b64data))))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guiet\.conda\envs\samapi\Lib\site-packages\PIL\Image.py", line 3298, in open
raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000001B1DCD2FFB0>
![image](https://private-user-images.githubusercontent.com/8309560/246080084-106eee18-9093-4797-adbf-f8d150130cb3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIzMzg4MDAsIm5iZiI6MTcyMjMzODUwMCwicGF0aCI6Ii84MzA5NTYwLzI0NjA4MDA4NC0xMDZlZWUxOC05MDkzLTQ3OTctYWRiZi1mOGQxNTAxMzBjYjMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDczMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MzBUMTEyMTQwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NDQzMjczODFmZTY5NDhlMTQzMzBkMmMzN2NkODQ1ZDU1MjdkOGMzZjUxODkwZjQ5NDQ4YjVlOTM5MGIxMmNkYiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.ypTOvGTMVtDfVreazSc9fLJOvSeQNWMpgYZIHd_VPOM)
I tried to reduce the number of displayed channels to 3 but without any positve effect 😅
Best
Romain
from samapi.
If using SAM as an 'annotation assistant', then I think RenderedImageServer
and RGB makes most sense - QuPath's wand tool also uses the viewer rendering. It means that, for multiple channel images, the user can toggle on and off channels according to what they want to be visible, which could be really useful.
For training StarDist/CellPose, then passing the raw pixels could be useful - e.g. if you're able to train a single-channel StarDist model (like the DSB2018 model from StarDist's original creators). In that case, you might use TransformedServerBuilder
along with the method I posted above to extract one or more channels and convert them to tiff bytes.
from samapi.
Thanks @petebankhead , both totally make sense. I will use RenderedImageServer for the SAM module.
About the modules for training StarDist/CellPoseI, only grayscale images are supported for now, but I will update them using TransformedServerBuilder as you suggested.
I really appreciate all your help!
from samapi.
That's great it works for your RGB data! 👍
At the moment, it assumes grayscale or RGB images. I will try to find a workaround.
@petebankhead do you have a readRegion method that returns an RGB BufferedImage as shown in QuPath?
from samapi.
Hi readRegion
will return whichever kind of BufferedImage
is required for the bit-depth and channels - so it's RGB where possible, but could be something else.
If it's something else, then there's a strong chance ImageIO
won't be able to write the image.
I understand you're using base64 in the end with PNG. One way to get a useful byte array to encode is to convert to ImageJ TIFF bytes, e.g.
public static byte[] getImageBytes(ImageServer<BufferedImage> server, RegionRequest request) throws IOException {
if (server.isRGB()) {
// Do whatever you usually do (PNG should be ok)
var img = server.readRegion(request);
return // ImageIO code to PNG
}
var imp = IJTools.convertToImagePlus(server, request).getImage();
return new FileSaver(imp).serialize();
}
where FileSaver
is a class in ImageJ. I haven't completed or properly tested this code, but I think the idea works, and the (uncompressed) TIFF can be read fine in Python.
Alternatively, if you really want an RGB version (applying whatever settings are used in the viewer), then you can create a RenderedImageServer
and get the pixels from that. Although I prefer the solution that sends the raw pixel values, without the rendering to RGB required (at least if it's possible to handle non-RGB meaningfully on the other side).
from samapi.
Thank you @petebankhead for your kind reply and nice suggestion.
Because all pre-trained models provided in the original SAM repository require an input image with three channels, we need to somehow convert a multi-channel image to a three-channel image in either Java or Python.
https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/build_sam.py#L67
https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/image_encoder.py#L22
I think using RenderedImageServer is easy to achieve it.
Assuming that the pre-trained SAM model is good at working with the objects that human eyes recognize, using the rendering settings on QuPath might make sense.
If you have a good approach to converting a multi-channel raw image into a three-channel image, please let me know.
Thanks.
from samapi.
Related Issues (12)
- windows installation issues HOT 6
- Support for SamAutomaticMaskGenerator HOT 3
- Introduce MobileSAM HOT 2
- Support micro-sam fine-tuned models
- build fail with 0.3.1, was working with 0.3.0 HOT 5
- Support for using cloud GPU HOT 5
- Support CellViT
- Connect with remote server HOT 1
- CUDA Out of Memory HOT 1
- RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory HOT 4
- Support SAM2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from samapi.