← All articles

scene graphsimage captioningexplainable aigraph methods

Turning a photo into a graph of what is in it, without training on graphs

A photo of a bedroom is more than a list of objects. The plant is on the table, the cushion sits on a wooden chair, the comforter is blue. A scene graph writes this down as nodes (things) joined by labelled edges (how they relate). Training a model to produce such graphs normally needs huge collections of images that people have annotated with graphs. We tried a different route: let existing models describe small parts of the image in words, then turn those sentences into graphs by fixed rules and merge them.

The problem

A scene graph is built from triplets of the form subject, predicate, object, such as plant, on top of, table. Learning these relations is hard. The number of possible combinations is huge, and a few combinations are very common while most are rare. Supervised models also need images with graph annotations, and the paper notes that these datasets have to be very large. Many existing methods also lean on tricks such as message passing, probabilistic models or statistics of the dataset, which are not easy to explain.

The idea

Our starting point was a hypothesis. A network that can write a caption for a picture must already encode some relational information about it, even if it never outputs a graph. A caption such as "a plant sitting on top of a table" contains a relation in plain language. So instead of building a dedicated graph model, we read the relations out of captions.

One caption for a whole image misses detail, so we caption regions. A pre-trained object detector called YOLO-V3 finds regions of interest. Each region is cropped, padded with zeros so that its shape is not distorted, resized to 224 × 224 pixels and passed to a pre-trained captioning model, Show, Attend and Tell. We kept a single caption per region to avoid redundancy. We trained none of these parts ourselves.

Block diagram. An input image is reshaped, regions are detected and cropped, each region gets a caption, each caption goes through a dependency parser into a small graph, and the small graphs are merged into one holistic graph.
Each coloured stream is one region: detect, crop, caption, parse, build a small graph. The graphs from all regions are merged at the end.Source: Fig. 2 of the paper.

How it works

To turn a caption into a graph, we first run the Stanford dependency parser. It labels how the words of a sentence depend on each other, for example which noun is the subject of which verb. From those labels, simple rules create the graph. Nouns become entity nodes, verbs become action nodes, and adjectives and adverbs become attribute nodes. Pronouns are handled too: "he" gives a masculine person with a "masculine" attribute, and "they" gives people. Auxiliary verbs such as "is" do not become actions.

Edges come from the dependency labels in the same way. A subject of a verb gives an agent edge, a direct object gives a patient edge, and a modifier gives an attr edge. Prepositions produce spatial edges such as on_top_of. Because every step is a written rule, you can trace why any node or edge exists. This is the sense in which the graph generation is explainable.

Table 2 lists some of the rules that turn a dependency into an edge. Read each row as: if the parser finds this dependency between words A and B, the rule adds the edge in the last column. Different dependencies can lead to the same kind of edge. A nominal subject and an oblique agent both give an agent edge, for example.

Some of the rules that turn dependencies into graph edges
Edge typeDependencyDescriptionEdge
AgentA → nsubj → BNominal SubjectB → agent → A
AgentA → obl:agent → BOblique AgentsB → agent → A
PatientA → obj → BDirect ObjectA → patient → B
PatientA → nsubj:pass → BPassive ObjectA → patient → B
AttributesA → amod → BAdjectival ModifierA → attr → B
AttributesA → advmod → BAdverbial ModifierA → attr → B
Spatial RelationsA → obl:preposition → BOblique Dependencies with prepositionsA → preposition → C
Spatial RelationsA → nmod:preposition → BNoun Modifiers with prepositionsA → preposition → C
Special relationsA → appos → BAppositional ModifierA → is → B
Special relationsA → conj → BConjunctionA → and → B
A selection of the rows of Table 2. Source: Table 2 of the paper.
Five rows, one per region caption. Each row shows the caption with its dependency parse on the left and the small graph built from it on the right.
Left: the dependency parse of each region caption. Right: the small graph our rules build from it.Source: Fig. 4 of the paper.

The region graphs overlap, so the last step merges them, using an approximate version of the maximum common subgraph idea (the largest piece two graphs share). Two entities are merged if they have the same lemma (the dictionary form of the word) and their bounding boxes overlap enough: the intersection divided by the area of the smaller box must be above 0.5. Entities with different words can also be merged if WordNet, a database of word meanings, puts them in the same synset, for example dog and hound. After two entities merge, their matching actions and attributes merge as well. Finally, if two overlapping regions name an entity at different levels of detail, such as "furniture" and "table", an is edge is added between them.

A bedroom photo with five coloured boxes and their captions, next to the merged scene graph. Dotted rectangles in the same colours show which parts came from which region.
Five regions of one bedroom photo become one graph. Green "is" edges link the general word "furniture" to bed, table and chair.Source: Fig. 1 of the paper.

What we found

Most related work relies on graph annotations as ground truth, so there is no fair way to compare our output with theirs. We therefore report statistics and examples. On the validation captions of the MSCOCO captioning dataset, our rules give on average 5.16 ± 1.00 entities, 2.06 ± 0.24 actions, 2.49 ± 0.87 attributes and 5.73 ± 1.55 relations per caption, where the average caption is 11.85 ± 2.04 words long.

The abstract's claim: rich concept graphs without explicit graph-based supervision, from a rule-based generator that works as plug-and-play with any region and caption model.

The merging rules can also keep things apart. In one example, two captions both mention a plant, but their boxes do not overlap, so the graph keeps two plants. Since several regions contribute, a completely wrong graph is unlikely, but partial mistakes happen.

Results in more detail

Merging removes redundancy. Before merging, the region graphs of one image together hold around 18.48 ± 12.47 entities, 3.48 ± 2.87 actions, 5.13 ± 4.84 attributes and 20.97 ± 15.86 relations. After merging, the same image has around 10.96 ± 6.06 entities, 1.94 ± 1.30 actions, 2.81 ± 2.11 attributes and 16.23 ± 10.57 relations. The scatter plot shows each count after merging against the count before, and the paper reads the trends as below linear for most cases.

Scatter plot with the number of graph elements before merging on the horizontal axis and after merging on the vertical axis, for relations, entities, attributes and actions. A black diagonal line and dotted trend lines are drawn.
Counts of relations, entities, attributes and actions in an image's graphs before merging (horizontal) and after merging (vertical). The dotted lines are trends.Source: Fig. 12 of the paper.

We also counted what the rules produce for captions of different lengths on the MSCOCO validation set. Table 3 gives the mean and the spread (mean ± standard deviation) of each kind of element for each caption length. Each row is one length in words, and the second column says how many captions had that length.

Graph elements per caption on MSCOCO validation captions, by caption length
No. of wordsNo. of captionsNo. of entitiesNo. of actionsNo. of attributesNo. of relations
83393.91 ± 0.592.02 ± 1.042.07 ± 0.964.03 ± 1.10
917324.34 ± 0.762.03 ± 0.162.26 ± 0.594.78 ± 0.89
1034184.67 ± 0.742.06 ± 0.232.31 ± 0.555.19 ± 1.07
1144375.02 ± 0.732.05 ± 0.222.28 ± 0.595.25 ± 1.11
1243445.17 ± 0.882.07 ± 0.262.49 ± 0.705.59 ± 1.12
1331975.57 ± 0.912.10 ± 0.302.54 ± 0.836.03 ± 1.24
1417455.79 ± 0.952.06 ± 0.252.68 ± 0.996.61 ± 1.38
159595.84 ± 1.112.05 ± 0.233.05 ± 1.327.25 ± 1.58
165536.18 ± 1.002.04 ± 0.193.20 ± 1.287.95 ± 1.88
172576.00 ± 1.262.05 ± 0.233.88 ± 1.688.76 ± 2.02
181186.79 ± 1.252.03 ± 0.183.53 ± 1.518.57 ± 1.81
19497.37 ± 1.182.16 ± 0.513.24 ± 1.369.02 ± 1.73
20216.62 ± 1.282.10 ± 0.304.52 ± 1.9710.81 ± 2.71
21126.50 ± 2.112.08 ± 0.295.92 ± 3.0312.25 ± 2.49
A selection of the rows of Table 3. Captions of 7 words and of 22 to 27 words, of which there are 5 or fewer each, are left out. Source: Table 3 of the paper.

The number of graph elements grows with the length of the caption, with entities following it most closely, then attributes, then actions. The number of actions hardly moves, between 2.02 and 2.16 in every row shown (Table 3). This is logical, since most of the actions in an image are shared by several entities. Relations climb from 4.03 for eight-word captions to 12.25 for 21-word ones (Table 3).

Scatter plot of the number of graph elements against the number of words in the caption, with a dotted straight-line fit for entities, actions, attributes and relations.
Number of graph elements against the number of words in the caption. The dotted lines are linear fits.Source: Fig. 13 of the paper.

The paper also walks through worked examples. For a simple image with one main object, the caption of the whole image would be enough, but the regional captions add attributes of the shirt and the tie (Fig. 14). Three very similar captions give a tightly joined graph, with a repeated action such as "sit" merged and several WordNet-based is edges (Fig. 15). A node such as "window" comes from a specific detection of the window, which the paper takes as a sign that graph generation is not limited by what YOLO-V3 detects (Fig. 16).

Discussion

Because the method uses no graph ground truth, a quantitative analysis is not feasible, and we could not measure correctness with a number. The graphs depend on the detector and the captioner, whose performance on COCO is recorded in their own papers. Partial mistakes show up in the examples. In one, a caption invents a tree, and in another a wooden carriage is called a bench or a fence. A person is made the agent of both drawing the carriage and riding the horses, possibly because of statistical bias in the captioner. A partly visible armchair is called a bed, and "each other" is turned into a node called "other".

We see the third-party detector and captioner as the major drawback. Because the approach is plug-and-play, they can be swapped for more robust ones. The step from region captions to region graphs is deterministic and depends only on the caption generator, and as a rule-based step it follows the principles of explainable AI, even though caption generation itself may not be completely explainable. We see the novelty in stabilising the whole workflow of region detection, captioning, dependency parsing, subgraph generation and graph merging, which differs from work guided by graph supervision or corpus knowledge.

We suggest that the holistic graphs could serve content-based image retrieval, visual question answering, image clustering, data warehousing and search engine optimisation. For future work we would refine the graphs by mapping nodes and edges to visual features learned from the image.

Sources

The figures and tables listed here are taken from the paper cited at the top of this page; the numbers quoted in the text come from it too.

  • Figures: Fig. 2, Fig. 4, Fig. 1, Fig. 12, Fig. 13
  • Tables: Table 2: rules that turn dependencies into graph edges; Table 3: number of graph elements per caption, by caption length

Acknowledgements

This work was funded by the Science and Engineering Research Board (DST), Govt. of India (Ref. EEQ/2018/000963). The authors are thankful to CMATER Laboratory, Dept. of CSE, Jadavpur University, for providing infrastructural support for this work.

Cite the paper

Swarnendu Ghosh, T Gonçalves, N Das (2023). Im2graph: A weakly supervised approach for generating holistic scene graphs from regional dependencies. Future Internet, 15(2):70 · MDPI.

BibTeX
@article{ghosh2023im2graph,
  author    = {Ghosh, Swarnendu and Gon{\c c}alves, T and Das, N},
  title     = {Im2graph: A weakly supervised approach for generating holistic scene graphs from regional dependencies},
  journal   = {Future Internet},
  volume    = {15},
  number    = {2},
  pages     = {70},
  publisher = {MDPI},
  year      = {2023},
  doi       = {10.3390/fi15020070}
}