facebookresearch / facebookresearch/segment-anything
Query for fixing an error in notebooks/automatic_mask_generator_example.ipynb
- Dominant language
- Jupyter Notebook
- Stars
- 54.9k
- Forks
- 6.4k
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I have found an error when using notebooks/automatic_mask_generator_example.ipynb. And I did know how to fix it. The original code have mistaken 'masks' variable as the expected masks that SAM generates, instead it's the first element of 'masks', i.e masks[0].
### Solution:
```
print(len(masks))
print(masks[0].keys()) **---> print(masks[0][0].keys())**
```
```
plt.figure(figsize=(20,20))
plt.imshow(image)
show_anns(masks) **---> show_anns(masks[0])**
plt.axis('off')
plt.show()
```
```
plt.figure(figsize=(20,20))
plt.imshow(image)
show_anns(masks2) **---> show_anns(masks2[0])**
plt.axis('off')
plt.show()
```
### Error Description
When running the code cell:
```
print(len(masks))
print(masks[0].keys())
```
An error occurred:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[7], line 2
1 print(len(masks))
----> 2 print(masks[0].keys())
AttributeError: 'list' object has no attribute 'keys'
When running the code cell:
```
plt.figure(figsize=(20,20))
plt.imshow(image)
show_anns(masks)
plt.axis('off')
plt.show()
```
An error occured:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[8], line 3
1 plt.figure(figsize=(20,20))
2 plt.imshow(image)
----> 3 show_anns(masks)
4 plt.axis('off')
5 plt.show()
Cell In[2], line 4, in show_anns(anns)
2 if len(anns) == 0:
3 return
----> 4 sorted_anns = sorted(anns, key=(lambda x: x['area']), reverse=True)
5 ax = plt.gca()
6 ax.set_autoscale_on(False)
Cell In[2], line 4, in show_anns..(x)
2 if len(anns) == 0:
3 return
----> 4 sorted_anns = sorted(anns, key=(lambda x: x['area']), reverse=True)
5 ax = plt.gca()
6 ax.set_autoscale_on(False)
TypeError: list indices must be integers or slices, not str
Contributor guide
Research direction
Open notebooks/automatic_mask_generator_example.ipynb and run the cells that inspect masks and display the annotations. Check the reported list-versus-dictionary errors, then update the notebook to use the intended nested mask values in those cells. Done means the inspection and both visualization examples run without the shown AttributeError or TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, python
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100