{"notes":[{"id":"text-recognition/clip4str","category":"text-recognition","legacyPath":"text-recognition/2305-clip4str","legacySlug":"2305-clip4str","legacyPaths":[],"title":"CLIP4STR","subtitle":"The Blessing of Multimodality","author":"Z. Yuan","paperDate":"2023-05-23","publishedOn":"2024-11-13","paperTitle":"CLIP4STR: A Simple Baseline for Scene Text Recognition with Pre-trained Vision-Language Model","paperUrl":"https://arxiv.org/abs/2305.14014","bibliography":{"title":"CLIP4STR: A Simple Baseline for Scene Text Recognition with Pre-trained Vision-Language Model","authors":["Shuai Zhao","Ruijie Quan","Linchao Zhu","Yi Yang"],"url":"https://arxiv.org/abs/2305.14014","pdfUrl":"https://arxiv.org/pdf/2305.14014","codeUrl":null,"preprint":{"id":"2305.14014","submittedOn":"2023-05-23","url":"https://arxiv.org/abs/2305.14014"},"publication":{"venue":"IEEE Transactions on Image Processing","shortVenue":"IEEE TIP","year":2024,"kind":"journal","url":"https://doi.org/10.1109/tip.2024.3512354"},"citation":"@misc{textrecognitionclip4str2023,\n  title = {{CLIP4STR: A Simple Baseline for Scene Text Recognition with Pre-trained Vision-Language Model}},\n  author = {Shuai Zhao and Ruijie Quan and Linchao Zhu and Yi Yang},\n  year = {2023},\n  eprint = {2305.14014},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2305.14014}\n}\n","citationPath":"/content/papers/citations/text-recognition/clip4str.1bfcbd35312c.bib"},"thumbnail":{"src":"/content/papers/assets/48bc304d4a866c791752cee7e3a7122667eedf77db229de1566e986c3fa4f6bc.jpg","width":1318,"height":308},"locale":"en","path":"/content/papers/en/text-recognition/clip4str.99bb767601f9.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"clip","text":"CLIP","depth":2},{"id":"so-what-does-this-mean","text":"So, What Does This Mean?","depth":3},{"id":"zero-shot-testing","text":"Zero-Shot Testing","depth":3},{"id":"problem-solving","text":"Problem Solving","depth":2},{"id":"model-architecture","text":"Model Architecture","depth":3},{"id":"text-decoder","text":"Text Decoder","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"comparison-with-other-methods","text":"Comparison with Other Methods","depth":3},{"id":"basic-ablation-study","text":"Basic Ablation Study","depth":3},{"id":"how-should-we-freeze-clip","text":"How Should We Freeze CLIP?","depth":3},{"id":"is-multimodality-really-useful","text":"Is Multimodality Really Useful?","depth":3},{"id":"can-we-use-peft","text":"Can We Use PEFT?","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"tags":["text-recognition","multimodality","vision-transformers","zju"],"relatedReading":[{"id":"multimodality/clip","relation":"background","topic":"Transferring image-text pretraining to OCR"}]},{"id":"multimodality/clip","category":"multimodality","legacyPath":"multimodality/2103-clip","legacySlug":"2103-clip","legacyPaths":["multi-model/2021/clip"],"title":"CLIP","subtitle":"Breaking the Dimensional Barrier","author":"Z. Yuan","paperDate":"2021-02-26","publishedOn":"2024-04-04","paperTitle":"Learning Transferable Visual Models From Natural Language Supervision","paperUrl":"https://arxiv.org/abs/2103.00020","bibliography":{"title":"Learning Transferable Visual Models From Natural Language Supervision","authors":["Alec Radford","Jong Wook Kim","Chris Hallacy","Aditya Ramesh","Gabriel Goh","Sandhini Agarwal","Girish Sastry","Amanda Askell","Pamela Mishkin","Jack Clark","Gretchen Krueger","Ilya Sutskever"],"url":"https://arxiv.org/abs/2103.00020","pdfUrl":"https://cdn.openai.com/papers/Learning_Transferable_Visual_Models_From_Natural_Language.pdf","codeUrl":"https://github.com/openai/CLIP","preprint":{"id":"2103.00020","submittedOn":"2021-02-26","url":"https://arxiv.org/abs/2103.00020"},"publication":{"venue":"ICML","year":2021,"kind":"conference","url":"https://proceedings.mlr.press/v139/radford21a.html"},"citation":"@misc{multimodalityclip2021,\n  title = {{Learning Transferable Visual Models From Natural Language Supervision}},\n  author = {Alec Radford and Jong Wook Kim and Chris Hallacy and Aditya Ramesh and Gabriel Goh and Sandhini Agarwal and Girish Sastry and Amanda Askell and Pamela Mishkin and Jack Clark and Gretchen Krueger and Ilya Sutskever},\n  year = {2021},\n  eprint = {2103.00020},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2103.00020}\n}\n","citationPath":"/content/papers/citations/multimodality/clip.a63b118c04c7.bib"},"thumbnail":{"src":"/content/papers/assets/03a0527e167fb49905db2879fecd0e0b7b140cb837e239778ffa7f83f02e25ef.jpg","width":1726,"height":622},"locale":"en","path":"/content/papers/en/multimodality/clip.f9c727d9ae23.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"the-solution","text":"The Solution","depth":2},{"id":"model-architecture","text":"Model Architecture","depth":3},{"id":"large-scale-dataset","text":"Large-Scale Dataset","depth":3},{"id":"training-details","text":"Training Details","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"zero-shot-learning","text":"Zero-Shot Learning","depth":3},{"id":"are-the-representations-any-good","text":"Are the Representations Any Good?","depth":3},{"id":"is-clip-truly-generalizable","text":"Is CLIP Truly Generalizable?","depth":3},{"id":"human-vs-machine","text":"Human vs. Machine","depth":3},{"id":"overlap-in-data","text":"Overlap in Data","depth":3},{"id":"limitations","text":"Limitations","depth":2},{"id":"ethical-concerns","text":"Ethical Concerns","depth":3},{"id":"conclusion","text":"Conclusion","depth":2},{"id":"key-contributions","text":"Key Contributions:","depth":3},{"id":"future-directions","text":"Future Directions:","depth":3}],"anchorAliases":{"match-the-text-before-trying-to-write-it":"model-architecture","four-hundred-million-pairs-and-a-sizable-training-bill":"large-scale-dataset","experimental-results-and-discussion":"discussion","strong-zero-shot-results-depend-on-the-task-and-the-baseline":"zero-shot-learning","distribution-shift-figure-13s-strength-and-figure-14s-warning":"is-clip-truly-generalizable","humans-overlapping-data-and-use-boundaries":"human-vs-machine"},"guide":null,"tags":["multimodality","image-classification","contrastive-learning","few-shot-learning","openai"],"relatedReading":[{"id":"model-tuning/coop","relation":"next","topic":"Adapting image-text models with prompts"},{"id":"multimodality/flip","relation":"comparison","topic":"Scaling and accelerating image-text pretraining"},{"id":"multimodality/florence","relation":"comparison","topic":"Scaling and accelerating image-text pretraining"}]}],"text":"Contrastive learning has swept across various fields.\n\nFollowing contrastive learning, multimodal learning has become a major focus in recent years, giving rise to a new term:\n\n- **VLM, Vision-Language Models.**\n\nIn the industry, almost everyone—regardless of age or background—can confidently chant: VLM!\n\nWith all the hype, it’s only natural for researchers in the field of text recognition to join the action, right?\n\n## Defining the Problem\n\nScene Text Recognition (STR) faces challenges when dealing with text that is rotated, curved, blurred, or occluded. Despite decades of work, STR’s performance on these challenging cases remains less than ideal.\n\nIt’s time to shake things up.\n\nSince CLIP was introduced in 2021, its powerful cross-modal learning capabilities have made it a hot topic. CLIP’s ability to perceive and interpret various text forms in natural images holds promise as a potential solution for STR.\n\nWait a second—what exactly is CLIP?\n\nWhy the sudden shift in style?\n\n\n> [!TIP]\n> \n> We’ve already explored CLIP, so readers unfamiliar with it might want to check out our previous article:\n> \n> - [**[21.03] CLIP: Breaking the Dimensional Barrier**](/blog/papers/multimodality/clip)\n\n\n## CLIP\n\nWe know you might not feel like diving into the details, so here’s a brief overview of CLIP.\n\nBelow is the architecture of CLIP:\n\n![clip arch](/content/papers/assets/03a0527e167fb49905db2879fecd0e0b7b140cb837e239778ffa7f83f02e25ef.jpg)\n\nImagine we have a set of image-text pairs, where one pair could be a picture of a dog and the caption “a cute little dog.”\n\nIn each training batch, CLIP processes multiple such pairs. The image encoder, possibly a ResNet or ViT, processes the images to obtain image features, while the text encoder, typically a Transformer, processes the text to obtain text features.\n\nThe model then compares these features to ensure that the cosine similarity between correctly matched images and text (e.g., a dog image and “a cute little dog”) is maximized, while the cosine similarity between mismatched pairs (e.g., a dog image and the text “an apple”) is minimized.\n\nIt’s a straightforward architecture!\n\nFinally, stack 400 million image-text pairs, and start training!\n\n### So, What Does This Mean?\n\nWhat’s the significance here?\n\nA trained CLIP model can retrieve images from text, or rank supplied text candidates for an image. It does not generate captions by itself. Image–text pretraining may also associate written text with its visual appearance, which motivates adapting CLIP to STR.\n\n- **Is there a link between text images and the text itself? That’s precisely what STR aims to resolve!**\n\nCLIP was trained on natural images from many settings, so its features may capture forms of text that ordinary STR training data misses. That makes it a promising starting point for improving STR.\n\nMost notably, for distorted, skewed, or heavily occluded text, CLIP’s data includes “unimaginable” varieties, so it may be able to detect these text features.\n\n\n> [!TIP]\n> \n> **What does “unimaginable” mean?**\n> \n> The scale is large, but the counting units differ. SynthText has roughly 800,000 full scene images, which can yield millions of cropped words. Union14M comprises roughly 14 million word images, including unlabeled ones. CLIP’s 400 million image–caption pairs are another type of sample.\n> \n> A ratio between these totals is not a like-for-like measure of OCR supervision.\n> \n> If you viewed one image per second, it would take you about 12 continuous years to go through the entire dataset.\n> \n\n\n### Zero-Shot Testing\n\nTo validate this concept, the authors conducted zero-shot testing on CLIP.\n\nThey wanted to see how much text CLIP could perceive. In the image below, the left column shows the input images, the middle column visualizes attention, and the right column shows scores for the supplied class candidates:\n\n\n\n![zero-shot](/content/papers/assets/64114e6176a188293b9ebc50363873c9397d6416b773b42a9abe33ee0e26dc06.jpg)\n\n\n\nTo our surprise, CLIP responds strongly to the text sticker, even when it is rotated or curved. These are scores over the supplied class candidates, though, rather than unrestricted transcription.\n\nFor the occluded example, both “cat” and “horse” receive weight, suggesting sensitivity to the visible text and image context. The displayed softmax scores depend on the candidate set and are not calibrated probabilities over all possible words.\n\n## Problem Solving\n\nSince CLIP already has a certain degree of text understanding, our goal now is to \"guide\" it, focusing its capabilities on the STR task.\n\n\n> [!TIP]\n> \n> CLIP4STR does not freeze CLIP completely: it fine-tunes the image encoder and freezes only part of the text encoder. The authors also compare other freezing choices below.\n\n\n### Model Architecture\n\n![model](/content/papers/assets/48bc304d4a866c791752cee7e3a7122667eedf77db229de1566e986c3fa4f6bc.jpg)\n\nAssuming you’re already familiar with CLIP, let’s dive straight into this architecture.\n\n---\n\nCLIP has two branches: a text branch and an image branch.\n\nIn the CLIP4STR architecture, the image is first fed into the \"CLIP image branch\" to obtain image features. These features are then passed into a custom “image decoder” to process the features and generate an initial text prediction.\n\nAs shown above, when an image is input, the model might first output something like \"briiad.\" Since this output may be incorrect, it is then fed into the \"CLIP text branch\" to extract text features.\n\nFinally, the text and image features are concatenated and fed into a custom \"cross-modal decoder\" to refine and produce the final text prediction. At inference, both branches first make autoregressive predictions in sequence; cloze masking can then refine them iteratively, with the cross-modal output used at the end.\n\nThe default configuration freezes the first half of the text encoder, rather than the entire text branch. The image encoder is fine-tuned through the visual branch. A stop-gradient on image features supplied to the cross-modal branch blocks that branch's backward path, allowing the visual branch to learn independently.\n\nThe CLIP text branch supplies a representation of the provisional text for correction; it does not generate the initial prediction.\n\n\n> [!TIP]\n> \n> The spell-checking concept here draws from ABINet. Readers interested in more details can refer to:\n> \n> - [**[21.03] ABINet: Thinking more!**](/blog/papers/text-recognition/abinet)\n\n\n### Text Decoder\n\n![decoder](/content/papers/assets/5956e1e49954f4e7c4895fdc567bed1a943a39a72ab7600b3f436fa6e757af05.jpg)\n\nRemember the \"cross-modal decoder\" module we mentioned earlier?\n\nThis module follows PARSeq's permuted sequence modeling and Transformer decoder design. The visual and cross-modal decoders have the same structure, but their second attention layer reads different features: the visual decoder uses image features, while the cross-modal decoder uses token-level features concatenated from the CLIP text and image encoders.\n\n\n> [!TIP]\n> \n> If you’re unfamiliar with PARSeq, feel free to check out our previous article:\n> \n> - [**[22.07] PARSeq: Wrod oerdr dseon't mteartr for redaing**](/blog/papers/text-recognition/parseq)\n\n\n## Discussion\n\n### Comparison with Other Methods\n\n![compare](/content/papers/assets/6e606a457216cea04cb582760d11bc640e4435673b366cefe0dd9caefc2babcb.jpg)\n\nThe imported table compares nine STR benchmark settings and separates synthetic from real training data. CLIP4STR reaches high accuracy in several columns, but the training data and model size differ between rows and must be considered when comparing methods.\n\n### Basic Ablation Study\n\n\n\n![ablation](/content/papers/assets/e1386dec0c94de3468aa526737205b7c7b3fb23d07661defc7377f4b2e8ee238.jpg)\n\n\n\nThe study begins with a baseline model that only includes a ViT-S encoder for the visual branch, with no pre-training.\n\n1. Introducing PSM (Permuted Sequence Modeling) and following PARSeq’s training recipe brings a 0.7-percentage-point accuracy improvement.\n2. Replacing the encoder with CLIP’s image encoder ViT-B/16 changes average accuracy only from **89.9% to 90.0%**, indicating a need for further adaptation.\n3. Adjusting training parameters by setting the patch size to 16×16, using a smaller learning rate for the encoder, a larger one for the decoder, and reducing training epochs to 16 rounds.\n\nAt this point, the model has already surpassed previous SOTA performance.\n\n4. Adding the cross-modal branch with features from all CLIP tokens raises the nine-benchmark average from **90.8% to 91.2%**; using only [CLASS] and [EOS] gives **90.6%** (added in the paper's v4 Table V; the figure above does not show this row).\n5. Introducing a larger model, ViT-L/14, yields an additional 0.7-percentage-point improvement in accuracy.\n\nThe CLIP-ViT-L/14 converges faster on STR than CLIP-ViT-B/16, requiring only 10 training epochs.\n\n### How Should We Freeze CLIP?\n\n\n\n![freeze](/content/papers/assets/c3792506cd9a5436850a659d4190485b230c8d3768ed10d32aee102439219f84.jpg)\n\n\n#Params counts trainable encoder parameters, while `token` indicates the use of pre-trained token embeddings only.<br/>The top half shows the frozen text branch, and the bottom half shows the frozen image branch.\n\n\n\n\n\n---\n\nCommon freezing strategies include:\n\n1. **Freezing part of the CLIP text branch**: The default freezes 6 of its 12 layers, and the paper tests other frozen-layer counts.\n2. **Freezing the CLIP image branch**: This makes the image branch untrainable, which could impact final performance.\n\nWith different numbers of frozen text-encoder layers, results rise or fall across the five tested benchmarks. Freezing many image-encoder layers causes a clearer decline.\n\nA variant using only the pretrained text token embeddings also comes close to the default setting. The authors take this as evidence that the language information needed for STR is often about words and phrases rather than the full range of language understanding tasks.\n\nFreezing the image model has a larger impact, possibly because CLIP was pretrained mainly on natural images while STR uses cropped word images. The results support keeping the image encoder trainable to narrow this gap.\n\n### Is Multimodality Really Useful?\n\n\n\n![multimodal](/content/papers/assets/f3ee91d7f5eee6c23a109a8ffa34db561c9e17e39c970aca2b377c24309feada.jpg)\n\n\n\nTo verify whether multimodal pre-training truly benefits STR, the authors re-trained the “image branch.”\n\nThree different image encoders were tested:\n\n- **Randomly Initialized ViT**: No pre-training.\n- **ImageNet-1K Pre-trained ViT**: Pre-trained on ImageNet-1K.\n- **ImageNet-21K Pre-trained ViT**: Pre-trained on ImageNet-21K.\n\nThis table compares only CLIP4STR-B's visual branch. Image-text pretraining outperforms training from scratch on four of the five benchmarks and ties it at **86.6%** on Uber. Both ImageNet-1K and ImageNet-21K pretraining fall below the scratch result in all five columns.\n\n\n> [!TIP]\n> \n> This is similar to what we saw with PARSeq: ImageNet classification pretraining did not help STR in this setting, while image-text pretraining should be judged on its own results.\n\n\n### Can We Use PEFT?\n\n\n\n![peft](/content/papers/assets/e32a5f2570ce422a5262e0a3a997edfd3dbdc4a88c647d8bf10e3ea7c3b9aa53.jpg)\n\n\n\nAside from full fine-tuning, parameter-efficient fine-tuning (PEFT) methods for large pre-trained models are becoming increasingly popular. For example, CoOp trains only learnable prefix prompts, while CLIP-Adapter adds tunable linear layers on top of a frozen VLM.\n\nGiven the success of PEFT methods in some tasks, the authors applied two PEFT methods to STR in this study:\n\n1. **CLIP-Adapter**: Adds two linear layers on top of the frozen CLIP model, with a residual addition ratio of $\\lambda = 0.2$.\n2. **LST (Ladder Side-Tuning)**: Uses a ladder side network with the frozen CLIP model, where features are downsampled, then upsampled to match the original feature dimensions.\n\nFor CLIP4STR-B's visual branch, CLIP-Adapter performs better than leaving the model frozen, but worse than full fine-tuning. LST improves accuracy further, though it also remains below full fine-tuning.\n\nWhen training resources are limited, LST serves as a viable alternative.\n\n\n> [!TIP]\n> \n> For further reading on LLM tuning, we’ve reviewed a few papers previously, which readers might find useful:\n> \n> - [**[19.02] Adapter: Saving 96% of Parameters**](/blog/papers/model-tuning/adapter)\n> - [**[21.01] Prefix-Tuning: Is it the Same or Different?**](/blog/papers/model-tuning/prefix-tuning)\n\n\n## Conclusion\n\nMultimodal models have done well across many fields in recent years. This study shows how CLIP can be applied to STR and reports leading results in several benchmark settings.\n\nThe road has not ended; perhaps it is time to turn.\n","imageSizes":{"/content/papers/assets/03a0527e167fb49905db2879fecd0e0b7b140cb837e239778ffa7f83f02e25ef.jpg":{"width":1726,"height":622},"/content/papers/assets/64114e6176a188293b9ebc50363873c9397d6416b773b42a9abe33ee0e26dc06.jpg":{"width":728,"height":1058},"/content/papers/assets/48bc304d4a866c791752cee7e3a7122667eedf77db229de1566e986c3fa4f6bc.jpg":{"width":1318,"height":308},"/content/papers/assets/5956e1e49954f4e7c4895fdc567bed1a943a39a72ab7600b3f436fa6e757af05.jpg":{"width":1636,"height":356},"/content/papers/assets/6e606a457216cea04cb582760d11bc640e4435673b366cefe0dd9caefc2babcb.jpg":{"width":1514,"height":928},"/content/papers/assets/e1386dec0c94de3468aa526737205b7c7b3fb23d07661defc7377f4b2e8ee238.jpg":{"width":1004,"height":500},"/content/papers/assets/c3792506cd9a5436850a659d4190485b230c8d3768ed10d32aee102439219f84.jpg":{"width":1016,"height":596},"/content/papers/assets/f3ee91d7f5eee6c23a109a8ffa34db561c9e17e39c970aca2b377c24309feada.jpg":{"width":1030,"height":300},"/content/papers/assets/e32a5f2570ce422a5262e0a3a997edfd3dbdc4a88c647d8bf10e3ea7c3b9aa53.jpg":{"width":736,"height":1008}}}
