notebooks
notebooks copied to clipboard
Updates and bug fixes to how-to-segment-anything-with-fast-sam.ipynb
Description
CHANGE 1: Changed typo in Markdown cell:
NOTE: FastSAM
code is not distributed via pip
not it is packaged. Make sure to run code balow from {HOME}/FastSAM
directory. ⚠️
to
NOTE: FastSAM
code is not distributed via pip
not it is packaged. Make sure to run code below from {HOME}/FastSAM
directory. ⚠️
CHANGE 2: Added print statement for DEVICE:
print(f"DEVICE = {DEVICE}")
CHANGE 3: Added cell to create output directory and path:
os.makedirs(f"{HOME}/output", exist_ok=True)
output_image_path = f"{HOME}/output/output-{os.path.basename(IMAGE_PATH)}"
This prevents error: OpenCV(4.9.0) /io/opencv/modules/imgcodecs/src/loadsave.cpp:696: error: (-2:Unspecified error) could not find a writer for the specified extension in function 'imwrite_'
when running prompt_process.plot(annotations=masks, output_path=f"{HOME}/output")
CHANGE 4: Changed NOTE: regarding output for prompt_process.everything_prompt:
NOTE: prompt_process.everything_prompt
returns torch.Tensor
to
NOTE: prompt_process.everything_prompt
returns torch.Tensor
when DEVICE = 'cuda:0'. prompt_process.everything_prompt
returns numpy.ndarray
when DEVICE = 'cpu'.
CHANGE 5: Added function masks_to_bool(masks)
:
Converts masks to boolean, regardless of if masks are numpy.ndarray or torch.Tensor
CHANGE 6: Replaced mask_annotator = sv.MaskAnnotator()
with mask_annotator = sv.MaskAnnotator(color_lookup = sv.ColorLookup.INDEX)
- Prevents error:
ValueError: Could not resolve color by class becauseDetections do not have class_id
when runningannotated_image=annotate_image(image_path=IMAGE_PATH, masks=masks)
- Fix found at https://github.com/roboflow/supervision/discussions/428
Please include a summary of the change and which issue is fixed or implemented. Please also include relevant motivation and context (e.g. links, docs, tickets etc.).
- Changes are a result of my personal demo of
how-to-segment-anything-with-fast-sam.ipynb
and running into the issues described in each CHANGE. - Updates to account for running in CPU are due to wanting to run notebook in cases where GPU not available.
List any dependencies that are required for this change.
- Python version: 3.10.14
- No additional dependencies beyond what was already listed in imports
Type of change
Please delete options that are not relevant.
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] This change requires a documentation update
How has this change been tested, please provide a testcase or example of how you tested the change?
- Ran entire
update--how-to-segment-anything-with-fast-sam.ipynb
successfully in Google Colab with CPU and T4 GPU - Ran entire
update--how-to-segment-anything-with-fast-sam.ipynb
successfully in Ubuntu 22.04 in Conda environment, Python 3.10.14, with CPU
Any specific deployment considerations
For example, documentation changes, usability, usage/costs, secrets, etc.:
- Orgingal notebook,
how-to-segment-anything-with-fast-sam.ipynb
may need to be replace with this updated notebook (update--how-to-segment-anything-with-fast-sam.ipynb
).
Docs
- [ ] Docs updated? What were the changes:
- No Docs changes beyond some Markdown changes in notebook (described in CHANGES above).
Hi, @MattLondon101 👋🏻 Thanks for your interest in notebooks and the time you spent working on this PR. Could you update the PR and commit your notebook under the original name? We wouldn't like to have two versions of the same notebook, we would like to update the original one.
@SkalskiP I have updated the PR with latest commit: "Deleted notebooks/how-to-seg ment-anything-with-fast-sam.ipynb. Then renamed notebooks/update--how-to-segment-anything-with-fast-sam.ipynb to notebooks/how-to-segment-anything-with-fast-sam.ipynb"
Hi @MattLondon101 👋🏻 Could you accept the CLA?
@SkalskiP I have accepted the CLA. Please let me know if there is anything else I can do.
Hi @MattLondon101 👋🏻 Let's clean up a few minor things before we merge.
- Please remove all changes you made in
README.md
andautomation/notebooks-table-data.csv
files. - Looks like this line
output_image_path = f"{HOME}/output/output-{os.path.basename(IMAGE_PATH)}"
is redundant.output_image_path
is not used anywhere. Please remove it. It looks like we could simplify themasks_to_bool
implementation
def masks_to_bool(masks):
if type(masks) == np.ndarray:
return masks.astype(bool)
return masks.cpu().numpy().astype(bool)
@SkalskiP I've made all changes requested. I think the README.md and notebooks-table-data.csv got messed up when I was initially thinking to make a new notebook for the update, instead of replacing the original one. I like your simplification of masks_to_bool
. Please let me know if any more changes needed.
@MattLondon101, no worries ;) I'm just making sure everything works. Merging! Thanks a lot for the contribution! 🙏🏻