Image Captioning — Hugging Face Space
Triển khai inference cho mô hình image captioning bằng TensorFlow/Keras, với giao diện Gradio đơn giản cho upload ảnh và nhận caption.
Image Captioning — Hugging Face Space
Triển khai inference cho mô hình image captioning dùng TensorFlow/Keras, EfficientNetV2B0 và giao diện Gradio.
Cấu trúc tệp cần có
.
├── app.py # UI Gradio cho Hugging Face Space
├── flickr30k.py # Logic model + tiền xử lý (đã cung cấp)
├── best_model.keras # Trọng số mô hình (đặt cùng thư mục)
├── tokenizer.pkl # Tokenizer đã fit
├── model_config.pkl # Chứa max_length, vocab_size
├── requirements.txt
└── README.md
Các hàm sử dụng trực tiếp từ flickr30k.py: load_caption_model, load_tokenizer_and_config, load_feature_extractor, extract_features_from_image, generate_caption.
Chạy cục bộ
python -m venv .venv
. .venv/bin/activate # Windows: .venv\Scripts\activate
pip install --upgrade pip
pip install -r requirements.txt
# Đảm bảo 3 tệp đã có:
# best_model.keras, tokenizer.pkl, model_config.pkl
python app.py
Mở URL Gradio hiển thị trong terminal.
Triển khai lên Hugging Face Spaces
- Tạo Space mới: SDK = Gradio, chọn CPU hoặc GPU tùy trọng số.
- Đẩy các tệp:
app.py,flickr30k.py,requirements.txt,README.md, và 3 tệp trọng số/cấu hình. - Sau khi build hoàn tất, Space sẽ mở UI upload ảnh và trả caption.
Ghi chú tương thích
- Mặc định dùng
tensorflow==2.12.0. Nếu bạn dùng trọng số huấn luyện ở phiên bản khác, cần đồng bộ phiên bản TensorFlow/Keras tương ứng. - Sử dụng
opencv-python-headlessthay vìopencv-pythonđể tránh lỗi GUI trên môi trường server. - Nếu thiếu tài nguyên trên Space Free, hạ kích thước mô hình hoặc chuyển phần cứng sang GPU trả phí.
- Downloads last month
- -
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
🙋
Ask for provider support