Skip to content

Instantly share code, notes, and snippets.

@davidefiocco
Last active November 11, 2019 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davidefiocco/7bbb3e3f1203c2c7bd11960b83eca982 to your computer and use it in GitHub Desktop.
Save davidefiocco/7bbb3e3f1203c2c7bd11960b83eca982 to your computer and use it in GitHub Desktop.
Working prodigy (http://prodi.gy) recipe for image binary classification, using Ines' suggestions in https://support.prodi.gy/t/whats-a-recipe-for-dead-simple-binary-or-multiclass-image-classification/2136
import prodigy
from prodigy.components.loaders import Images
from prodigy.util import split_string
def add_label_to_stream(stream, label):
for eg in stream:
# The 'label' you get from the command line is a list
# so let's just assume it's always one and take the first
eg["label"] = label[0]
yield eg
@prodigy.recipe('image-classification',
dataset=("The dataset to use", "positional", None, str),
source=("Path to a directory of images", "positional", None, str),
label=("One or more comma-separated labels", "option", "l", split_string)
)
def image_classification(dataset, source, label=None):
"""
Stream images from directory and apply first label among the ones in input
"""
stream = Images(source)
stream = add_label_to_stream(stream, label)
print(stream)
return {
'dataset': dataset, # Name of dataset to save annotations
'stream': stream, # Incoming stream of examples
'view_id': 'classification'
}
# Example usage (works in prodigy 1.8.5):
# prodigy image-classification your-dataset-name local-directory-with-images -l spam,eggs -F image_classification.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment