Skip to content

Query for fixing an error in notebooks/automatic_mask_generator_example.ipynb #849

@ConcordeFree

Description

@ConcordeFree

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

Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions