Last active
November 11, 2019 10:13
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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