Downloads · 30 days
1
8% of all-time downloads
ritzz01/cnn-mnn-model
cnn-mnn-model is a machine learning model from ritzz01. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
CNN-MNN Model for Image Captioning This repository contains the CNN-MNN model for generating image captions. This model leverages a Convolutional Neural Network (CNN) for image encoding and a Multi-Head Attention Netw…
Downloads · 30 days
1
8% of all-time downloads
All-time downloads
12
Public
Repo size
3.1 GB
Likes
0
Public
Click a slice to open those files.
.zip1.1 GB · 53%
From the Hugging Face model README
CNN-MNN Model for Image Captioning This repository contains the CNN-MNN model for generating image captions. This model leverages a Convolutional Neural Network (CNN) for image encoding and a Multi-Head Attention Network (MNN) for decoding to produce descriptive captions.
Model Description The CNN-MNN model is designed to generate captions for images by encoding visual information and decoding it into coherent text descriptions.
Model Card Model Type: CNN-MNN for Image Captioning Pretrained Weights: Available on Hugging Face Model Hub (update with actual path if applicable) Licenses: Apache License 2.0 Installation You can install the required libraries using pip:
bash Copy code pip install transformers torch torchvision pillow Usage Here’s a simple example of how to use the model for image captioning:
python Copy code from transformers import VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizer import torch from PIL import Image
model = VisionEncoderDecoderModel.from_pretrained('your_username/cnn-mnn-model') # Update with your model path feature_extractor = ViTImageProcessor.from_pretrained('your_username/cnn-mnn-model') tokenizer = AutoTokenizer.from_pretrained('your_username/cnn-mnn-model')
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') model.to(device)
max_length = 16 num_beams = 4 gen_kwargs = {'max_length': max_length, 'num_beams': num_beams}
def predict_step(image_paths): images = [] for image_path in image_paths: i_image = Image.open(image_path) if i_image.mode != 'RGB': i_image = i_image.convert(mode='RGB') images.append(i_image)
pixel_values = feature_extractor(images=images, return_tensors='pt').pixel_values
pixel_values = pixel_values.to(device)
output_ids = model.generate(pixel_values, **gen_kwargs)
preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
preds = [pred.strip() for pred in preds]
return preds
captions = predict_step(['your_image_path.jpg']) # Update with your image path print(captions) Sample Running Code Using Transformers Pipeline You can also use the Transformers pipeline for a simpler interface:
python Copy code from transformers import pipeline
image_to_text = pipeline('image-to-text', model='your_username/cnn-mnn-model') # Update with your model path
caption = image_to_text('https://example.com/path/to/your/image.jpg') # Update with an actual image URL print(caption) Model Performance The model has been evaluated on standard image captioning benchmarks. Refer to the associated documentation for details on performance metrics and datasets.
Citation If you use this model in your research, please cite the following:
bibtex Copy code @inproceedings{your_citation_key, title={Your Paper Title}, author={Your Name}, year={Year}, publisher={Publisher}, ... } License This project is licensed under the Apache License 2.0. See the LICENSE file for details.
Contact For questions or issues, feel free to open an issue in this repository or contact the authors via email.
Customization Model Weights: Update the model path with the actual Hugging Face model URL. Example Image Paths: Provide appropriate example paths for images. Citation Information: Update the citation section with relevant details if applicable. This README structure provides essential information for users of your model and can help in making it more accessible and understandable. If you have specific information or sections you'd like to include, feel free to ask!