vlm-captioning-tools
Python scripts to use for captioning images with VLMs
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (8.0%) to scientific vocabulary
Keywords
Repository
Python scripts to use for captioning images with VLMs
Basic Info
Statistics
- Stars: 39
- Watchers: 2
- Forks: 0
- Open Issues: 2
- Releases: 0
Topics
Metadata Files
README.md
VLM-Captioning-Tools
Python scripts to use for captioning images with VLMs
CogVLM Captioning Tool
This script uses CogVLM to create captions for one or more directories (including subdirectories) and lists of file paths in txt files. Repeating sequence caption failures caused by greedy search algorithms are automatically detected and resolved by changing model parameters when they arise.
Generated captions are saved in a parquet file with the following structure: ['image_name', 'hash', 'short_caption', 'long_caption', 'resolution'].
Usage:
First adjust the path_and_save_dir parameter's input directories and backup directory in the script to your liking. Then run it like this:
python cogvlm_captioning_tool.py
Prefixes
CogVLM often uses common prefix substrings in output captions. This function provides a way to remove those if desired.
``` def modify_caption(caption: str) -> str: """ Removes common prefix substrings from CogVLM outputs.
Args:
caption (str): A string containing a cogvlm caption.
Returns:
str: The caption with the prefix substring removed
or altered if it was present.
"""
base_words = ['showcases ', 'portrays ', 'appears to be ', 'is ', 'depicts ', 'features ']
prefix_substrings = [("The image " + s, '') for s in base_words] + [("This image " + s, '') for s in base_words]
prefix_substrings += [("In this " + s, '') for s in ["picture, ", "depiction, ", "piece, ", "image, ", "scene, "]]
prefix_substrings += [
('In this artwork, ', 'Artwork of '),
('In this illustration, ', 'Illustration of '),
('In this art piece, ', 'Art of ')
]
pattern = '|'.join([re.escape(opening) for opening, _ in prefix_substrings])
replacers = {opening: replacer for opening, replacer in prefix_substrings}
def replace_fn(match):
return replacers[match.group(0)]
return re.sub(pattern, replace_fn, caption, count=1, flags=re.IGNORECASE).capitalize()
```
MoonDream Captioning Tool
This script uses MoonDream to create captions for one or more directories (including subdirectories) and lists of file paths in txt files. Repeating sequence caption failures caused by greedy search algorithms are automatically detected and resolved by changing model parameters when they arise.
Generated captions are saved in a parquet file with the following structure: ['image_name', 'hash', 'short_caption', 'long_caption', 'resolution'].
Usage:
First adjust the batch_size and path_and_save_dir parameter's input directories and backup directory in the script to your liking. Then run it like this:
python moondream_batch_captioning_tool.py
Dolphin Caption Summarization Tool
This script uses the Dolphin 2.6 Mistral 7b - DPO LLM model to create a shortened version of the long_caption value for every item in the provided parquet's short_caption column.
Usage:
First adjust the input parquet and output parquet parameters in the script to your liking. Then run it like this:
python dolphin_mistral_short_captioning_tool.py
Meta Llama 3 Caption Summarization Tool
This script uses the Meta Llama 3 8B Instruct LLM model to create a shortened version of the long_caption value for every item in the provided parquet's short_caption column.
Usage:
First adjust the input parquet and output parquet parameters in the script to your liking. Then run it like this:
python meta_llama3_short_captioning_tool.py
Bad Caption Finder Tool
This script provides the ability to determine the number of caption failures in a dataset due to greedy search induced failures. It is capable of detecting repeating characters, words, sentences, and more and thus is extremely robust. The same failed caption detection code is used in the CogVLM Captioning Tool script above to automatically detect and retry failed captions.
Usage:
First ensure the script loads your dataset captions (example code loads from parquet, but this can be changed). Then run it like this:
python bad_caption_finder.py
Owner
- Login: ProGamerGov
- Kind: user
- Location: Multiverse
- Repositories: 15
- Profile: https://github.com/ProGamerGov
Citation (CITATION.cff)
cff-version: 1.2.0 message: "If you use this software, please cite it as below." authors: - family-names: "Egan" given-names: "Ben" - family-names: "Redden" given-names: "Alex" title: "VLM Captioning Tools" version: 1.0.0 date-released: 2024-03-24 url: "https://github.com/ProGamerGov/VLM-Captioning-Tools" keywords: - "VLM" - "CogVLM" - "Dolphin 2.6 Mistral 7b - DPO" - "image captioning" - "research" license: MIT
GitHub Events
Total
- Issues event: 1
- Watch event: 7
- Delete event: 1
- Issue comment event: 2
- Push event: 3
- Pull request event: 2
- Create event: 1
Last Year
- Issues event: 1
- Watch event: 7
- Delete event: 1
- Issue comment event: 2
- Push event: 3
- Pull request event: 2
- Create event: 1
Issues and Pull Requests
Last synced: over 1 year ago
All Time
- Total issues: 1
- Total pull requests: 5
- Average time to close issues: N/A
- Average time to close pull requests: 1 day
- Total issue authors: 1
- Total pull request authors: 1
- Average comments per issue: 1.0
- Average comments per pull request: 0.0
- Merged pull requests: 5
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 5
- Average time to close issues: N/A
- Average time to close pull requests: 1 day
- Issue authors: 1
- Pull request authors: 1
- Average comments per issue: 1.0
- Average comments per pull request: 0.0
- Merged pull requests: 5
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- brandostrong (1)
Pull Request Authors
- ProGamerGov (9)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- accelerate *
- bitsandbytes *
- pandas *
- pillow *
- protobuf *
- pyarrow *
- torch *
- tqdm *
- transformers *
- xformers *