Skip to content

Commit

Permalink
Update README.md with the new output image
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Feb 4, 2024
1 parent 6c0259a commit 312f87f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Binary file modified .readme/dogs_mask.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .readme/dogs_output.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,36 @@ pip install osam

```bash
# Run a model with an image
osam run efficient-sam:25m --image examples/_images/dogs.jpg > mask.jpg
osam run efficient-sam:25m --image examples/_images/dogs.jpg > output.jpg

# Get a JSON output
osam run efficient-sam:25m --image examples/_images/dogs.jpg --json
# {"model": "efficient-sam:25m", "mask": "..."}

# Give a prompt
osam run efficient-sam:25m --image examples/_images/dogs.jpg --json \
--prompt '{"points": [[1439, 504], [1439, 1289]], "point_labels": [1, 1]}'
osam run efficient-sam:25m --image examples/_images/dogs.jpg \
--prompt '{"points": [[1439, 504], [1439, 1289]], "point_labels": [1, 1]}' > output.jpg
```

<img src="examples/_images/dogs.jpg" width="35%"> <img src=".readme/dogs_mask.jpg" width="35%">
<i>Input and output images ('dogs.jpg', 'mask.jpg').</i>
<img src="examples/_images/dogs.jpg" width="35%"> <img src=".readme/dogs_output.jpg" width="35%">
<i>Input and output images ('dogs.jpg', 'output.jpg').</i>

### Python

```python
import numpy as np
import PIL.Image

import osam
import osam.apis
import osam.types

request = osam.types.GenerateRequest(
model=model_name,
image=np.asarray(PIL.Image.open("examples/_images/dogs.jpg)),
model="efficient-sam:25m",
image=np.asarray(PIL.Image.open("examples/_images/dogs.jpg")),
prompt=osam.types.Prompt(points=[[1439, 504], [1439, 1289]], point_labels=[1, 1]),
)
response = osam.apis.generate(request=request)
PIL.Image.fromarray(response.mask).save("mask.jpg")
print(response.mask.shape, request.mask.dtype) # (1600, 2560), "uint8"
```
<img src="examples/_images/dogs.jpg" width="35%"> <img src=".readme/dogs_mask.jpg" width="35%">
<i>Input and output images ('dogs.jpg', 'mask.jpg').</i>

### HTTP

Expand All @@ -73,7 +72,8 @@ osam serve
# POST request
curl 127.0.0.1:11368/api/generate -X POST \
-H "Content-Type: application/json" \
-d "{\"model\": \"efficient-sam:25m\", \"image\": \"$(cat examples/_images/dogs.jpg | base64)\"}"
-d "{\"model\": \"efficient-sam:25m\", \"image\": \"$(cat examples/_images/dogs.jpg | base64)\"}" \
| jq -r .mask | base64 --decode > mask.jpg
```

## License
Expand Down

0 comments on commit 312f87f

Please sign in to comment.