Editor’s introduction
The research investigates whether large language models (LLMs) can understand images when transformed into Scalable Vector Graphics (SVG) format, a textual representation of visual data. The LLMs were tested on three computer vision tasks: visual reasoning and question answering, image classification under distribution shifts and few-shot conditions, and generating new images via visual prompting. Findings are limited to the specific tasks and datasets used, and the evaluation relies on structured prompts derived from SVG transformations, with performance measured using color-aware mIOU metrics. The work does not establish general visual perception in LLMs but demonstrates potential in a narrow, well-defined context where images are represented as text.
Introduction
Large-scale data and enormous compute: the effect of these two ingredients has been on display in recent years in the significantly increased capability of machine learning systems. Models operating on the two most popular forms of data - image and text - have particularly felt that effect the most. From the side dealing with textual data, we have seen the emergence of large language models (LLMs) such as ChatGPT and GPT-4. Similarly, on the vision side, large vision models (LVMs) have also shown impressive accomplishments.
When we compare these two realms, the abilities of LLMs stand out in a distinct way because of their remarkable abilities in reasoning, in-context learning, and open-ended tasks. These analytical capabilities are something that the vision models, despite their significant advances, have not yet mirrored to the same depth.
This distinction can be attributed to the inherent nature of their respective data: LLMs thrive on the diverse and sequential structure of textual data, which is conducive to understanding intricate relationships and producing contextually relevant responses. In contrast, the continuous and varied nature of visual data complicates the discernment of nuanced relationships, potentially hindering the depth of analysis LVMs can achieve. Moreover, there is an ongoing debate on whether LLMs, trained on internet-scale text data, can learn world models that could lead to AGI capabilities, or that they are fundamentally limited due to their lack of grounding on physical interaction and visual perception in the real world.
The disparity between LLMs and LVMs, and the debate on the necessity of physical interaction and perceptual grounding, intrigue us to a question: Can LLMs, which have never seen visual data, understand and reason about images? Answering this question will bring us closer to understanding the capabilities of LLMs beyond the textual domain, their fundamental limitations, and whether they possess world models. As such, our study takes a small but important step toward this goal.
Specifically, we evaluate whether an LLM can perform both discriminative and generative visual understanding tasks. For discriminative tasks, we study their capabilities in visual reasoning, visual question answering, few-shot learning for image classification, and their robustness to distribution shift in visual data. Surprisingly, despite never having seen dense visual data, LLMs perform much better than chance and are often robust to distribution shifts. For generative tasks, we study LLMs’ image generation ability through the task of visual prompting. We find that LLMs can identify transformations related to color, shape, style, and content from provided SVG examples, generating credible output that is consistent with those examples.
Leveraging LLMs for Visual Tasks
Upon observing the powerful reasoning capabilities of LLM, researchers began to harness its potential for visual tasks. Presently, there are three primary works to utilizing LLM for these purposes. The first work involves using LLM to produce textual guidelines. Vision models then rely on these instructions to execute a range of visual tasks. Examples include Visual ChatGPT, visual programming as seen in, and ViperGPT. The second work, as illustrated by LLaVA and MiniGPT4, incorporates the pretrained vision encoder model, along with a trainable projector. This allows for feeding visual features directly to LLMs, demonstrating remarkable reasoning abilities. VisionLLM presents bounding boxes and segmentation masks in text format (as polygons), enabling LLMs to address more intricate perception challenges. The third work seeks to represent images directly in a text-based format, bypassing the use of visual encoders. The goal here is to allow LLMs to interpret these text-based representations. For instance, LIFT represents images using their raw pixel values in textual form and then fine-tunes the language model on them for visual tasks. Another study explores image generation by expressing the image in text formats, like TiKZ or SVG.
Our novelty: Our study aligns with the third direction. Unlike LIFT, we represent images using SVG, a format that inherently encodes more structural information than raw pixel values. This could enable LLMs to better grasp intricate relationships and yield contextually relevant responses. Distinct from the investigation presented in, we conduct a comprehensive study of how LLMs process images via textual representations, including both discriminative and generative tasks.
Large Language Models
Large Language Models (LLMs) have attracted much attention in recent years due to their remarkable performance across numerous natural language processing tasks. GPT-3, developed by OpenAI, is a prime example of this category, boasting an immense scale of 175 billion parameters and human-like text generation capabilities. In a similar vein, BERT (Bidirectional Encoder Representations from Transformers), introduced by Google, takes advantage of the transformer architecture and has substantially enhanced the state-of-the-art across various tasks by learning deep bidirectional representations. ChatGPT, another noteworthy model, is a GPT variant specifically designed for human-like conversational abilities. The most recent iteration, GPT-4, succeeds GPT-3 and carries on the LLM advancements in terms of scale and performance. These models lay the groundwork for our research, enabling us to investigate their potential in more complex tasks such as image understanding and generation. Our work illustrates the applicability of LLMs to SVG-based image understanding and generation, paving the way for novel applications and research directions in the visual domain.
Visual reasoning
With all the successes in the traditional perception tasks like image classification/segmentation, visual reasoning still remains a pivotal challenge for many modern computer vision systems. It typically refers to the ability of a model to answer questions about different constituents of an image. To better understand what entails that task, we first discuss the dataset we use for this experiment.
Out-of-distribution Generalization
To DNNs, innocuous transformations can completely change predictions. This has been reported in various cases such as shifting the image by a few pixels, adding a bit of random noise or changing the background, color, or texture while keeping the shape intact. In this section, we aim to investigate if representing images as SVG could mitigate these issues and result in a model focusing more on recognizing the target shapes.
Task and experimental setting: In the first setup, we fine-tune the ImageNet pre-trained vision model ConvNeXt using PNG images and the pre-trained language model Vicuna using both PNG images and SVG-converted images on MNIST. Subsequent testing is carried out on both Colored-MNIST variants (A) and (B). This setup seeks to examine whether the model can prioritize shape over other features for its predictions. In the second setup, our objective is to explore the potential of harnessing the potent in-context capabilities of Large Language Models (LLMs) to enhance image classification using SVG. So, we employ GPT-4 to conduct both zero-shot and in-context learning on MNIST variants. More details on ConvNeXt and Vicuna fine-tuning, prompting for in context learning can be found in the appendix.
Visual Question Answering
Task and experimental setting: In this task, LLMs are tasked with answering various questions regarding the attributes of objects, including their color, category, and usage. We query representative LLMs, including GPT-3.5, GPT-4, and the recent SoTA open-sourced LLM Mixtral-8x7B. After getting their responses, we leverage GPT-4 to rate whether the LLM prediction is correct again using in-context examples.
Visual Prompting
The previous sections discussed the emergent abilities of LLMs in discriminative tasks. Now, we turn our attention towards the generative side to see if LLMs can understand and generate logically coherent images as well. We consider the task of visual prompting, where, given a series of images, the goal is to learn the transformation and fill in the remaining spot with an appropriate image.
Conclusion
This paper studied whether LLMs can “see” and understand images through the Scalable Vector Graphics (SVG) format. By converting raster images into SVG representations, we provided LLMs with a textual representation of visual data, enabling them to engage in a variety of computer vision tasks. Our exploration across three major domains—visual reasoning and question answering, image classification in the face of distribution shifts and with limited examples, and the generation of new images through visual prompting. Despite their primary design for natural language understanding, LLMs demonstrate a promising capacity to understand and generate visual content when it is represented in an SVG format. Additionally, we have collected a SVG question-answering dataset for future research aimed at assessing the visual understanding capabilities of LLMs. We believe that our work provides an exploratory step for understanding the capabilities of LLMs beyond the textual domain, whether they possess world models, and what their potential is.
Limitations
While the structured nature of the SVG representation does make them effective for certain visual tasks, that format also abstracts away the finer details of the natural images (e.g., the furry texture of a dog). To understand the negative effect of this abstraction, we consider the image classification task; specifically, 10-way classification on Imagenette dataset. We convert the images from the dataset into their corresponding SVG format and use the Vicuna-7B model to get the predicted class. This prompting method gives a top-1 accuracy of 68.14%. We also train a ResNet50 model on the original images, which achieves an accuracy of 90.62%. These results show that the loss of information during the SVG conversion can lead to a loss of performance for certain tasks.
Referring Segmentation
The objective of the task is to label pixels in an image or video that correspond to an object instance referred by a linguistic expression. SVG representation has two advantages. First, language instruction is naturally embedded within the prompt, thus a separate design of the image segmentation model is not needed. Second, a large corpus of text and programming languages including XML are seen during pretraining, benefiting the vision-language understanding ability.
Raster Images to SVG Conversion
One of the most fundamental pieces of information for visual perception is object shape. Our method can be conceptualized as selectively diminishing details from an image, prioritizing the extraction of less significant shapes. This guided process of reduction offers a quantitative way to manage the amount of visual data present within an image. Within this framework, we perceive segmentation as an example of extreme simplification, whereas vectorization serves as a more moderate form of the same. Here we introduce how we use such two approaches to convert the raster images to SVG.
Image Vectorization
The vector tracing algorithm operates in a sequential three-step process. Initially, pixels are transformed into a defined path. Subsequently, this path is condensed into a simplified polygonal representation. Lastly, the polygon is refined and approximated using a curve-fitting (tracing) technique, which enhances its smoothness.
There are several online tools to convert the raster images (jpg and png) into vector graphics (SVG), such as Adobe Illustrator, Inkscape, and VTracer. We experiment with all of them and found that VTracer leads to the best balance between SVG complexity (code length) and rich semantic representation.
Segmentation Prior
As mentioned earlier, segmentation can provide a strong prior for object shape. We want a generalist model that can segment any image, i.e., not trained and thus biased towards a certain dataset. The Segment Anything (SA) project introduces such an image segmentation model, the Segment Anything Model (SAM), and a large-scale dataset, SA-1B, with the aim of achieving powerful generalization and zero-shot transfer across diverse segmentation tasks, demonstrating competitive results often surpassing prior fully supervised methods. We use the default hyper-parameters of SAM to segment the whole image into a set of masks without class labels, where the color of each mask is represented by the average value of the pixels within the mask. Specifically, we sample 32 query points per side (1024 points overall) to generate the image mask. Then we select the top 20 masks with the highest area as the final representation for an image.
We then use VTracer to transform the mask into SVG format. Note that, to reduce the final SVG, we adjust several settings: we set the number of significant bits to use in an RGB channel to 0; we set the minimum angle displacement degree to splice a spline to 90; we set the color difference between gradient layers to be 35; we consider a corner to have a minimum momentary angle of 0 degrees; we discard patches smaller than 16 pixels in size; and we perform iterative subdivide smoothing until all segments are shorter than 10 pixels.
Prompt Engineering
In this section, we provide the details of prompt engineering for each task. The prompt is designed to figure out the common transformation in the SVG example pairs first (each example pair consists of a query and a key) and then transform the query into the corresponding key SVG by following the discovered common transformation.


