Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 7 min read Case study mediumAdept

Fine tuning CLIP with Remote Sensing (Satellite) images and captions

Fine-tuning OpenAI's CLIP (ViT-B/32) on satellite image-caption pairs from RSICD, UCM and Sydney datasets using JAX/Flax on TPUs substantially improves zero-shot-style retrieval on remote sensing imagery: top-1 accuracy over 30 categories rose from 0.572 for the pretrained baseline to 0.883. Overfitting on the small dataset was reduced with Torchvision image augmentations and Marian MT backtranslation to fill out captions. The best run used batch size 1024 across 8 TPU cores with Adam at learning rate 5e-6. A demo serves text-to-image and image-to-image search via an NMSLib ANN index, and localizes text features by matching against encoded image patches.

Assumes: contrastive learning basicsCLIP image-text embeddingsmodel fine-tuning

Related posts

  • New ViT and ALIGN Models From Kakao Brain

    Hugging Face mediumAdept

    Kakao Brain has released COYO-700M, an open image-text dataset of roughly 700 million web alt-text pairs, along with ViT and ALIGN models trained on it. The models use Google's original architectures and hyperparameters, and their training data is fully public, unlike Google's JFT-300M and ALIGN 1.8B. Kakao's ALIGN-B7-Base matches Google's on KNN classification and beats it on MS-COCO retrieval despite using far fewer pairs. ViT-L/16 performs similarly on ImageNet and ImageNet-ReaL. Compared with LAION, COYO ships richer per-pair metadata (CLIP similarity, NSFW, watermark, aesthetic and face-count scores), and code examples show how to stream it with 🤗 Datasets and run classification, zero-shot classification and embedding extraction with Transformers.

  • Image search with 🤗 datasets

    Hugging Face mediumAdept

    A text-to-image search over 10,000 British Library book embellishments can be built by loading the images with the 🤗 datasets ImageFolder loader and embedding them with the CLIP ViT-B/32 model via sentence_transformers. The embeddings are indexed with datasets' built-in add_faiss_index, and text prompts are queried with get_nearest_examples. push_to_hub stores intermediate datasets so work can move between machines, such as a laptop and a Colab GPU. Results for prompts like "a steam engine" or "a musical instrument" are not always correct but are usually reasonable, which is enough to search images by semantic content.

  • Zero-shot image-to-text generation with BLIP-2

    Hugging Face mediumAdept

    BLIP-2 connects a frozen pre-trained image encoder (ViT) to a frozen LLM (OPT or Flan-T5) through a lightweight Querying Transformer (Q-Former), the only trainable component. This cuts trainable parameters and pre-training cost while reaching state-of-the-art results on visual-language tasks. Q-Former is pre-trained in two stages. The first uses image-text contrastive, image-grounded generation and image-text matching losses. The second feeds its query outputs to the LLM as a visual prefix under a causal LM loss. Code examples with Hugging Face Transformers show zero-shot image captioning, prompted captioning, visual question answering with a "Question: Answer:" template, and chat-style prompting, which must stay within the 512-token context.

  • Multimodal Embedding & Reranker Models with Sentence Transformers

    Hugging Face mediumAdept

    Sentence Transformers v5.4 extends its familiar encode/similarity and CrossEncoder APIs to images, audio, video and mixed text-image inputs, mapping them into a shared embedding space for cross-modal search, visual document retrieval and multimodal RAG. Code examples show loading VLM-based models such as Qwen3-VL-Embedding-2B, using encode_query/encode_document for prompt-aware retrieval, ranking mixed-modality documents with multimodal rerankers, and combining both in a retrieve-then-rerank pipeline. Cross-modal similarity scores run lower than within-modality scores because of the modality gap, but relative ordering is preserved. VLM models need roughly 8 GB of VRAM for 2B variants and about 20 GB for 8B, while CLIP or text-only models suit CPU inference.

  • Image Similarity with Hugging Face Datasets and Transformers

    Hugging Face mediumAdept

    An image similarity system can be built by embedding images with a fine-tuned Vision Transformer (CLS token from the last hidden state) and ranking candidates by cosine similarity against a query embedding. The walkthrough uses 🤗 Transformers' AutoModel and 🤗 Datasets' batched map() to embed a 100-image subset of the Beans dataset, then retrieves top-k matches from the test split. For scale, brute-force search over 768-d embeddings becomes costly in memory and compute, so dimensionality reduction via random projection and locality-sensitive hashing, or a FAISS index through Datasets' add_faiss_index(), is recommended.

The quest for software engineering knowledge.

Look:
Layout: