Skip to content

Instantly share code, notes, and snippets.

@koAlech
Created March 25, 2019 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koAlech/1bfeebbef7117d0d2530ff61f2dc1a5e to your computer and use it in GitHub Desktop.
Save koAlech/1bfeebbef7117d0d2530ff61f2dc1a5e to your computer and use it in GitHub Desktop.
# coding: utf8
from __future__ import unicode_literals
import prodigy
from prodigy.components.loaders import Images
from prodigy.util import split_string
from prodigy.util import set_hashes
from prodigy.components.db import connect
import itertools
def update(answers):
for answer in answers:
for option in answer['options']:
del option['image']
# print('answer:', answer)
# Recipe decorator with argument annotations: (description, argument type,
# shortcut, type / converter function called on value before it's passed to
# the function). Descriptions are also shown when typing --help.
@prodigy.recipe('multi_image_classification',
dataset=("The dataset to use", "positional", None, str),
source=("Path to a directory of images", "positional", None, str),
)
def multi_image_classification(dataset, source):
tmp = Images(source)
stream = []
it = 0
tID = 1
x = {}
for task in tmp:
if it == 0:
x = {}
x['label'] = 'DIY'
x['id'] = tID
x['options'] = []
x['options'].append({'id': it, 'text': task['meta']['file'] ,'image': task['image']})
if it == 3:
stream.append(x)
it = 0
tID += 1
else:
it += 1
if it > 0:
stream.append(x)
return {
'view_id': 'choice', # Annotation interface to use
'dataset': dataset, # Name of dataset to save annotations
'update': update,
'stream': stream, # Incoming stream of examples
'config': { # Additional config settings
'choice_style': 'multiple',
'choice_auto_accept': False
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment