SegmentAnything.jl
requires python 3.8.6
with the following packages:
segment anything
cv2
matplotlib.pyplot
numpy
torch
You can use pyenv
to handle multiple versions of python on your computer. Once pyenv
installed, run pyenv install 3.8.6
and pyenv global 3.8.6
to add and to activate the required version on your machine.
There is a requirements.txt
file into SegmentAnything.jl/deps/python/
. To install the python environment, you just need to create a virtual env and add the packages with the following commands
# change directory
cd SegmentAnything.jl/deps/python
# create venv
python3 -m venv .venv
# activate venv
source .venv/bin/activate
# install python packages from requirements.txt
pip3 install -r requirements.txt
SegmeAnything.jl
needs the Segment Anything Model Checkpoints. To download the 3 checkpoints, just run the download_sam.jl
file located at SegmentAnything/deps/sam
.
- Clone the repo
- In a terminal emulator, change the working directory:
cd path/to/SegmentAnything.jl
- Activate the julia env in the julia REPL:
pkg> activate.
- Instantiate the env to install deps:
pkg> instantiate
- Then, load the module:
julia> include("SegmentAnything.jl")
To perform an automatic segmentation, just run the segment_image()
function. This function takes two arguments, the image path
and a sam checkpoint
(vit_b
, vit_l
or vit_h
).
julia> image = "path/to/image"
julia> segmentation = SegmentAnything.segment_image(image, "vit_b")
To display the masks over image, use the show_anns_jl()
function.
julia> SegmentAnything.show_anns_jl(segmentation, image)