unable to use classify-images

Hi,

I want to use multi-label image classification as described here in your docs.
However, when I use:

prodigy classify-images sunglasses_brands ./images -F recipe.py

I get the following error:

Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "...prodigy/lib/python3.10/site-packages/prodigy/main.py", line 50, in
main()
File ".../prodigy/lib/python3.10/site-packages/prodigy/main.py", line 44, in main
controller = run_recipe(run_args)
File "cython_src/prodigy/cli.pyx", line 135, in prodigy.cli.run_recipe
File "cython_src/prodigy/core.pyx", line 155, in prodigy.core.Controller.from_components
File "cython_src/prodigy/core.pyx", line 307, in prodigy.core.Controller.init
File "cython_src/prodigy/components/stream.pyx", line 191, in prodigy.components.stream.Stream.is_empty
File "cython_src/prodigy/components/stream.pyx", line 230, in prodigy.components.stream.Stream.peek
File "cython_src/prodigy/components/stream.pyx", line 343, in prodigy.components.stream.Stream._get_from_iterator
File "cython_src/prodigy/components/source.pyx", line 755, in load_noop
File "cython_src/prodigy/components/source.pyx", line 109, in iter
File "cython_src/prodigy/components/source.pyx", line 110, in prodigy.components.source.Source.iter
File "cython_src/prodigy/components/source.pyx", line 365, in read
File "... recipe.py", line 16, in get_stream
stream = get_stream(source)
TypeError: classify_images..get_stream() takes 0 positional arguments but 1 was given

Could you please help with the same?

Thanks,
Akshay.

Hi @Akshay,

I must admit there's en error in the example code which results in the naming conflict between the custom and the built-in get_stream function.

I have already edited the example in the docs, but here it is as well:

import prodigy
from prodigy.components.stream import get_stream as prodigy_get_stream

OPTIONS = [
    {"id": 0, "text": "Ray Ban Wayfarer (Original)"},
    {"id": 1, "text": "Ray Ban Wayfarer (New)"},
    {"id": 2, "text": "Ray Ban Clubmaster (Classic)"},
    {"id": 3, "text": "Ray Ban Aviator (Classic)"},
    {"id": -1, "text": "Other model"}
]

@prodigy.recipe("classify-images")
def classify_images(dataset, source):
    def get_stream():
        # Load the directory of images and add options to each task
        stream = prodigy_get_stream(source)
        for eg in stream:
            eg["options"] = OPTIONS
            yield eg

    return {
        "dataset": dataset,
        "stream": get_stream(),
        "view_id": "choice",
        "config": {
            "choice_style": "single",  # or "multiple"
            # Automatically accept and submit the answer if an option is
            # selected (only available for single-choice tasks)
            "choice_auto_accept": True
        }
    }

As you can see I renamed the built-in get_stream function in the import statement to avoid naming conflict in the recipe script.
Apologies for that and many thanks for the heads-up that helped us to improve the docs!

Oh, I should have spotted that.
Thank you for the resolution.