unaied
unaied

Reputation: 307

can you use pigeon to annotate all images in a folder

I would like to label images within a folder with either yes or no for a machine learning project.

I found this great tool; Pigeon.. https://github.com/agermanidis/pigeon

but the examples provided online requires the user to provide the names of all files within the script. I have not been able to find a way to point the script to a folder instead of including all image names.

Is there a way where you can just provide a link to a folder only.

from pigeon import annotate
from IPython.display import display, Image

annotations = annotate(
  ['assets/img_example1.jpg', 'assets/img_example2.jpg'],
  options=['cat', 'dog', 'horse'],
  display_fn=lambda filename: display(Image(filename))
)

Upvotes: 1

Views: 424

Answers (2)

Lomtrur
Lomtrur

Reputation: 1798

One possible solution is to just list all files in the folder you are interested in. In this case you provide just the path to the folder (absolute or relative) and use os.listdir to get all the files in that folder.

I then use os.path.join to get the file paths and pass a list of the file paths to annotate.

from pigeon import annotate
from IPython.display import display, Image
import os

path = "assets"
imgs = os.listdir(path)
imgs = [os.path.join(path, img) for img in imgs]

annotations = annotate(
  imgs,
  options=['cat', 'dog', 'horse'],
  display_fn=lambda filename: display(Image(filename))
)

Upvotes: 1

user16985041
user16985041

Reputation:

I made a for-loop that went through a folder and populated a list with the image names. Then just called the list in place of

['assets/img_example1.jpg', 'assets/img_example2.jpg']

Upvotes: 1

Related Questions