replicate / cog

Containers for machine learning
https://cog.run
Apache License 2.0
8.08k stars 561 forks source link

Array as inputs and outputs using Input method #527

Open simonMoisselin opened 2 years ago

simonMoisselin commented 2 years ago

Hello,

Is it possible to add the type array as an input, in addition to images or files?

zeke commented 2 years ago

Hi @simonMoisselin 👋🏼

Arrays/lists as inputs and outputs are not currently supported in Cog, but this seems to me like a reasonable thing to support. Can you share a little about your intended use case?

For a list of types that are currently supported, see the docs on Input and output types.

See also this open issue about supporting multiple file outputs: https://github.com/replicate/cog/issues/411

dashstander commented 2 years ago

I think this is a great idea. I don't know necessarily if this would work the best (in particular it might be somewhat extraneous to using models from replicate.com), but would be awesome to support Arrow for serializing and de-serializing array data.

anotherjesse commented 1 year ago

This is still the case - we do not yet support lists/arrays of input:

TypeError: Unsupported input type typing.List[float] for parameter `nums`. Supported input types are: str, int, float, bool, cog.File, cog.Path.
ⅹ Failed to get container status: exit status 1
jayaffine commented 1 year ago

This would be a great idea to support different formats. I wanted to host some derivatives of Segment Anything Model where the results are in dict format. So the results will have numpy arrays, boolean arrays, etc. It would be great if I can pass these dict files as results.

Hi @simonMoisselin 👋🏼

Arrays/lists as inputs and outputs are not currently supported in Cog, but this seems to me like a reasonable thing to support. Can you share a little about your intended use case?

For a list of types that are currently supported, see the docs on Input and output types.

See also this open issue about supporting multiple file outputs: #411

bfirsh commented 1 year ago

Related / dupe of https://github.com/replicate/cog/issues/608

alexblattner commented 1 year ago

hi, I'd like to be able to upload multiple pictures for a single argument. This would be very useful for that

camenduru commented 8 months ago

Hi @zeke 👋 Dust3r ( https://replicate.com/camenduru/dust3r ) needs multiple images as input.

yosun commented 8 months ago

@zeke this is a bug not an enhancement! i am afraid to upload pictures of corgi.cam but, if you want to know, currently, with only 2 photos, this issue is killing pugs: https://replicate.com/p/llpqfprbx6oo3hmnggl4nbvqku

yosun commented 8 months ago

This atrocity can be fixed if we can input more than 2 images!

Image from Gyazo

zeke commented 8 months ago

Raised it with the team. We're working on it!

dkhokhlov commented 8 months ago

the issue with List[str] type is confirmed. temp workaround - use simple 'str' type and split value later. looking into it.

$ cog --version cog version 0.9.4 (built 2024-01-24T22:16:49Z)

zeke commented 8 months ago

use simple 'str' type and split value later.

Can you provide an example? How would that work for files?

yosun commented 8 months ago

the issue with List[str] type is confirmed. temp workaround - use simple 'str' type and split value later. looking into it.

$ cog --version cog version 0.9.4 (built 2024-01-24T22:16:49Z)

okay so basically we can just concatenate as many input URLs as we want and then parse split it?

this does not seem secure. kind of like injection attack looming to happen.

dkhokhlov commented 8 months ago

right, looking into it.

dkhokhlov commented 8 months ago

@yosun

cog on "support_for_list_in_input" PR branch supports list[Path] input. For local runs only, not supported in Web UI yet, in progress. Example:

$ echo test1 > 1.txt
$ echo test2 > 2.txt
$ cat predict.py
from cog import BasePredictor, Path

class Predictor(BasePredictor):
   def predict(self, paths: list[Path]) -> str:
       output_parts = []  # Use a list to collect file contents
       for path in paths:
           with open(path) as f:
             output_parts.append(f.read())
       return "".join(output_parts)

$ cog predict -i 'paths=["@1.txt", "@1.txt"]'

Running prediction...
test1

test2
simonMoisselin commented 8 months ago

@yosun

cog on "support_for_list_in_input" PR branch supports list[Path] input. For local runs only, not supported in Web UI yet, in progress. Example:

$ echo test1 > 1.txt
$ echo test2 > 2.txt
$ cat predict.py
from cog import BasePredictor, Path

class Predictor(BasePredictor):
   def predict(self, paths: list[Path]) -> str:
       output_parts = []  # Use a list to collect file contents
       for path in paths:
           with open(path) as f:
             output_parts.append(f.read())
       return "".join(output_parts)

$ cog predict -i 'paths=["@1.txt", "@1.txt"]'

Running prediction...
test1

test2

Thanks a lot @dkhokhlov!

yosun commented 8 months ago

@yosun

cog on "support_for_list_in_input" PR branch supports list[Path] input. For local runs only, not supported in Web UI yet, in progress. Example:

$ echo test1 > 1.txt
$ echo test2 > 2.txt
$ cat predict.py
from cog import BasePredictor, Path

class Predictor(BasePredictor):
   def predict(self, paths: list[Path]) -> str:
       output_parts = []  # Use a list to collect file contents
       for path in paths:
           with open(path) as f:
             output_parts.append(f.read())
       return "".join(output_parts)

$ cog predict -i 'paths=["@1.txt", "@1.txt"]'

Running prediction...
test1

test2

is this also supported via API, if so what's the brief format?

dkhokhlov commented 8 months ago

it will be supported by api. format should be the same as in list[str] case, except str is uri str now..