Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated readme, contributing, docstrings, and adding requirements.txt #429

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,48 @@ possible.
## Pull Requests
We actively welcome your pull requests.

1. Fork the repo and create your branch from `main`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints, using the `linter.sh` script in the project's root directory. Linting requires `black==23.*`, `isort==5.12.0`, `flake8`, and `mypy`.
6. If you haven't already, complete the Contributor License Agreement ("CLA").
1. **Fork the Repository**: Start by forking the Segment-Anything repository to your own GitHub account.
- A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project. In the upper right of the main repo you may select fork and create a copy for your profile.

2. **Create a New Branch**: From the `main` branch, create a new branch to contain your changes.
- Creating a new branch is done with the following command in your forked copy:

```
git checkout -b <branch-name>
```

3. **Make Your Changes**: Implement your changes in this branch.

4. **Write Tests**: If you've added code that should be tested, ensure you include appropriate tests.

5. **Update the Documentation**: If your changes include updates to APIs, make sure you update the corresponding documentation.

6. **Run Tests**: Ensure that all existing and new tests pass.

7. **Lint Your Code**: Linting is the process of checking your source code for programmatic and stylistic errors. Make sure your code adheres to our styling conventions. You can do this by using the `linter.sh` script in the project's root directory.

- Run the following command:

```
pip install black==23.* isort==5.12.0 flake8 mypy
```

- Run Linter Script: After you've installed the required tools, you can run the linter.sh script located in the root directory of the project. Navigate to the project's root directory in your terminal or command line and run the following command:

```
./linter.sh
```

- This command will start the linting process. The script will check your code and report any stylistic or programmatic errors it finds.
- **Note** - Please note that you might need to make the linter script executable before you can run it. You can do this with the following command:

```
chmod +x linter.sh
```

8. **Sign the CLA**: If you haven't already, complete the Contributor License Agreement ("CLA"). More information below.

9. **Submit a Pull Request**: Upon completion of the above steps, you can create a pull request (PR). Go to the GitHub page for Segment Anything's original repository, navigate to the "Pull requests" tab, and then click the "New pull request" button. On the next page, click the "compare across forks" link, then select your fork and the branch with your changes. Fill out the form describing your changes and then click "Create pull request."

## Contributor License Agreement ("CLA")
In order to accept your pull request, we need you to submit a CLA. You only need
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ cd segment-anything; pip install -e .
```

The following optional dependencies are necessary for mask post-processing, saving masks in COCO format, the example notebooks, and exporting the model in ONNX format. `jupyter` is also required to run the example notebooks.
- PyTorch: An open-source machine learning library based on the Torch library.
- Torchvision: A package that provides access to popular datasets, model architectures, and image transformations for computer vision.
- CUDA: Compute Unified Device Architecture, a parallel computing platform and API model created by NVIDIA, which allows using GPU for general purpose processing.
- COCO: Common Objects in Context, a large-scale object detection, segmentation, and captioning dataset.
- ONNX: Open Neural Network Exchange, an open format to represent deep learning models.

```
pip install opencv-python pycocotools matplotlib onnxruntime onnx
Expand Down Expand Up @@ -134,7 +139,7 @@ annotation {

Image ids can be found in sa_images_ids.txt which can be downloaded using the above [link](https://ai.facebook.com/datasets/segment-anything-downloads/) as well.

To decode a mask in COCO RLE format into binary:
To decode a mask in [COCO RLE](#coco-common-objects-in-context) format into binary:

```
from pycocotools import mask as mask_utils
Expand Down
34 changes: 34 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
beautifulsoup4==4.11.1
bs4==0.0.1
certifi==2022.12.7
charset-normalizer==2.1.1
coloredlogs==15.0.1
contourpy==1.0.7
cycler==0.11.0
distlib==0.3.6
filelock==3.9.0
flatbuffers==23.5.26
fonttools==4.39.4
humanfriendly==10.0
idna==3.4
kiwisolver==1.4.4
matplotlib==3.7.1
mpmath==1.3.0
numpy==1.24.2
onnx==1.14.0
onnxruntime==1.15.0
opencv-python==4.7.0.72
packaging==23.1
Pillow==9.5.0
platformdirs==2.6.2
protobuf==4.23.2
pycocotools==2.0.6
pyparsing==3.0.9
python-dateutil==2.8.2
requests==2.28.1
six==1.16.0
soupsieve==2.3.2.post1
sympy==1.12
typing_extensions==4.6.2
urllib3==1.26.13
virtualenv==20.17.1
8 changes: 8 additions & 0 deletions segment_anything/modeling/sam.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@


class Sam(nn.Module):
"""
SAM (Segmentation and Masking) is a class used for object masking in images.
It leverages the power of the Vision Transformer (ViT) as an image encoder,
a prompt encoder for various types of input prompts, and a mask decoder
for predicting object masks. It fits into the larger system as a module responsible
for understanding the spatial layout of objects in an image, based on prompts given
as inputs, and generating corresponding object masks.
"""
mask_threshold: float = 0.0
image_format: str = "RGB"

Expand Down