Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Refactor the Generate Interface #140

Merged
merged 50 commits into from
Apr 9, 2024
Merged

[Refactor] Refactor the Generate Interface #140

merged 50 commits into from
Apr 9, 2024

Conversation

kennymckormick
Copy link
Member

@kennymckormick kennymckormick commented Apr 3, 2024

After refactoring, all VLMs (no matter API ones or OpenSource ones), will follow the following input format:

  1. A list of dictionary: A multi-modal message is represented by a list of dictionary, each dictionary has two keys: type and value:

    1. type: We currently support two types, choices are ["image", "text"].
    2. value: When type=='text' , the value is the text message (a single string); when type=='image', the value can be the local path of an image file, or the image URL.

    Example:

    IMAGE_PTH = 'assets/apple.jpg'
    IMAGE_URL = 'https://raw.githubusercontent.com/open-compass/VLMEvalKit/main/assets/apple.jpg'
    msg1 = [
        dict(type='image', value=IMAGE_PTH),
        dict(type='text', value='What is in this image?')
    ]
    msg2 = [
        dict(type='image', value=IMAGE_URL),
        dict(type='image', value=IMAGE_URL),
        dict(type='text', value='How many apples are there in these images?')
    ]
    response = model.generate(msg1)
  2. For convenience sake, we also support to take a list of string as inputs. In that case, we will check if a string is an image path or image URL and automatically convert it to the list[dict] format.

    Example:

    IMAGE_PTH = 'assets/apple.jpg'
    IMAGE_URL = 'https://raw.githubusercontent.com/open-compass/VLMEvalKit/main/assets/apple.jpg'
    msg1 = [IMAGE_PTH, 'What is in this image?']
    msg2 = [IMAGE_URL, IMAGE_URL,  'How many apples are there in these images?']
    response = model.generate(msg1)
  3. Though the input format accepts multiple images in a multi-modal message, sometimes the VLM does not support that feature (for example, some VLMs only accept a single image). In such case, only the first image will be processed by the VLM, and there will be a warning message.

  4. Another advantage of the new format is, it can be compatible with potential future updates. For examples, in the future, new types can be added to be compatible with audio or signals from custom sensors.

@kennymckormick kennymckormick changed the title [WIP] Refactor the Generate Interface [Refactor] Refactor the Generate Interface Apr 8, 2024
@kennymckormick kennymckormick merged commit ea0ff61 into main Apr 9, 2024
2 checks passed
@kennymckormick kennymckormick deleted the interface branch April 16, 2024 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant