<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Image-to-Graph Models on Hunter Heidenreich | ML Research Scientist</title><link>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/</link><description>Recent content in Image-to-Graph Models on Hunter Heidenreich | ML Research Scientist</description><image><title>Hunter Heidenreich | ML Research Scientist</title><url>https://hunterheidenreich.com/img/avatar.webp</url><link>https://hunterheidenreich.com/img/avatar.webp</link></image><generator>Hugo -- 0.147.7</generator><language>en-US</language><copyright>2026 Hunter Heidenreich</copyright><lastBuildDate>Sun, 05 Apr 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/index.xml" rel="self" type="application/rss+xml"/><item><title>GraSP: Graph Recognition via Subgraph Prediction (2026)</title><link>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/grasp-2026/</link><pubDate>Sun, 15 Mar 2026 00:00:00 +0000</pubDate><guid>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/grasp-2026/</guid><description>GraSP is a general image-to-graph framework using sequential subgraph prediction, applied to OCSR with 67.5% accuracy on QM9.</description><content:encoded><![CDATA[<h2 id="a-general-framework-for-visual-graph-recognition">A General Framework for Visual Graph Recognition</h2>
<p>GraSP (Graph Recognition via Subgraph Prediction) addresses a fundamental limitation in image-to-graph methods: existing solutions are task-specific and do not transfer between domains. Whether the task is OCSR, scene graph recognition, music notation parsing, or road network extraction, each domain has developed independent solutions despite solving the same conceptual problem of extracting a graph from an image.</p>
<p>The key insight is that graph recognition can be reformulated as sequential subgraph prediction using a binary classifier, sidestepping two core difficulties of using graphs as neural network outputs:</p>
<ol>
<li><strong>Graph isomorphism</strong>: An uncolored graph with $n$ nodes has $n!$ equivalent representations, making direct output comparison intractable</li>
<li><strong>Compositional outputs</strong>: Nodes, edges, and features are interdependent, so standard i.i.d. loss functions are insufficient</li>
</ol>
<h2 id="sequential-subgraph-prediction-as-an-mdp">Sequential Subgraph Prediction as an MDP</h2>
<p>GraSP formulates graph recognition as a Markov Decision Process. Starting from an empty graph, the method iteratively expands the current graph by adding one edge at a time (connecting either a new node or two existing nodes). At each step, a binary classifier predicts whether each candidate successor graph is a subgraph of the target graph shown in the image.</p>
<p>The critical observation is that the optimal value function $V^{\pi^*}$ satisfies:</p>
<p>$$V^{\pi^*}(\mathcal{G}_t | \mathcal{I}) = 1 \iff \mathcal{G}_t \subseteq \mathcal{G}_{\mathcal{I}}$$</p>
<p>This means the value function reduces to a subgraph membership test, which can be learned as a binary classifier rather than requiring reinforcement learning. Greedy decoding then suffices: at each step, select any successor that the classifier predicts is a valid subgraph, and terminate when the classifier indicates the current graph is complete.</p>
<p>This formulation decouples <strong>decision</strong> (what to add) from <strong>generation</strong> (in what order), making the same model applicable across different graph types without modification.</p>
<h2 id="architecture-gnn--film-conditioned-cnn">Architecture: GNN + FiLM-Conditioned CNN</h2>
<p>The architecture has three components:</p>
<ol>
<li>
<p><strong>GNN encoder</strong>: A Message Passing Neural Network processes the candidate subgraph, producing a graph embedding. Messages are constructed as concatenations of source node features, target node features, and connecting edge features.</p>
</li>
<li>
<p><strong>FiLM-conditioned CNN</strong>: A ResNet-v2 processes the image, with FiLM layers placed after every normalization layer within each block. The graph embedding conditions the image processing, producing a joint graph-image representation.</p>
</li>
<li>
<p><strong>MLP classification head</strong>: Takes the conditioned image embedding plus a binary terminal flag (indicating whether this is a termination check) and predicts subgraph membership.</p>
</li>
</ol>
<p>The model uses only 7.25M parameters. Group Normalization is used in the CNN (8 groups per layer), Layer Normalization in the GNN and MLP.</p>
<h2 id="training-via-streaming-data-generation">Training via Streaming Data Generation</h2>
<p>Training uses a streaming architecture rather than a fixed dataset:</p>
<ul>
<li>For each iteration, a target graph $\mathcal{G}_T$ is sampled and rendered as an image</li>
<li><strong>Positive samples</strong> are generated by deleting edges that do not disconnect the graph (yielding valid subgraphs)</li>
<li><strong>Negative samples</strong> are generated by expanding successor states and checking via approximate subgraph matching</li>
<li>Two FIFO buffers (one for positives, one for negatives), each holding up to 25,000 images, maintain diverse and balanced mini-batches of 1024 samples</li>
<li>Training uses the RAdam optimizer with a cosine learning rate schedule (warmup over 50M samples, cycle of 250M samples) on 4 A100 GPUs with a 24h budget</li>
</ul>
<h2 id="synthetic-benchmarks-on-colored-trees">Synthetic Benchmarks on Colored Trees</h2>
<p>GraSP is evaluated on increasingly complex synthetic tasks involving colored tree graphs:</p>
<ul>
<li><strong>Small trees (6-9 nodes)</strong>: Tasks with varying numbers of node colors (1, 3, 5) and edge colors (1, 3, 5). The model works well across all configurations, with simpler tasks (fewer colors) converging faster.</li>
<li><strong>Larger trees (10-15 nodes)</strong>: The same trends hold but convergence is slower due to increased structural complexity.</li>
<li><strong>Out-of-distribution generalization</strong>: Models trained on 6-9 node trees show zero-shot generalization to 10-node trees, indicating learned patterns are size-independent.</li>
</ul>
<h2 id="ocsr-evaluation-on-qm9">OCSR Evaluation on QM9</h2>
<p>For the real-world OCSR evaluation, GraSP is applied to QM9 molecular images (grayscale, no stereo-bonds) with a 10,000-molecule held-out test set:</p>
<table>
  <thead>
      <tr>
          <th>Method</th>
          <th>Accuracy</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>OSRA</td>
          <td>45.61%</td>
      </tr>
      <tr>
          <td>GraSP</td>
          <td>67.51%</td>
      </tr>
      <tr>
          <td>MolGrapher</td>
          <td>88.36%</td>
      </tr>
      <tr>
          <td>DECIMER</td>
          <td>92.08%</td>
      </tr>
  </tbody>
</table>
<p>GraSP does not match state-of-the-art OCSR tools, but the authors emphasize that the same model architecture and training procedure transfers directly from synthetic tree tasks to molecular graphs with no task-specific modifications. The only domain knowledge incorporated is a simple chemistry rule: not extending nodes that already have degree four.</p>
<p>The method highlights the practical advantage of decoupling decision from generation. Functional groups can be represented at different granularities (as single nodes to reduce trajectory depth, or expanded to reduce trajectory breadth) without changing the model.</p>
<h2 id="reproducibility">Reproducibility</h2>
<table>
  <thead>
      <tr>
          <th>Artifact</th>
          <th>Type</th>
          <th>License</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><a href="https://github.com/c72bcbf4/grasp">GraSP Code</a></td>
          <td>Code</td>
          <td>Unknown</td>
          <td>Official implementation with pre-trained models</td>
      </tr>
  </tbody>
</table>
<p>The repository includes pre-trained models and example trajectories for interactive exploration. Training requires 4 A100 GPUs with a 24h time budget. The QM9 dataset used for OCSR evaluation is publicly available. No license file is included in the repository.</p>
<h2 id="limitations-and-future-directions">Limitations and Future Directions</h2>
<ul>
<li><strong>Finite type assumption</strong>: The current framework assumes a finite set of node and edge types, limiting applicability to open-vocabulary tasks like scene graph recognition</li>
<li><strong>Scaling to large graphs</strong>: For very large graphs, the branching factor of successor states becomes expensive. Learned filters to prune irrelevant successor states could help</li>
<li><strong>OCSR performance gap</strong>: While GraSP demonstrates transferability, it falls short of specialized OCSR tools that use domain-specific encodings (SMILES) or pixel-level supervision</li>
<li><strong>Modality extension</strong>: The framework could extend beyond images to other input modalities, such as vector embeddings of graphs</li>
</ul>
<h2 id="paper-information">Paper Information</h2>
<p><strong>Citation</strong>: Eberhard, A., Neumann, G., &amp; Friederich, P. (2026). Graph Recognition via Subgraph Prediction. <em>arXiv preprint arXiv:2601.15133</em>. <a href="https://arxiv.org/abs/2601.15133">https://arxiv.org/abs/2601.15133</a></p>
<p><strong>Publication</strong>: arXiv 2026</p>
]]></content:encoded></item><item><title>AdaptMol: Domain Adaptation for Molecular OCSR (2026)</title><link>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/adaptmol-2026/</link><pubDate>Sun, 15 Mar 2026 00:00:00 +0000</pubDate><guid>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/adaptmol-2026/</guid><description>AdaptMol is an image-to-graph OCSR model using MMD-based domain adaptation and self-training for hand-drawn molecule recognition.</description><content:encoded><![CDATA[<h2 id="bridging-the-synthetic-to-real-gap-in-graph-based-ocsr">Bridging the Synthetic-to-Real Gap in Graph-Based OCSR</h2>
<p>Most OCSR methods are trained on synthetic molecular images and evaluated on high-quality literature figures, both exhibiting relatively uniform styles. Hand-drawn molecules represent a particularly challenging domain with irregular bond lengths, variable stroke widths, and inconsistent atom symbols. Prior graph reconstruction methods like MolScribe and MolGrapher drop below 15% accuracy on hand-drawn images, despite achieving over 65% on literature datasets.</p>
<p>AdaptMol addresses this with a three-stage pipeline that enables effective transfer from synthetic to real-world data without requiring graph annotations in the target domain:</p>
<ol>
<li><strong>Base model training</strong> on synthetic data with comprehensive augmentation and dual position representation</li>
<li><strong>MMD alignment</strong> of bond-level features between source and target domains</li>
<li><strong>Self-training</strong> with SMILES-validated pseudo-labels on unlabeled target images</li>
</ol>
<h2 id="end-to-end-graph-reconstruction-architecture">End-to-End Graph Reconstruction Architecture</h2>
<p>AdaptMol builds on MolScribe&rsquo;s architecture, using a Swin Transformer base encoder ($384 \times 384$ input) with a 6-layer Transformer decoder (8 heads, hidden dim 256). The model jointly predicts atoms and bonds:</p>
<p><strong>Atom prediction</strong> follows the Pix2Seq approach, autoregressively generating a sequence of atom tokens:</p>
<p>$$S_N = [l_1, x_1, y_1, l_2, x_2, y_2, \dots, l_n, x_n, y_n]$$</p>
<p>where $l_i$ is the atom label and $(x_i, y_i)$ are discretized coordinate bin indices.</p>
<p><strong>Dual position representation</strong> adds a 2D spatial heatmap on top of token-based coordinate prediction. The heatmap aggregates joint spatial distributions of all atoms:</p>
<p>$$\mathbf{H} = \text{Upsample}\left(\sum_{i=1}^{n} P_y^{(i)} \otimes P_x^{(i)}\right)$$</p>
<p>where $P_x^{(i)}$ and $P_y^{(i)}$ are coordinate probability distributions from the softmax logits. During training, this heatmap is supervised with Gaussian kernels at ground-truth atom positions. This reduces false positive atom predictions substantially (from 356 to 33 false positives at IoU 0.05).</p>
<p><strong>Bond prediction</strong> extracts atom-level features from decoder hidden states and enriches them with encoder visual features via multi-head attention with a learnable residual weight $\alpha$:</p>
<p>$$\mathbf{F}_{\text{enriched}} = \text{LayerNorm}(\mathbf{F}_{\text{atom}} + \alpha \cdot \text{MHA}(\mathbf{F}_{\text{atom}}, \mathbf{E}_{\text{vis}}))$$</p>
<p>A feed-forward network then predicts bond types between all atom pairs.</p>
<h2 id="bond-level-domain-adaptation-via-mmd">Bond-Level Domain Adaptation via MMD</h2>
<p>The key insight is that bond features are domain-invariant: they encode structural relationships (single, double, triple, aromatic) independent of visual style. Atom-level alignment is problematic due to class imbalance (carbon dominates), multi-token spanning (functional groups), and position-dependent features.</p>
<p>AdaptMol aligns bond-level feature distributions via class-conditional Maximum Mean Discrepancy:</p>
<p>$$L_{\text{MMD}} = \frac{1}{|\mathcal{C}&rsquo;|} \sum_{c \in \mathcal{C}&rsquo;} MMD(F_c^{\text{src}}, F_c^{\text{tgt}})$$</p>
<p>where $\mathcal{C}&rsquo;$ contains classes with sufficient samples in both domains. Confidence-based filtering retains only high-confidence predictions (confidence &gt; 0.95, entropy &lt; 0.1) for alignment, tightening to 0.98 and 0.05 after the first epoch. Progressive loss weighting follows a schedule of 0.1 (epoch 0), 0.075 (epoch 1), and 0.05 thereafter.</p>
<p>An important side effect: MMD alignment improves inter-class bond discrimination, reducing confusion between visually similar bond types (e.g., jagged double bonds vs. aromatic bonds).</p>
<h2 id="self-training-with-smiles-validation">Self-Training with SMILES Validation</h2>
<p>After MMD alignment, the model generates predictions on unlabeled target images. Predicted molecular graphs are converted to SMILES and validated against ground-truth SMILES annotations. Only exact matches are retained as pseudo-labels, providing complete graph supervision (atom coordinates, element types, bond types) that was previously unavailable in the target domain.</p>
<p>This approach is far more data-efficient than alternatives: AdaptMol uses only 4,080 real hand-drawn images vs. DECIMER-Handdraw&rsquo;s 38 million synthetic hand-drawn images.</p>
<h2 id="comprehensive-data-augmentation">Comprehensive Data Augmentation</h2>
<p>Two categories of augmentation are applied during synthetic data generation:</p>
<ul>
<li><strong>Structure-rendering augmentation</strong>: Functional group abbreviation substitution, bond type conversions (single to wavy/aromatic, Kekule to aromatic rings), R-group insertion, and rendering parameter randomization (font family/size, bond width/spacing)</li>
<li><strong>Image-level augmentation</strong>: Geometric operations, quality degradation, layout variations, and chemical document artifacts (caption injection, arrows, marginal annotations)</li>
</ul>
<p>Structure-rendering augmentation provides the larger benefit, contributing ~20% accuracy improvement on JPO and ~30% on ACS benchmarks.</p>
<h2 id="results">Results</h2>
<h3 id="hand-drawn-molecule-recognition">Hand-Drawn Molecule Recognition</h3>
<table>
  <thead>
      <tr>
          <th>Method</th>
          <th>DECIMER test (Acc)</th>
          <th>ChemPix (Acc)</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><strong>AdaptMol</strong></td>
          <td><strong>82.6</strong></td>
          <td><strong>60.5</strong></td>
      </tr>
      <tr>
          <td>DECIMER v2.2</td>
          <td>71.9</td>
          <td>51.4</td>
      </tr>
      <tr>
          <td>AtomLenz</td>
          <td>30.0</td>
          <td>48.4</td>
      </tr>
      <tr>
          <td>MolScribe</td>
          <td>10.1</td>
          <td>26.1</td>
      </tr>
      <tr>
          <td>MolGrapher</td>
          <td>10.7</td>
          <td>14.5</td>
      </tr>
  </tbody>
</table>
<h3 id="literature-and-synthetic-benchmarks">Literature and Synthetic Benchmarks</h3>
<p>AdaptMol achieves state-of-the-art on 4 of 6 literature benchmarks:</p>
<table>
  <thead>
      <tr>
          <th>Dataset</th>
          <th>AdaptMol</th>
          <th>MolScribe</th>
          <th>MolGrapher</th>
          <th>DECIMER v2.2</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>CLEF</td>
          <td><strong>92.7</strong></td>
          <td>87.5</td>
          <td>57.2</td>
          <td>77.7</td>
      </tr>
      <tr>
          <td>JPO</td>
          <td><strong>88.2</strong></td>
          <td>78.8</td>
          <td>73.0</td>
          <td>75.7</td>
      </tr>
      <tr>
          <td>UOB</td>
          <td><strong>89.3</strong></td>
          <td>88.2</td>
          <td>85.1</td>
          <td>87.2</td>
      </tr>
      <tr>
          <td>ACS</td>
          <td><strong>75.5</strong></td>
          <td>72.8</td>
          <td>41.0</td>
          <td>37.7</td>
      </tr>
      <tr>
          <td>USPTO</td>
          <td>90.9</td>
          <td><strong>92.6</strong></td>
          <td>74.9</td>
          <td>59.6</td>
      </tr>
      <tr>
          <td>Staker</td>
          <td>84.0</td>
          <td><strong>84.4</strong></td>
          <td>0.0</td>
          <td>66.3</td>
      </tr>
  </tbody>
</table>
<p>MolScribe edges out on USPTO and Staker. The authors attribute this to MolScribe directly training on all 680K USPTO samples, which may cause it to specialize to that distribution.</p>
<h3 id="pipeline-ablation">Pipeline Ablation</h3>
<table>
  <thead>
      <tr>
          <th>Configuration</th>
          <th>Hand-drawn</th>
          <th>ChemDraw</th>
          <th>JPO</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Base model</td>
          <td>10.4</td>
          <td>92.3</td>
          <td>82.7</td>
      </tr>
      <tr>
          <td>+ Font augmentation</td>
          <td>30.2</td>
          <td>92.5</td>
          <td>82.8</td>
      </tr>
      <tr>
          <td>+ Font aug + MMD</td>
          <td>42.1</td>
          <td>94.0</td>
          <td>83.0</td>
      </tr>
      <tr>
          <td>+ Font aug + MMD + Self-training</td>
          <td><strong>82.6</strong></td>
          <td><strong>95.9</strong></td>
          <td><strong>88.2</strong></td>
      </tr>
  </tbody>
</table>
<p>Each component contributes meaningfully: font augmentation (+19.8), MMD alignment (+11.9), and self-training (+40.5) on hand-drawn accuracy.</p>
<h2 id="reproducibility">Reproducibility</h2>
<table>
  <thead>
      <tr>
          <th>Artifact</th>
          <th>Type</th>
          <th>License</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><a href="https://github.com/fffh1/AdaptMol">AdaptMol Code</a></td>
          <td>Code</td>
          <td>MIT</td>
          <td>Official implementation</td>
      </tr>
      <tr>
          <td><a href="https://huggingface.co/fffh1/AdaptMol/tree/main">Model + Data</a></td>
          <td>Model/Dataset</td>
          <td>MIT</td>
          <td>Pretrained checkpoint and datasets</td>
      </tr>
  </tbody>
</table>
<p>Training uses 2 NVIDIA A100 GPUs (40GB each). Base model trains for 30 epochs on 1M synthetic samples. Domain adaptation involves 3 steps: USPTO self-training (3 iterations of 3 epochs), MMD alignment on hand-drawn data (5 epochs), and hand-drawn self-training (5 iterations).</p>
<h2 id="limitations">Limitations</h2>
<ul>
<li>Sequence length constraints prevent accurate prediction of very large molecules (&gt;120 atoms), where resizing causes significant information loss</li>
<li>Cannot recognize Markush structures with repeating unit notation (parentheses/brackets), as synthetic training data lacks such cases</li>
<li>Stereochemistry information is lost when stereo bonds connect to abbreviated functional groups due to RDKit post-processing limitations</li>
<li>The retrained baseline (30 epochs from scratch on synthetic + pseudo-labels) achieves higher hand-drawn accuracy (87.2%) but at the cost of cross-domain robustness on literature benchmarks</li>
</ul>
<h2 id="paper-information">Paper Information</h2>
<p><strong>Citation</strong>: Hu, F., He, E., &amp; Verspoor, K. (2026). AdaptMol: Domain Adaptation for Molecular Image Recognition with Limited Supervision. <em>Research Square preprint</em>. <a href="https://doi.org/10.21203/rs.3.rs-8365561/v1">https://doi.org/10.21203/rs.3.rs-8365561/v1</a></p>
<p><strong>Publication</strong>: Research Square preprint, February 2026</p>
<p><strong>Additional Resources</strong>:</p>
<ul>
<li><a href="https://github.com/fffh1/AdaptMol">GitHub</a></li>
<li><a href="https://huggingface.co/fffh1/AdaptMol/tree/main">HuggingFace (model + data)</a></li>
</ul>
]]></content:encoded></item><item><title>MolScribe: Robust Image-to-Graph Molecular Recognition</title><link>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/molscribe/</link><pubDate>Fri, 19 Dec 2025 00:00:00 +0000</pubDate><guid>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/molscribe/</guid><description>Image-to-graph generation model for OCSR that predicts atoms, bonds, and coordinates jointly to better handle stereochemistry and abbreviations.</description><content:encoded><![CDATA[<h2 id="contribution-generative-image-to-graph-modelling">Contribution: Generative Image-to-Graph Modelling</h2>
<p>This is a <strong>Methodological Paper</strong> ($\Psi_{\text{Method}}$) with a secondary contribution to Resources ($\Psi_{\text{Resource}}$).</p>
<p>It proposes a novel architecture (image-to-graph generation) to solve the Optical Chemical Structure Recognition (OCSR) task, validating it through extensive ablation studies and comparisons against strong baselines like MolVec and DECIMER. It also contributes a new benchmark dataset of annotated images from ACS journals.</p>
<h2 id="motivation-limitations-in-existing-ocsr-pipelines">Motivation: Limitations in Existing OCSR Pipelines</h2>
<p>Translating molecular images into machine-readable graphs (OCSR) is challenging due to the high variance in drawing styles, stereochemistry conventions, and abbreviated structures found in literature.</p>
<p>Existing solutions face structural bottlenecks:</p>
<ul>
<li><strong>Rule-based systems</strong> (e.g., OSRA) rely on rigid heuristics that fail on diverse styles.</li>
<li><strong>Image-to-SMILES neural models</strong> treat the problem as captioning. They struggle with geometric reasoning (which is strictly required for chirality) and struggle to incorporate chemical constraints or verify correctness because they omit explicit atom locations.</li>
</ul>
<h2 id="core-innovation-joint-graph-and-coordinate-prediction">Core Innovation: Joint Graph and Coordinate Prediction</h2>
<p>MolScribe introduces an <strong>Image-to-Graph</strong> generation paradigm that combines the flexibility of neural networks with the precision of symbolic constraints. It frames the task probabilistically as:</p>
<p>$$
P(G | I) = P(A | I) P(B | A, I)
$$</p>
<p>Where the model predicts a sequence of atoms $A$ given an image $I$, followed by the bonds $B$ given both the atoms and the image.</p>
<ol>
<li><strong>Explicit Graph Prediction</strong>: It predicts a sequence of atoms (with 2D coordinates) and then predicts bonds between them.</li>
<li><strong>Symbolic Constraints</strong>: It uses the predicted graph structure and coordinates to strictly determine chirality and cis/trans isomerism.</li>
<li><strong>Abbreviation Expansion</strong>: It employs a greedy algorithm to parse and expand &ldquo;superatoms&rdquo; (e.g., &ldquo;CO2Et&rdquo;) into their full atomic structure.</li>
<li><strong>Dynamic Augmentation</strong>: It introduces a data augmentation strategy that randomly substitutes functional groups with abbreviations and adds R-groups during training to improve generalization.</li>
</ol>
<h2 id="methodology-autoregressive-atoms-and-pairwise-bonds">Methodology: Autoregressive Atoms and Pairwise Bonds</h2>
<p>The authors evaluate MolScribe on synthetic and real-world datasets, focusing on <strong>Exact Match Accuracy</strong> of the canonical SMILES string. The model generates atom sequences autoregressively:</p>
<p>$$
P(A | I) = \prod_{i=1}^n P(a_i | A_{&lt;i}, I)
$$</p>
<p>To handle continuous spatial locations, atom coordinates map to discrete bins (e.g., $\hat{x}_i = \lfloor \frac{x_i}{W} \times n_{\text{bins}} \rfloor$), and decode alongside element labels. Bonds act on a pairwise classifier over the hidden states of every atom pair:</p>
<p>$$
P(B | A, I) = \prod_{i=1}^n \prod_{j=1}^n P(b_{i,j} | A, I)
$$</p>
<ul>
<li><strong>Baselines</strong>: Compared against rule-based (MolVec, OSRA) and neural (Img2Mol, DECIMER, SwinOCSR) systems.</li>
<li><strong>Benchmarks</strong>:
<ul>
<li><strong>Synthetic</strong>: Indigo (in-domain) and ChemDraw (out-of-domain).</li>
<li><strong>Realistic</strong>: Five public benchmarks (CLEF, JPO, UOB, USPTO, Staker).</li>
<li><strong>New Dataset</strong>: 331 images from ACS Publications (journal articles).</li>
</ul>
</li>
<li><strong>Ablations</strong>: Tested performance without data augmentation, with continuous vs. discrete coordinates, and without non-atom tokens.</li>
<li><strong>Human Eval</strong>: Measured the time reduction for chemists using MolScribe to digitize molecules vs. drawing from scratch.</li>
</ul>
<h2 id="results-robust-exact-match-accuracy">Results: Robust Exact Match Accuracy</h2>
<ul>
<li><strong>Strong Performance</strong>: MolScribe achieved <strong>76-93% accuracy</strong> across public benchmarks, outperforming baselines on most datasets. On the ACS dataset of journal article images, MolScribe achieved 71.9% compared to the next best 55.3% (OSRA). On the large Staker patent dataset, MolScribe achieved 86.9%, surpassing MSE-DUDL (77.0%) while using far less training data (1.68M vs. 68M examples).</li>
<li><strong>Chirality Verification</strong>: Explicit geometric reasoning allowed MolScribe to predict chiral molecules significantly better than image-to-SMILES baselines. When chirality is ignored, the performance gap narrows (e.g., on Indigo, baseline accuracy rises from 94.1% to 96.3%), isolating MolScribe&rsquo;s primary advantage to geometric reasoning for stereochemistry.</li>
<li><strong>Hand-Drawn Generalization</strong>: The model achieved <strong>11.2% exact match accuracy</strong> on the DECIMER-HDM dataset, despite lacking hand-drawn images in the training set, with many errors bounded to a few atomic mismatches.</li>
<li><strong>Robustness</strong>: The model maintained high performance on perturbed images (rotation/shear), whereas rule-based systems degraded severely.</li>
<li><strong>Usability</strong>: The atom-level alignment allows for confidence visualization, and human evaluation showed it reduced digitization time from <strong>137s to 20s</strong> per molecule.</li>
</ul>
<hr>
<h2 id="reproducibility-details">Reproducibility Details</h2>
<h3 id="data">Data</h3>
<p>The model was trained on a mix of synthetic and patent data with extensive dynamic augmentation:</p>
<table>
  <thead>
      <tr>
          <th>Purpose</th>
          <th>Dataset</th>
          <th>Size</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Training</td>
          <td><strong>PubChem (Synthetic)</strong></td>
          <td>1M</td>
          <td>Molecules randomly sampled from PubChem and rendered via Indigo toolkit; includes atom coords.</td>
      </tr>
      <tr>
          <td>Training</td>
          <td><strong>USPTO (Patents)</strong></td>
          <td>680K</td>
          <td>Patent data lacks exact atom coordinates; relative coordinates normalized from MOLfiles to image dimensions (often introduces coordinate shifts).</td>
      </tr>
  </tbody>
</table>
<p><strong>Molecule Augmentation</strong>:</p>
<ul>
<li><strong>Functional Groups</strong>: Randomly substituted using 53 common substitution rules (e.g., replacing substructures with &ldquo;Et&rdquo; or &ldquo;Ph&rdquo;).</li>
<li><strong>R-Groups</strong>: Randomly added using vocabulary: <code>[R, R1...R12, Ra, Rb, Rc, Rd, X, Y, Z, A, Ar]</code>.</li>
<li><strong>Styles</strong>: Random variation of aromaticity (circle vs. bonds) and explicit hydrogens.</li>
</ul>
<p><strong>Image Augmentation</strong>:</p>
<ul>
<li><strong>Rendering</strong>: Randomized font (Arial, Times, Courier, Helvetica), line width, and label modes during synthetic generation.</li>
<li><strong>Perturbations</strong>: Applied rotation ($\pm 90^{\circ}$), cropping ($1%$), padding ($40%$), downscaling, blurring, and Salt-and-Pepper/Gaussian noise.</li>
</ul>
<p><strong>Preprocessing</strong>: Input images are resized to $384 \times 384$.</p>
<h3 id="algorithms">Algorithms</h3>
<ul>
<li><strong>Atom Prediction (Pix2Seq-style)</strong>:
<ul>
<li>The model generates a sequence of tokens: $S^A = [l_1, \hat{x}_1, \hat{y}_1, \dots, l_n, \hat{x}_n, \hat{y}_n]$.</li>
<li><strong>Discretization</strong>: Coordinates are binned into integer tokens ($n_{bins} = 64$).</li>
<li><strong>Tokenizer</strong>: Atom-wise tokenizer splits SMILES into atoms; non-atom tokens (parentheses, digits) are kept to help structure learning.</li>
</ul>
</li>
<li><strong>Bond Prediction</strong>:
<ul>
<li>Format: Pairwise classification for every pair of predicted atoms.</li>
<li>Symmetry: For symmetric bonds (single/double), the probability is averaged as:
$$
\hat{P}(b_{i,j} = t) = \frac{1}{2} \big( P(b_{i,j} = t) + P(b_{j,i} = t) \big)
$$
For wedges, directional logic strictly applies instead.</li>
</ul>
</li>
<li><strong>Abbreviation Expansion (Algorithm 1)</strong>:
<ul>
<li>A greedy algorithm connects atoms within an expanded abbreviation (e.g., &ldquo;COOH&rdquo;) until valences are full, avoiding the need for a fixed dictionary.</li>
<li><strong>Carbon Chains</strong>: Splits condensed chains like $C_aX_b$ into explicit sequences ($CX_q&hellip;CX_{q+r}$).</li>
<li><strong>Nested Formulas</strong>: Recursively parses nested structures like $N(CH_3)_2$ by treating them as superatoms attached to the current backbone.</li>
<li><strong>Valence Handling</strong>: Iterates through common valences first to resolve ambiguities.</li>
</ul>
</li>
</ul>
<h3 id="models">Models</h3>
<p>The architecture is an encoder-decoder with a classification head:</p>
<ul>
<li><strong>Encoder</strong>: <strong>Swin Transformer (Swin-B)</strong>, pre-trained on ImageNet-22K (88M params).</li>
<li><strong>Decoder</strong>: 6-layer Transformer, 8 heads, hidden dimension 256.</li>
<li><strong>Bond Predictor</strong>: 2-layer MLP (Feedforward) with ReLU, taking concatenated atom hidden states as input.</li>
<li><strong>Training</strong>: Teacher forcing, Cross-Entropy Loss, Batch size 128, 30 epochs.</li>
</ul>
<h3 id="evaluation">Evaluation</h3>
<p><strong>Metric</strong>: Exact Match of Canonical SMILES.</p>
<ul>
<li>Stereochemistry: Must match tetrahedral chirality; cis-trans ignored.</li>
<li>R-groups: Replaced with wildcards <code>*</code> or <code>[d*]</code> for evaluation.</li>
</ul>
<h3 id="hardware">Hardware</h3>
<ul>
<li><strong>Compute</strong>: Training performed on Linux server with <strong>96 CPUs</strong> and <strong>500GB RAM</strong>.</li>
<li><strong>GPUs</strong>: <strong>4x NVIDIA A100 GPUs</strong>.</li>
<li><strong>Training Time</strong>: Unspecified; comparative models on large datasets took &ldquo;more than one day&rdquo;.</li>
<li><strong>Inference</strong>: Requires autoregressive decoding for atoms, followed by a single forward pass for bonds.</li>
</ul>
<h3 id="artifacts">Artifacts</h3>
<table>
  <thead>
      <tr>
          <th>Artifact</th>
          <th>Type</th>
          <th>License</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><a href="https://github.com/thomas0809/MolScribe">MolScribe (GitHub)</a></td>
          <td>Code</td>
          <td>MIT</td>
          <td>Official PyTorch implementation with training, inference, and evaluation scripts</td>
      </tr>
      <tr>
          <td><a href="https://huggingface.co/spaces/yujieq/MolScribe">MolScribe (Hugging Face)</a></td>
          <td>Demo</td>
          <td>MIT</td>
          <td>Interactive web demo for molecular image recognition</td>
      </tr>
  </tbody>
</table>
<h3 id="limitations">Limitations</h3>
<ul>
<li>Scoped to single-molecule images only; does not handle multi-molecule diagrams or reaction schemes.</li>
<li>Hand-drawn molecule recognition remains weak (the model was not trained on hand-drawn data).</li>
<li>Complex Markush structures (positional variation, frequency variation) are not supported, as these cannot be represented in SMILES or MOLfiles.</li>
</ul>
<hr>
<h2 id="paper-information">Paper Information</h2>
<p><strong>Citation</strong>: Qian, Y., Guo, J., Tu, Z., Li, Z., Coley, C. W., &amp; Barzilay, R. (2023). MolScribe: Robust Molecular Structure Recognition with Image-To-Graph Generation. <em>Journal of Chemical Information and Modeling</em>, 63(7), 1925-1934. <a href="https://doi.org/10.1021/acs.jcim.2c01480">https://doi.org/10.1021/acs.jcim.2c01480</a></p>
<p><strong>Publication</strong>: Journal of Chemical Information and Modeling 2023</p>
<p><strong>Additional Resources</strong>:</p>
<ul>
<li><a href="https://huggingface.co/spaces/yujieq/MolScribe">Hugging Face Space</a></li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bibtex" data-lang="bibtex"><span style="display:flex;"><span><span style="color:#a6e22e">@article</span>{qianMolScribeRobustMolecular2023,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">title</span> = <span style="color:#e6db74">{{{MolScribe}}: {{Robust Molecular Structure Recognition}} with {{Image-To-Graph Generation}}}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">shorttitle</span> = <span style="color:#e6db74">{{{MolScribe}}}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">author</span> = <span style="color:#e6db74">{Qian, Yujie and Guo, Jiang and Tu, Zhengkai and Li, Zhening and Coley, Connor W. and Barzilay, Regina}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">year</span> = <span style="color:#ae81ff">2023</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">month</span> = apr,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">journal</span> = <span style="color:#e6db74">{Journal of Chemical Information and Modeling}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">volume</span> = <span style="color:#e6db74">{63}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">number</span> = <span style="color:#e6db74">{7}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">pages</span> = <span style="color:#e6db74">{1925--1934}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">doi</span> = <span style="color:#e6db74">{10.1021/acs.jcim.2c01480}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">url</span> = <span style="color:#e6db74">{https://pubs.acs.org/doi/10.1021/acs.jcim.2c01480}</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div>]]></content:encoded></item><item><title>MolMole: Unified Vision Pipeline for Molecule Mining</title><link>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/molmole/</link><pubDate>Fri, 19 Dec 2025 00:00:00 +0000</pubDate><guid>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/molmole/</guid><description>A vision-based deep learning framework that unifies molecule detection, reaction parsing, and OCSR for page-level chemical data extraction.</description><content:encoded><![CDATA[<h2 id="molmoles-dual-contribution-unified-ocsr-method-and-page-level-benchmarks">MolMole&rsquo;s Dual Contribution: Unified OCSR Method and Page-Level Benchmarks</h2>
<p>This is primarily a <strong>Method</strong> paper, with a strong <strong>Resource</strong> contribution.</p>
<p>It functions as a <strong>Method</strong> paper because it introduces &ldquo;MolMole,&rdquo; a unified deep learning framework that integrates molecule detection, reaction diagram parsing, and optical chemical structure recognition (OCSR) into a single pipeline. It validates this method through extensive comparisons against state-of-the-art baselines like DECIMER and OpenChemIE.</p>
<p>It also serves as a <strong>Resource</strong> paper because the authors construct and release a novel page-level benchmark dataset of 550 annotated pages (patents and articles) to address the lack of standardized evaluation metrics for full-page chemical extraction.</p>
<h2 id="addressing-the-limitations-of-fragmented-processing">Addressing the Limitations of Fragmented Processing</h2>
<p>The rapid accumulation of chemical literature has trapped valuable molecular and reaction data in unstructured formats like images and PDFs. Extracting this manually is time-consuming, while existing AI frameworks have significant limitations:</p>
<ul>
<li><strong>DECIMER</strong>: Lacks the ability to process reaction diagrams entirely.</li>
<li><strong>OpenChemIE</strong>: Relies on external layout parser models to crop elements before processing. This dependence often leads to detection failures in documents with complex layouts.</li>
<li><strong>Generative Hallucination</strong>: Existing generative OCSR models (like MolScribe) are prone to &ldquo;hallucinating&rdquo; structures or failing on complex notations like polymers.</li>
</ul>
<h2 id="a-unified-vision-pipeline-for-layout-aware-detection">A Unified Vision Pipeline for Layout-Aware Detection</h2>
<p>MolMole introduces several architectural and workflow innovations:</p>
<ul>
<li><strong>Direct Page-Level Processing</strong>: Unlike OpenChemIE, MolMole processes full document pages directly without requiring an external layout parser, which improves robustness on complex layouts like two-column patents.</li>
<li><strong>Unified Vision Pipeline</strong>: It integrates three specialized vision models into one workflow:
<ul>
<li><strong>ViDetect</strong>: A DINO-based object detector for identifying molecular regions.</li>
<li><strong>ViReact</strong>: An RxnScribe-based model adapted for full-page reaction parsing.</li>
<li><strong>ViMore</strong>: A detection-based OCSR model that explicitly predicts atoms and bonds.</li>
</ul>
</li>
<li><strong>Hallucination Mitigation</strong>: By using a detection-based approach (ViMore), the model avoids hallucinating chemical structures and provides confidence scores.</li>
<li><strong>Advanced Notation Support</strong>: The system explicitly handles &ldquo;wavy bonds&rdquo; (variable attachments in patents) and polymer bracket notations, which confuse standard SMILES-based models.</li>
</ul>
<h2 id="page-level-benchmark-evaluation-and-unified-metrics">Page-Level Benchmark Evaluation and Unified Metrics</h2>
<p>The authors evaluated the framework on both a newly curated benchmark and existing public datasets:</p>
<ul>
<li><strong>New Benchmark Creation</strong>: They curated 550 pages (300 patents, 250 articles) fully annotated with bounding boxes, reaction roles (reactant, product, condition), and MOLfiles.</li>
<li><strong>Baselines</strong>: MolMole was compared against <strong>DECIMER 2.0</strong>, <strong>OpenChemIE</strong>, and <strong>ReactionDataExtractor 2.0</strong>.</li>
<li><strong>OCSR Benchmarking</strong>: ViMore was evaluated against DECIMER, MolScribe, and MolGrapher on four public datasets: <strong>USPTO</strong>, <strong>UOB</strong>, <strong>CLEF</strong>, and <strong>JPO</strong>.</li>
<li><strong>Metric Proposal</strong>: They introduced a combined &ldquo;End-to-End&rdquo; metric that modifies standard object detection Precision/Recall to strictly require correct SMILES conversion for a &ldquo;True Positive&rdquo;.</li>
</ul>
<p>$$ \text{True Positive (End-to-End)} = ( \text{IoU} \geq 0.5 ) \land ( \text{SMILES}_{\text{gt}} == \text{SMILES}_{\text{pred}} ) $$</p>
<h2 id="key-results">Key Results</h2>
<ul>
<li><strong>Page-Level Performance</strong>: On the new benchmark, MolMole achieved F1 scores of <strong>89.1%</strong> (Patents) and <strong>86.8%</strong> (Articles) for the combined detection-to-conversion task, compared to 73.8% and 67.3% for DECIMER and 68.8% and 70.6% for OpenChemIE (Table 4).</li>
<li><strong>Reaction Parsing</strong>: ViReact achieved soft-match F1 scores of <strong>98.0%</strong> on patents and <strong>97.0%</strong> on articles, compared to 82.2% and 82.9% for the next best model, RxnScribe (w/o LP). Hard-match F1 scores were 92.5% (patents) and 84.6% (articles).</li>
<li><strong>Public Benchmarks</strong>: ViMore outperformed competitors on 3 out of 4 public OCSR datasets (CLEF, JPO, USPTO).</li>
<li><strong>Layout Handling</strong>: The authors demonstrated that MolMole successfully handles multi-column reaction diagrams where cropping-based models fail and faithfully preserves layout geometry in generated MOLfiles.</li>
</ul>
<h2 id="reproducibility">Reproducibility</h2>
<h3 id="artifacts">Artifacts</h3>
<table>
  <thead>
      <tr>
          <th>Artifact</th>
          <th>Type</th>
          <th>License</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><a href="https://lgai-ddu.github.io/molmole/">MolMole Project Page</a></td>
          <td>Other</td>
          <td>Unknown</td>
          <td>Demo and project information</td>
      </tr>
  </tbody>
</table>
<h3 id="data">Data</h3>
<ul>
<li><strong>Training Data</strong>: The models (ViDetect and ViMore) were trained on <strong>private/proprietary datasets</strong>, which is a limitation for full reproducibility from scratch.</li>
<li><strong>Benchmark Data</strong>: The authors introduce a test set of <strong>550 pages</strong> (3,897 molecules, 1,022 reactions) derived from patents and scientific articles. This dataset is stated to be made &ldquo;publicly available&rdquo;.</li>
<li><strong>Public Evaluation Data</strong>: Standard OCSR datasets used include USPTO (5,719 images), UOB (5,740 images), CLEF (992 images), and JPO (450 images).</li>
</ul>
<h3 id="algorithms">Algorithms</h3>
<ul>
<li><strong>Pipeline Workflow</strong>: PDF → PNG Images → Parallel execution of <strong>ViDetect</strong> and <strong>ViReact</strong> → Cropping of molecular regions → <strong>ViMore</strong> conversion → Output (JSON/Excel).</li>
<li><strong>Post-Processing</strong>:
<ul>
<li><em>ViDetect</em>: Removes overlapping proposals based on confidence scores and size constraints.</li>
<li><em>ViReact</em>: Refines predictions by correcting duplicates and removing empty entities.</li>
<li><em>ViMore</em>: Assembles detected atom/bond information into structured representations (MOLfile).</li>
</ul>
</li>
</ul>
<h3 id="models">Models</h3>
<table>
  <thead>
      <tr>
          <th>Model</th>
          <th>Architecture Basis</th>
          <th>Task</th>
          <th>Key Feature</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><strong>ViDetect</strong></td>
          <td>DINO (DETR-based)</td>
          <td>Molecule Detection</td>
          <td>End-to-end training; avoids slow autoregressive methods.</td>
      </tr>
      <tr>
          <td><strong>ViReact</strong></td>
          <td>RxnScribe</td>
          <td>Reaction Parsing</td>
          <td>Operates on full pages; autoregressive decoder for structured sequence generation.</td>
      </tr>
      <tr>
          <td><strong>ViMore</strong></td>
          <td>Custom Vision Model</td>
          <td>OCSR</td>
          <td>Detection-based (predicts atom/bond regions).</td>
      </tr>
  </tbody>
</table>
<h3 id="evaluation">Evaluation</h3>
<ul>
<li><strong>Molecule Detection</strong>: Evaluated using COCO metrics (AP, AR, F1) at IoU thresholds 0.50-0.95.</li>
<li><strong>Molecule Conversion</strong>: Evaluated using SMILES exact match accuracy and Tanimoto similarity.</li>
<li><strong>Combined Metric</strong>: A custom metric where a True Positive requires both IoU $\geq$ 0.5 and a correct SMILES string match where $\text{SMILES}_{\text{gt}} == \text{SMILES}_{\text{pred}}$.</li>
<li><strong>Reaction Parsing</strong>: Evaluated using <strong>Hard Match</strong> (all components correct) and <strong>Soft Match</strong> (molecular entities only, ignoring text labels).</li>
</ul>
<h3 id="missing-components">Missing Components</h3>
<ul>
<li><strong>Source code</strong>: Not publicly released. The paper states the toolkit &ldquo;will be accessible soon through an interactive demo on the LG AI Research website.&rdquo; For commercial use, the authors direct inquiries to contact <a href="mailto:ddu@lgresearch.ai">ddu@lgresearch.ai</a>.</li>
<li><strong>Training data</strong>: ViDetect and ViMore are trained on proprietary datasets. Training code and data are not available.</li>
<li><strong>Hardware requirements</strong>: Not specified in the paper.</li>
</ul>
<h2 id="paper-information">Paper Information</h2>
<p><strong>Citation</strong>: Chun, S., Kim, J., Jo, A., Jo, Y., Oh, S., et al. (2025). MolMole: Molecule Mining from Scientific Literature. <em>arXiv preprint arXiv:2505.03777</em>. <a href="https://doi.org/10.48550/arXiv.2505.03777">https://doi.org/10.48550/arXiv.2505.03777</a></p>
<p><strong>Publication</strong>: arXiv 2025</p>
<p><strong>Additional Resources</strong>:</p>
<ul>
<li><a href="https://lgai-ddu.github.io/molmole/">Project Page</a></li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bibtex" data-lang="bibtex"><span style="display:flex;"><span><span style="color:#a6e22e">@article</span>{chun2025molmole,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">title</span>=<span style="color:#e6db74">{MolMole: Molecule Mining from Scientific Literature}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">author</span>=<span style="color:#e6db74">{Chun, Sehyun and Kim, Jiye and Jo, Ahra and Jo, Yeonsik and Oh, Seungyul and Lee, Seungjun and Ryoo, Kwangrok and Lee, Jongmin and Kim, Seung Hwan and Kang, Byung Jun and Lee, Soonyoung and Park, Jun Ha and Moon, Chanwoo and Ham, Jiwon and Lee, Haein and Han, Heejae and Byun, Jaeseung and Do, Soojong and Ha, Minju and Kim, Dongyun and Bae, Kyunghoon and Lim, Woohyung and Lee, Edward Hwayoung and Park, Yongmin and Yu, Jeongsang and Jo, Gerrard Jeongwon and Hong, Yeonjung and Yoo, Kyungjae and Han, Sehui and Lee, Jaewan and Park, Changyoung and Jeon, Kijeong and Yi, Sihyuk}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">year</span>=<span style="color:#e6db74">{2025}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">journal</span>=<span style="color:#e6db74">{arXiv preprint arXiv:2505.03777}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">doi</span>=<span style="color:#e6db74">{10.48550/arXiv.2505.03777}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">url</span>=<span style="color:#e6db74">{https://arxiv.org/abs/2505.03777}</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div>]]></content:encoded></item><item><title>MolGrapher: Graph-based Chemical Structure Recognition</title><link>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/molgrapher/</link><pubDate>Fri, 19 Dec 2025 00:00:00 +0000</pubDate><guid>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/molgrapher/</guid><description>A graph-based deep learning approach for optical chemical structure recognition that outperforms image captioning methods.</description><content:encoded><![CDATA[<h2 id="1-contribution--type">1. Contribution / Type</h2>
<p>This is primarily a <strong>Methodological</strong> paper that proposes a novel neural architecture (MolGrapher), shifting the paradigm of Optical Chemical Structure Recognition (OCSR) from image captioning back to graph reconstruction. It also has a significant <strong>Resource</strong> component, releasing a synthetic data generation pipeline and a new large-scale benchmark (USPTO-30K) to address the scarcity of annotated real-world data.</p>
<h2 id="2-motivation">2. Motivation</h2>
<p>The automatic analysis of chemical literature is critical for accelerating drug and material discovery, but much of this information is locked in 2D images of molecular structures.</p>
<ul>
<li><strong>Problem:</strong> Existing rule-based methods are rigid, while recent deep learning methods based on &ldquo;image captioning&rdquo; (predicting <a href="/notes/chemistry/molecular-representations/notations/smiles/">SMILES</a> strings) struggle with complex molecules and fail to exploit the natural graph structure of molecules.</li>
<li><strong>Gap:</strong> There is a lack of diverse, annotated real-world training data, and captioning models suffer from &ldquo;hallucinations&rdquo; where they predict valid SMILES that do not match the image.</li>
</ul>
<h2 id="3-novelty--core-innovation">3. Novelty / Core Innovation</h2>
<p>MolGrapher introduces a <strong>graph-based deep learning pipeline</strong> that explicitly models the molecule&rsquo;s geometry and topology.</p>
<ul>
<li><strong>Supergraph Concept:</strong> It first detects all atom keypoints and builds a &ldquo;supergraph&rdquo; of all plausible bonds.</li>
<li><strong>Hybrid Approach:</strong> It combines a ResNet-based keypoint detector with a Graph Neural Network (GNN) that classifies both atom nodes and bond nodes within the supergraph context. Both atoms and bonds are represented as nodes, with edges only connecting atom nodes to bond nodes.</li>
<li><strong>Synthetic Pipeline:</strong> A data generation pipeline that renders molecules with varying styles (fonts, bond widths) and augmentations (pepper patches, random lines, captions) to simulate real document noise.</li>
</ul>
<p>At the core of the Keypoint Detector&rsquo;s performance is the <strong>Weight-Adaptive Heatmap Regression (WAHR)</strong> loss. Since pixels without an atom drastically outnumber pixels containing an atom, WAHR loss is designed to counter the class imbalance. For ground-truth heatmap $y$ and prediction $p$:</p>
<p>$$ L_{WAHR}(p, y) = \sum_i \alpha_y (p_i - y_i)^2 $$</p>
<p>where $\alpha_y$ dynamically down-weights easily classified background pixels.</p>
<h2 id="4-methodology--experiments">4. Methodology &amp; Experiments</h2>
<p>The authors evaluated MolGrapher against both rule-based (OSRA, MolVec) and deep learning baselines (DECIMER, Img2Mol, Image2Graph).</p>
<ul>
<li><strong>Benchmarks:</strong> Evaluated on standard datasets: USPTO, Maybridge UoB, CLEF-2012, and JPO.</li>
<li><strong>New Benchmark:</strong> Introduced and tested on <strong>USPTO-30K</strong>, split into clean, abbreviated, and large molecule subsets.</li>
<li><strong>Ablations:</strong> Analyzed the impact of synthetic augmentations, keypoint loss functions, supergraph connectivity radius, and GNN layers.</li>
<li><strong>Robustness:</strong> Tested on perturbed images (rotations, shearing) to mimic scanned patent quality.</li>
</ul>
<p>The GNN iteratively updates node embeddings through layers ${g^k}_{k \in [1, N]}$, where $e^{k+1} = g^k(e^k)$. Final predictions are obtained via two MLPs (one for atoms, one for bonds): $p_i = MLP_t(e_i^N)$, where $p_i \in \mathbb{R}^{C_t}$ contains the logits for atom or bond classes.</p>
<h2 id="5-results--conclusions">5. Results &amp; Conclusions</h2>
<p>MolGrapher achieved the highest accuracy among synthetic-only deep learning methods on most benchmarks tested.</p>
<ul>
<li><strong>Accuracy:</strong> It achieved <strong>91.5%</strong> accuracy on USPTO, outperforming all other synthetic-only deep learning methods including ChemGrapher (80.9%), Graph Generation (67.0%), and DECIMER 2.0 (61.0%).</li>
<li><strong>Large Molecules:</strong> It demonstrated superior scaling, correctly recognizing large molecules (USPTO-10K-L) where image captioning methods like Img2Mol failed completely (0.0% accuracy).</li>
<li><strong>Generalization:</strong> The method proved robust to image perturbations and style variations without requiring fine-tuning on real data. The paper acknowledges that MolGrapher cannot recognize Markush structures (depictions of sets of molecules with positional and frequency variation indicators).</li>
</ul>
<hr>
<h2 id="reproducibility-details">Reproducibility Details</h2>
<h3 id="data">Data</h3>
<p>The model relies on synthetic data for training due to the scarcity of annotated real-world images.</p>
<table>
  <thead>
      <tr>
          <th>Purpose</th>
          <th>Dataset</th>
          <th>Size</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><strong>Training</strong></td>
          <td>Synthetic Data</td>
          <td>300,000 images</td>
          <td>Generated from PubChem SMILES using RDKit. Augmentations include pepper patches, random lines, and variable bond styles.</td>
      </tr>
      <tr>
          <td><strong>Evaluation</strong></td>
          <td>USPTO-30K</td>
          <td>30,000 images</td>
          <td>Created by authors from USPTO patents (2001-2020). Subsets: 10K clean, 10K abbreviated, 10K large (&gt;70 atoms).</td>
      </tr>
      <tr>
          <td><strong>Evaluation</strong></td>
          <td>Standard Benchmarks</td>
          <td>Various</td>
          <td>USPTO (5,719), Maybridge UoB (5,740), CLEF-2012 (992), JPO (450).</td>
      </tr>
  </tbody>
</table>
<h3 id="algorithms">Algorithms</h3>
<p>The pipeline consists of three distinct algorithmic stages:</p>
<ol>
<li>
<p><strong>Keypoint Detection</strong>:</p>
<ul>
<li>Predicts a heatmap of atom locations using a CNN.</li>
<li>Thresholds heatmaps at the bottom 10th percentile and uses a $5\times5$ window for local maxima.</li>
<li>Uses <strong>Weight-Adaptive Heatmap Regression (WAHR)</strong> loss to handle class imbalance (background vs. atoms).</li>
</ul>
</li>
<li>
<p><strong>Supergraph Construction</strong>:</p>
<ul>
<li>Connects every detected keypoint to neighbors within a radius of $3 \times$ the estimated bond length.</li>
<li>Prunes edges with no filled pixels or if obstructed by a third keypoint.</li>
<li>Keeps a maximum of 6 bond candidates per atom.</li>
</ul>
</li>
<li>
<p><strong>Superatom Recognition</strong>:</p>
<ul>
<li>Detects &ldquo;superatom&rdquo; nodes (abbreviations like <code>COOH</code>).</li>
<li>Uses <strong>PP-OCR</strong> to transcribe the text at these node locations.</li>
</ul>
</li>
</ol>
<h3 id="models">Models</h3>
<p>The architecture utilizes standard backbones tailored for specific sub-tasks:</p>
<ul>
<li><strong>Keypoint Detector</strong>: <strong>ResNet-18</strong> backbone with $8\times$ dilation to preserve spatial resolution.</li>
<li><strong>Node Classifier</strong>: <strong>ResNet-50</strong> backbone with $2\times$ dilation for extracting visual features at node locations.</li>
<li><strong>Graph Neural Network</strong>: A custom GNN that updates node embeddings based on visual features and neighborhood context. The initial node embedding combines the visual feature vector $v_i$ and a learnable type encoding $w_{t_i}$.</li>
<li><strong>Readout</strong>: MLPs classify nodes into atom types (e.g., C, O, N) and bond types (No Bond, Single, Double, Triple).</li>
</ul>
<h3 id="evaluation">Evaluation</h3>
<p>Accuracy is defined strictly: the predicted molecule must have an identical <strong><a href="/notes/chemistry/molecular-representations/notations/inchi-2013/">InChI</a></strong> string to the ground truth. Stereochemistry and Markush structures are excluded from evaluation.</p>
<table>
  <thead>
      <tr>
          <th>Metric</th>
          <th>Dataset</th>
          <th>MolGrapher Score</th>
          <th>Best DL Baseline (Synthetic)</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Accuracy</td>
          <td>USPTO</td>
          <td><strong>91.5%</strong></td>
          <td>80.9% (ChemGrapher)</td>
          <td>Full USPTO benchmark</td>
      </tr>
      <tr>
          <td>Accuracy</td>
          <td>USPTO-10K-L</td>
          <td><strong>31.4%</strong></td>
          <td>0.0% (Img2Mol)</td>
          <td>Large molecules (&gt;70 atoms)</td>
      </tr>
      <tr>
          <td>Accuracy</td>
          <td>JPO</td>
          <td><strong>67.5%</strong></td>
          <td>64.0% (DECIMER 2.0)</td>
          <td>Challenging, low-quality images</td>
      </tr>
  </tbody>
</table>
<h3 id="hardware">Hardware</h3>
<ul>
<li><strong>GPUs</strong>: Trained on 3 NVIDIA A100 GPUs.</li>
<li><strong>Training Time</strong>: 20 epochs.</li>
<li><strong>Optimization</strong>: ADAM optimizer, learning rate 0.0001, decayed by 0.8 after 5000 iterations.</li>
<li><strong>Loss Weighting</strong>: Atom classifier loss weighted by 1; bond classifier loss weighted by 3.</li>
</ul>
<h3 id="artifacts">Artifacts</h3>
<table>
  <thead>
      <tr>
          <th>Artifact</th>
          <th>Type</th>
          <th>License</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><a href="https://github.com/DS4SD/MolGrapher">DS4SD/MolGrapher</a></td>
          <td>Code</td>
          <td>MIT</td>
          <td>Official PyTorch implementation with training and inference scripts</td>
      </tr>
  </tbody>
</table>
<hr>
<h2 id="paper-information">Paper Information</h2>
<p><strong>Title</strong>: MolGrapher: Graph-based Visual Recognition of Chemical Structures</p>
<p><strong>Authors</strong>: Lucas Morin, Martin Danelljan, Maria Isabel Agea, Ahmed Nassar, Valéry Weber, Ingmar Meijer, Peter Staar, Fisher Yu</p>
<p><strong>Citation</strong>: Morin, L., Danelljan, M., Agea, M. I., Nassar, A., Weber, V., Meijer, I., Staar, P., &amp; Yu, F. (2023). MolGrapher: Graph-based Visual Recognition of Chemical Structures. <em>Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)</em>, 19552-19561.</p>
<p><strong>Publication</strong>: ICCV 2023</p>
<p><strong>Links</strong>:</p>
<ul>
<li><a href="https://openaccess.thecvf.com/content/ICCV2023/html/Morin_MolGrapher_Graph-based_Visual_Recognition_of_Chemical_Structures_ICCV_2023_paper.html">Paper</a></li>
<li><a href="https://github.com/DS4SD/MolGrapher">GitHub Repository</a></li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bibtex" data-lang="bibtex"><span style="display:flex;"><span><span style="color:#a6e22e">@inproceedings</span>{morinMolGrapherGraphbasedVisual2023,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">title</span> = <span style="color:#e6db74">{{{MolGrapher}}: {{Graph-based Visual Recognition}} of {{Chemical Structures}}}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">shorttitle</span> = <span style="color:#e6db74">{{{MolGrapher}}}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">booktitle</span> = <span style="color:#e6db74">{Proceedings of the {{IEEE}}/{{CVF International Conference}} on {{Computer Vision}}}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">author</span> = <span style="color:#e6db74">{Morin, Lucas and Danelljan, Martin and Agea, Maria Isabel and Nassar, Ahmed and Weber, Valéry and Meijer, Ingmar and Staar, Peter and Yu, Fisher}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">year</span> = <span style="color:#e6db74">{2023}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">pages</span> = <span style="color:#e6db74">{19552--19561}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">doi</span> = <span style="color:#e6db74">{10.1109/ICCV51070.2023.01791}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">urldate</span> = <span style="color:#e6db74">{2025-10-18}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">langid</span> = <span style="color:#e6db74">{english}</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div>]]></content:encoded></item><item><title>MolMiner: Deep Learning OCSR with YOLOv5 Detection</title><link>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/molminer/</link><pubDate>Thu, 18 Dec 2025 00:00:00 +0000</pubDate><guid>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/molminer/</guid><description>Deep learning OCSR tool using YOLOv5 and MobileNetV2 to extract machine-readable molecular structures from scientific documents and PDFs.</description><content:encoded><![CDATA[<h2 id="classification-and-contribution">Classification and Contribution</h2>
<p>This is primarily a <strong>Resource</strong> paper ($\Psi_{\text{Resource}}$) with a strong <strong>Method</strong> component ($\Psi_{\text{Method}}$).</p>
<ul>
<li><strong>Resource</strong>: It presents a complete software application (published as an &ldquo;Application Note&rdquo;) for Optical Chemical Structure Recognition (OCSR), including a graphical user interface (GUI) and a new curated &ldquo;Real-World&rdquo; dataset of 3,040 molecular images.</li>
<li><strong>Method</strong>: It proposes a novel &ldquo;rule-free&rdquo; pipeline that replaces traditional vectorization algorithms with deep learning object detection (YOLOv5) and segmentation models.</li>
</ul>
<h2 id="motivation-bottlenecks-in-rule-based-systems">Motivation: Bottlenecks in Rule-Based Systems</h2>
<ul>
<li><strong>Legacy Backlog</strong>: Decades of scientific literature contain chemical structures only as 2D images (PDFs), which are not machine-readable.</li>
<li><strong>Limitations of Legacy Architecture</strong>: Existing tools (like OSRA, CLIDE, MolVec) rely on rule-based vectorization (interpreting vectors and nodes) which struggle with noise, low resolution, and complex drawing styles found in scanned documents.</li>
<li><strong>Deep Learning Gap</strong>: While deep learning (DL) has advanced computer vision, few practical, end-to-end DL tools existed for OCSR that could handle the full pipeline from PDF extraction to graph generation with high accuracy.</li>
</ul>
<h2 id="core-innovation-object-detection-paradigm-for-ocsr">Core Innovation: Object Detection Paradigm for OCSR</h2>
<ul>
<li><strong>Object Detection Paradigm</strong>: MolMiner shifts away from the strategy of line-tracing (vectorization), opting to treat atoms and bonds directly as objects to be detected using <strong>YOLOv5</strong>. This allows it to &ldquo;look once&rdquo; at the image.</li>
<li><strong>End-to-End Pipeline</strong>: Integration of three specialized modules:
<ol>
<li><strong>MobileNetV2</strong> for segmenting molecular figures from PDF pages.</li>
<li><strong>YOLOv5</strong> for detecting chemical elements (atoms/bonds) as bounding boxes.</li>
<li><strong>EasyOCR</strong> for recognizing text labels and resolving abbreviations (supergroups) to full explicit structures.</li>
</ol>
</li>
<li><strong>Synthetic Training Strategy</strong>: The authors bypassed manual labeling by building a data generation module that uses RDKit to create chemically valid images with perfect ground-truth annotations automatically.</li>
</ul>
<h2 id="methodology-end-to-end-object-detection-pipeline">Methodology: End-to-End Object Detection Pipeline</h2>
<ul>
<li><strong>Benchmarks</strong>: Evaluated on four standard OCSR datasets: <strong>USPTO</strong> (5,719 images), <strong>UOB</strong> (5,740 images), <strong>CLEF2012</strong> (992 images), and <strong>JPO</strong> (450 images).</li>
<li><strong>New External Dataset</strong>: Collected and annotated a &ldquo;Real-World&rdquo; dataset of <strong>3,040 images</strong> from 239 scientific papers to test generalization beyond synthetic benchmarks.</li>
<li><strong>Baselines</strong>: Compared against open-source tools: <strong>MolVec</strong> (v0.9.8), <strong>OSRA</strong> (v2.1.0), and <strong>Imago</strong> (v2.0).</li>
<li><strong>Qualitative Tests</strong>: Tested on difficult cases like hand-drawn molecules and large-sized scans (e.g., Palytoxin).</li>
</ul>
<h2 id="results-speed-and-generalization-metrics">Results: Speed and Generalization Metrics</h2>
<ul>
<li><strong>Benchmark Performance</strong>: MolMiner outperformed open-source baselines on standard validation splits.
<ul>
<li><em>USPTO</em>: 93% MCS accuracy (vs. 89% for MolVec, per Table 2). The commercial CLiDE Pro tool reports 93.8% on USPTO, slightly higher than MolMiner&rsquo;s 93.3%.</li>
<li><em>Real-World Set</em>: 87.8% MCS accuracy (vs. 50.1% for MolVec, 8.9% for OSRA, and 10.3% for Imago).</li>
</ul>
</li>
<li><strong>Inference Velocity</strong>: The architecture allows for faster processing compared to CPU rule-based systems. On JPO (450 images), MolMiner finishes in under 1 minute versus 8-23 minutes for rule-based tools (Table 3).</li>
<li><strong>Robustness</strong>: Demonstrated ability to handle hand-drawn sketches and noisy scans, though limitations remain with crossing bonds, colorful backgrounds, crowded layout segmentation, and Markush structures.</li>
<li><strong>Software Release</strong>: Released as a free desktop application for Mac and Windows with a Ketcher-based editing plugin.</li>
</ul>
<hr>
<h2 id="reproducibility-details">Reproducibility Details</h2>
<h3 id="data">Data</h3>
<p>The system relies heavily on synthetic data for training, while evaluation uses both standard and novel real-world datasets.</p>
<table>
  <thead>
      <tr>
          <th style="text-align: left">Purpose</th>
          <th style="text-align: left">Dataset</th>
          <th style="text-align: left">Size</th>
          <th style="text-align: left">Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td style="text-align: left"><strong>Training</strong></td>
          <td style="text-align: left"><strong>Synthetic RDKit</strong></td>
          <td style="text-align: left">Large-scale</td>
          <td style="text-align: left">Generated using RDKit v2021.09.1 and ReportLab v3.5.0. Includes augmentations (rotation, thinning, noise).</td>
      </tr>
      <tr>
          <td style="text-align: left"><strong>Evaluation</strong></td>
          <td style="text-align: left"><strong>USPTO</strong></td>
          <td style="text-align: left">5,719</td>
          <td style="text-align: left">Standard benchmark. Avg MW: 380.0.</td>
      </tr>
      <tr>
          <td style="text-align: left"><strong>Evaluation</strong></td>
          <td style="text-align: left"><strong>UOB</strong></td>
          <td style="text-align: left">5,740</td>
          <td style="text-align: left">Standard benchmark. Avg MW: 213.5.</td>
      </tr>
      <tr>
          <td style="text-align: left"><strong>Evaluation</strong></td>
          <td style="text-align: left"><strong>CLEF2012</strong></td>
          <td style="text-align: left">992</td>
          <td style="text-align: left">Standard benchmark. Avg MW: 401.2.</td>
      </tr>
      <tr>
          <td style="text-align: left"><strong>Evaluation</strong></td>
          <td style="text-align: left"><strong>JPO</strong></td>
          <td style="text-align: left">450</td>
          <td style="text-align: left">Standard benchmark. Avg MW: 360.3.</td>
      </tr>
      <tr>
          <td style="text-align: left"><strong>Evaluation</strong></td>
          <td style="text-align: left"><strong>Real-World</strong></td>
          <td style="text-align: left">3,040</td>
          <td style="text-align: left"><strong>New Contribution</strong>. Collected from 239 scientific papers. <a href="https://zenodo.org/records/6973361">Download Link</a>.</td>
      </tr>
  </tbody>
</table>
<h3 id="algorithms">Algorithms</h3>
<ul>
<li><strong>Data Generation</strong>:
<ul>
<li>Uses <strong>RDKit</strong> <code>MolDraw2DSVG</code> and <code>CondenseMolAbbreviations</code> to generate images and ground truth.</li>
<li><strong>Augmentation</strong>: Rotation, line thinning/thickness variation, noise injection.</li>
</ul>
</li>
<li><strong>Graph Construction</strong>:
<ul>
<li>A distance-based algorithm connects recognized &ldquo;Atom&rdquo; and &ldquo;Bond&rdquo; objects into a molecular graph.</li>
<li><strong>Supergroup Parser</strong>: Matches detected text against a dictionary collected from RDKit, ChemAxon, and OSRA to resolve abbreviations (e.g., &ldquo;Ph&rdquo;, &ldquo;Me&rdquo;).</li>
</ul>
</li>
<li><strong>Image Preprocessing</strong>:
<ul>
<li><strong>Resizing</strong>: Images with max dim &gt; 2560 are resized to 2560. Small images (&lt; 640) resized to 640.</li>
<li><strong>Padding</strong>: Images padded to nearest upper bound (640, 1280, 1920, 2560) with white background (255, 255, 255).</li>
<li><strong>Dilation</strong>: For thick-line images, <code>cv2.dilate</code> (3x3 or 2x2 kernel) is applied to estimate median line width.</li>
</ul>
</li>
</ul>
<h3 id="models">Models</h3>
<p>The system is a cascade of three distinct deep learning models:</p>
<ol>
<li><strong>MolMiner-ImgDet</strong> (Page Segmentation):
<ul>
<li><strong>Architecture</strong>: <strong>MobileNetV2</strong>.</li>
<li><strong>Task</strong>: Semantic segmentation to identify and crop chemical figures from full PDF pages.</li>
<li><strong>Classes</strong>: Background vs. Compound.</li>
<li><strong>Performance</strong>: Recall 95.5%.</li>
</ul>
</li>
<li><strong>MolMiner-ImgRec</strong> (Structure Recognition):
<ul>
<li><strong>Architecture</strong>: <strong>YOLOv5</strong> (One-stage object detector). Selected over MaskRCNN/EfficientDet for speed/accuracy trade-off.</li>
<li><strong>Task</strong>: Detects atoms and bonds as bounding boxes.</li>
<li><strong>Labels</strong>:
<ul>
<li><em>Atoms</em>: Si, N, Br, S, I, Cl, H, P, O, C, B, F, Text.</li>
<li><em>Bonds</em>: Single, Double, Triple, Wedge, Dash, Wavy.</li>
</ul>
</li>
<li><strong>Performance</strong>: <a href="mailto:mAP@0.5">mAP@0.5</a> = 97.5%.</li>
</ul>
</li>
<li><strong>MolMiner-TextOCR</strong> (Character Recognition):
<ul>
<li><strong>Architecture</strong>: <strong>EasyOCR</strong> (fine-tuned).</li>
<li><strong>Task</strong>: Recognize specific characters in &ldquo;Text&rdquo; regions identified by YOLO (e.g., supergroups, complex labels).</li>
<li><strong>Performance</strong>: ~96.4% accuracy.</li>
</ul>
</li>
</ol>
<h2 id="performance-evaluation--accuracy-metrics">Performance Evaluation &amp; Accuracy Metrics</h2>
<p>The paper argues that computing the Maximum Common Substructure (MCS) accuracy is superior to string comparisons of canonical identifiers like InChI or SMILES. The InChI string is heavily sensitive to slight canonicalization or tautomerization discrepancies (like differing aromaticity models). Therefore, for comparing structural isomorphism:</p>
<p>$$ \text{MCS_Accuracy} = \frac{|\text{Edges}_{\text{MCS}}| + |\text{Nodes}_{\text{MCS}}|}{|\text{Edges}_{\text{Ground_Truth}}| + |\text{Nodes}_{\text{Ground_Truth}}|} $$</p>
<p>Using this metric to evaluate bond- and atom-level recall directly measures OCR extraction fidelity.</p>
<table>
  <thead>
      <tr>
          <th style="text-align: left">Metric</th>
          <th style="text-align: left">MolMiner (Real-World)</th>
          <th style="text-align: left">MolVec</th>
          <th style="text-align: left">OSRA</th>
          <th style="text-align: left">Imago</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td style="text-align: left"><strong>MCS Accuracy</strong></td>
          <td style="text-align: left"><strong>87.8%</strong></td>
          <td style="text-align: left">50.1%</td>
          <td style="text-align: left">8.9%</td>
          <td style="text-align: left">10.3%</td>
      </tr>
      <tr>
          <td style="text-align: left"><strong>InChI Accuracy</strong></td>
          <td style="text-align: left"><strong>88.9%</strong></td>
          <td style="text-align: left">62.6%</td>
          <td style="text-align: left">64.5%</td>
          <td style="text-align: left">10.8%</td>
      </tr>
  </tbody>
</table>
<h3 id="hardware">Hardware</h3>
<ul>
<li><strong>Inference Hardware</strong>: Tested on Intel Xeon Gold 6230R CPU @ 2.10 GHz.</li>
<li><strong>Acceleration</strong>: Supports batch inference on GPU, which provides the reported speedups over rule-based CPU tools.</li>
<li><strong>Runtime</strong>: Under 1 minute on JPO (450 images), 7 minutes on USPTO (5,719 images), compared to 29-148 minutes for baseline tools on USPTO (Table 3).</li>
</ul>
<h3 id="artifacts">Artifacts</h3>
<table>
  <thead>
      <tr>
          <th style="text-align: left">Artifact</th>
          <th style="text-align: left">Type</th>
          <th style="text-align: left">License</th>
          <th style="text-align: left">Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td style="text-align: left"><a href="https://github.com/iipharma/pharmamind-molminer">pharmamind-molminer</a></td>
          <td style="text-align: left">Code</td>
          <td style="text-align: left">Unknown</td>
          <td style="text-align: left">GitHub repo with user guides and release downloads</td>
      </tr>
      <tr>
          <td style="text-align: left"><a href="https://zenodo.org/records/6973361">Real-World Dataset</a></td>
          <td style="text-align: left">Dataset</td>
          <td style="text-align: left">Unknown</td>
          <td style="text-align: left">3,040 molecular images from 239 papers</td>
      </tr>
  </tbody>
</table>
<hr>
<h2 id="paper-information">Paper Information</h2>
<p><strong>Citation</strong>: Xu, Y., Xiao, J., Chou, C.-H., Zhang, J., Zhu, J., Hu, Q., Li, H., Han, N., Liu, B., Zhang, S., Han, J., Zhang, Z., Zhang, S., Zhang, W., Lai, L., &amp; Pei, J. (2022). MolMiner: You only look once for chemical structure recognition. <em>Journal of Chemical Information and Modeling</em>, 62(22), 5321&ndash;5328. <a href="https://doi.org/10.1021/acs.jcim.2c00733">https://doi.org/10.1021/acs.jcim.2c00733</a></p>
<p><strong>Publication</strong>: Journal of Chemical Information and Modeling (JCIM) 2022</p>
<p><strong>Additional Resources</strong>:</p>
<ul>
<li><a href="https://github.com/iipharma/pharmamind-molminer">Github Repository</a></li>
<li><a href="https://zenodo.org/records/6973361">Zenodo Dataset</a></li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bibtex" data-lang="bibtex"><span style="display:flex;"><span><span style="color:#a6e22e">@article</span>{xuMolMinerYouOnly2022,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">title</span> = <span style="color:#e6db74">{MolMiner: You only look once for chemical structure recognition}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">shorttitle</span> = <span style="color:#e6db74">{MolMiner}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">author</span> = <span style="color:#e6db74">{Xu, Youjun and Xiao, Jinchuan and Chou, Chia-Han and Zhang, Jianhang and Zhu, Jintao and Hu, Qiwan and Li, Hemin and Han, Ningsheng and Liu, Bingyu and Zhang, Shuaipeng and Han, Jinyu and Zhang, Zhen and Zhang, Shuhao and Zhang, Weilin and Lai, Luhua and Pei, Jianfeng}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">year</span> = <span style="color:#ae81ff">2022</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">month</span> = nov,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">journal</span> = <span style="color:#e6db74">{Journal of Chemical Information and Modeling}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">volume</span> = <span style="color:#e6db74">{62}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">number</span> = <span style="color:#e6db74">{22}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">pages</span> = <span style="color:#e6db74">{5321--5328}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">publisher</span> = <span style="color:#e6db74">{American Chemical Society}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">issn</span> = <span style="color:#e6db74">{1549-9596}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">doi</span> = <span style="color:#e6db74">{10.1021/acs.jcim.2c00733}</span>,
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div>]]></content:encoded></item><item><title>Image-to-Graph Transformers for Chemical Structures</title><link>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/image-to-graph-transformers/</link><pubDate>Thu, 18 Dec 2025 00:00:00 +0000</pubDate><guid>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/image-to-graph-transformers/</guid><description>A deep learning model that converts molecular images directly into graph structures, enabling recognition of abbreviated non-atomic symbols.</description><content:encoded><![CDATA[<h2 id="contribution-and-taxonomic-classification">Contribution and Taxonomic Classification</h2>
<p>This is a <strong>Method</strong> paper. It proposes a novel deep learning architecture designed to extract molecular structures from images by directly predicting the graph topology. The paper validates this approach through ablation studies (comparing ResNet-only baselines to the Transformer-augmented model) and extensive benchmarking against existing tools.</p>
<h2 id="the-challenge-with-smiles-and-non-atomic-symbols">The Challenge with SMILES and Non-Atomic Symbols</h2>
<ul>
<li><strong>Handling Abbreviations:</strong> Chemical structures in scientific literature often use non-atomic symbols (superatoms like &ldquo;R&rdquo; or &ldquo;Ph&rdquo;) to reduce complexity. Standard tools that generate SMILES strings fail here because SMILES syntax does not support arbitrary non-atomic symbols.</li>
<li><strong>Robustness to Style:</strong> Existing rule-based tools are brittle to the diverse drawing styles found in literature.</li>
<li><strong>Data Utilization:</strong> Pixel-wise graph recognition tools (like ChemGrapher) require expensive pixel-level labeling. An end-to-end approach can utilize massive amounts of image-molecule pairs (like USPTO data) without needing exact coordinate labels.</li>
</ul>
<h2 id="the-image-to-graph-i2g-architecture">The Image-to-Graph (I2G) Architecture</h2>
<p>The core novelty is the <strong>Image-to-Graph (I2G)</strong> architecture that bypasses string representations entirely:</p>
<ul>
<li><strong>Hybrid Encoder:</strong> Combines a ResNet backbone (for locality) with a Transformer encoder (for global context), allowing the model to capture relationships between atoms that are far apart in the image.</li>
<li><strong>Graph Decoder (GRAT):</strong> A modified Transformer decoder that generates the graph auto-regressively. It uses feature-wise transformations to modulate attention weights based on edge information (bond types).</li>
<li><strong>Coordinate-Aware Training:</strong> The model is forced to predict the exact 2D coordinates of atoms in the source image. Combined with auxiliary losses, this boosts SMI accuracy from 0.009 to 0.567 on the UoB ablation (Table 1 in the paper).</li>
</ul>
<h2 id="experimental-setup-and-baselines">Experimental Setup and Baselines</h2>
<ul>
<li><strong>Baselines:</strong> The model was compared against OSRA (rule-based), MolVec (rule-based), and ChemGrapher (deep learning pixel-wise).</li>
<li><strong>Benchmarks:</strong> Evaluated on four standard datasets: UoB, USPTO, CLEF, and JPO. Images were converted to PDF and back to simulate degradation.</li>
<li><strong>Large Molecule Test:</strong> A custom dataset (<strong>OLED</strong>) was created from 12 journal papers (434 images) to test performance on larger, more complex structures (average 52.8 atoms).</li>
<li><strong>Ablations:</strong> The authors tested the impact of the Transformer encoder, auxiliary losses, and coordinate prediction.</li>
</ul>
<h2 id="empirical-results-and-robustness">Empirical Results and Robustness</h2>
<ul>
<li><strong>Benchmark Performance:</strong> The proposed model outperformed existing models with a 17.1% relative improvement on benchmark datasets.</li>
<li><strong>Robustness:</strong> On large molecules (OLED dataset), it achieved a 12.8% relative improvement over MolVec (and 20.0% over OSRA).</li>
<li><strong>Data Scaling:</strong> Adding real-world USPTO data to the synthetic training set improved performance by 20.5%, demonstrating the model&rsquo;s ability to learn from noisy, unlabeled coordinates.</li>
<li><strong>Handling Superatoms:</strong> The model successfully recognized pseudo-atoms (e.g., $R_1$, $R_2$, $R_3$) as distinct nodes. OSRA, which outputs SMILES, collapsed them into generic &ldquo;Any&rdquo; atoms since SMILES does not support non-atomic symbols. MolVec could not recognize them properly at all.</li>
</ul>
<h2 id="limitations-and-error-analysis">Limitations and Error Analysis</h2>
<p>The paper identifies two main failure modes on the USPTO, CLEF, and JPO benchmarks:</p>
<ol>
<li><strong>Unrecognized superatoms:</strong> The model struggles with complex multi-character superatoms not seen during training (e.g., NHNHCOCH$_3$ or H$_3$CO$_2$S). The authors propose character-level atom decoding as a future solution.</li>
<li><strong>Caption interference:</strong> The model sometimes misidentifies image captions as atoms, particularly on the JPO dataset. Data augmentation with arbitrary caption text or a dedicated image segmentation step could mitigate this.</li>
</ol>
<hr>
<h2 id="reproducibility-details">Reproducibility Details</h2>
<h3 id="data">Data</h3>
<p>The authors used a combination of synthetic and real-world data for training.</p>
<table>
  <thead>
      <tr>
          <th>Purpose</th>
          <th>Dataset</th>
          <th>Size</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Training</td>
          <td><strong>PubChem</strong></td>
          <td>4.6M</td>
          <td>Synthetic images generated using RDKit. Random superatoms (e.g., $CF_3$, $NO_2$) were substituted to simulate abbreviations.</td>
      </tr>
      <tr>
          <td>Training</td>
          <td><strong>USPTO</strong></td>
          <td>2.5M</td>
          <td>Real image-molecule pairs from patents. Used for robustness; lacks coordinate labels.</td>
      </tr>
      <tr>
          <td>Evaluation</td>
          <td><strong>Benchmarks</strong></td>
          <td>~5.7k</td>
          <td>UoB, USPTO, CLEF, JPO. Average ~15.8 atoms per molecule.</td>
      </tr>
      <tr>
          <td>Evaluation</td>
          <td><strong>OLED</strong></td>
          <td>434</td>
          <td>Manually segmented from 12 journal papers. Large molecules (avg 52.8 atoms).</td>
      </tr>
  </tbody>
</table>
<p><strong>Preprocessing:</strong></p>
<ul>
<li>Input resolution is fixed at $800 \times 800$ pixels.</li>
<li>Images are virtually split into a $25 \times 25$ grid (625 patches total), where each patch is $32 \times 32$ pixels.</li>
</ul>
<h3 id="algorithms">Algorithms</h3>
<p><strong>Encoder Logic:</strong></p>
<ul>
<li><strong>Grid Serialization:</strong> The $25 \times 25$ grid is flattened into a 1D sequence. 2D position information is concatenated to ResNet features before the Transformer.</li>
<li><strong>Auxiliary Losses:</strong> To aid convergence, classifiers on the encoder predict three things <em>per patch</em>: (1) number of atoms, (2) characters in atom labels, and (3) edge-sharing neighbors. These losses decrease to zero during training.</li>
</ul>
<p><strong>Decoder Logic:</strong></p>
<ul>
<li><strong>Auto-regressive Generation:</strong> At step $t$, the decoder generates a new node and connects it to existing nodes.</li>
<li><strong>Attention Modulation:</strong> Attention weights are transformed using bond information:
$$
\begin{aligned}
\text{Att}(Q, K, V) = \text{softmax} \left( \frac{\Gamma \odot (QK^T) + B}{\sqrt{d_k}} \right) V
\end{aligned}
$$
where $(\gamma_{ij}, \beta_{ij}) = f(e_{ij})$, with $e_{ij}$ being the edge type (in one-hot representation) between nodes $i$ and $j$, and $f$ is a multi-layer perceptron. $\Gamma$ and $B$ are matrices whose elements at position $(i, j)$ are $\gamma_{ij}$ and $\beta_{ij}$, respectively.</li>
<li><strong>Coordinate Prediction:</strong> The decoder outputs coordinates for each atom, which acts as a mechanism to track attention history.</li>
</ul>
<h3 id="models">Models</h3>
<ul>
<li><strong>Image Encoder:</strong> ResNet-34 backbone followed by a Transformer encoder.</li>
<li><strong>Graph Decoder:</strong> A &ldquo;Graph-Aware Transformer&rdquo; (GRAT) that outputs nodes (atom labels, coordinates) and edges (bond types).</li>
</ul>
<h3 id="evaluation">Evaluation</h3>
<p>Metrics focus on structural identity, as standard string matching (SMILES) is insufficient for graphs with superatoms.</p>
<table>
  <thead>
      <tr>
          <th>Metric</th>
          <th>Description</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><strong>SMI</strong></td>
          <td>Canonical SMILES Match</td>
          <td>Correct if predicted SMILES is identical to ground truth.</td>
      </tr>
      <tr>
          <td><strong>TS 1</strong></td>
          <td>Tanimoto Similarity = 1.0</td>
          <td>Ratio of predictions with perfect fingerprint overlap.</td>
      </tr>
      <tr>
          <td><strong>Sim.</strong></td>
          <td>Average Tanimoto Similarity</td>
          <td>Measures average structural overlap across all predictions.</td>
      </tr>
  </tbody>
</table>
<h2 id="reproducibility">Reproducibility</h2>
<p>The paper does not release source code, pre-trained models, or the custom OLED evaluation dataset. The training data sources (PubChem, USPTO) are publicly available, but the specific image generation pipeline (modified RDKit with coordinate extraction and superatom substitution) is not released. Key architectural details (ResNet-34 backbone, Transformer encoder/decoder configuration) and training techniques are described, but exact hyperparameters for full reproduction are limited.</p>
<table>
  <thead>
      <tr>
          <th>Artifact</th>
          <th>Type</th>
          <th>License</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><a href="https://pubchem.ncbi.nlm.nih.gov/">PubChem</a></td>
          <td>Dataset</td>
          <td>Public Domain</td>
          <td>Source of 4.6M molecules for synthetic image generation</td>
      </tr>
      <tr>
          <td><a href="https://www.uspto.gov/">USPTO</a></td>
          <td>Dataset</td>
          <td>Public Domain</td>
          <td>2.5M real image-molecule pairs from patents</td>
      </tr>
      <tr>
          <td><a href="https://www.rdkit.org/">RDKit</a></td>
          <td>Code</td>
          <td>BSD-3-Clause</td>
          <td>Used (with modifications) for synthetic image generation</td>
      </tr>
  </tbody>
</table>
<h2 id="paper-information">Paper Information</h2>
<p><strong>Citation</strong>: Yoo, S., Kwon, O., &amp; Lee, H. (2022). Image-to-Graph Transformers for Chemical Structure Recognition. <em>ICASSP 2022 - 2022 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP)</em>, 3393-3397. <a href="https://doi.org/10.1109/ICASSP43922.2022.9746088">https://doi.org/10.1109/ICASSP43922.2022.9746088</a></p>
<p><strong>Publication</strong>: ICASSP 2022</p>
]]></content:encoded></item><item><title>ABC-Net: Keypoint-Based Molecular Image Recognition</title><link>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/abc-net/</link><pubDate>Thu, 18 Dec 2025 00:00:00 +0000</pubDate><guid>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/abc-net/</guid><description>Deep learning OCSR model using keypoint estimation to detect atom and bond centers for graph-based molecular structure recognition.</description><content:encoded><![CDATA[<h2 id="contribution-and-paper-type">Contribution and Paper Type</h2>
<p><strong>Method</strong>. The paper proposes a novel architectural framework (ABC-Net) for Optical Chemical Structure Recognition (OCSR). It reformulates the problem from image captioning (sequence generation) to keypoint estimation (pixel-wise detection), backed by ablation studies on noise and comparative benchmarks against state-of-the-art tools.</p>
<h2 id="motivation-for-keypoint-based-ocsr">Motivation for Keypoint-Based OCSR</h2>
<ul>
<li><strong>Inefficiency of Rule-Based Methods</strong>: Traditional tools (OSRA, MolVec) rely on hand-coded rules that are brittle, require domain expertise, and fail to handle the wide variance in molecular drawing styles.</li>
<li><strong>Data Inefficiency of Captioning Models</strong>: Recent Deep Learning approaches (like DECIMER, Img2mol) treat OCSR as image captioning (Image-to-SMILES). This is data-inefficient because canonical SMILES require learning traversal orders, necessitating millions of training examples.</li>
<li><strong>Goal</strong>: To create a scalable, data-efficient model that predicts graph structures directly by detecting atomic/bond primitives.</li>
</ul>
<h2 id="abc-nets-divide-and-conquer-architecture">ABC-Net&rsquo;s Divide-and-Conquer Architecture</h2>
<ul>
<li><strong>Divide-and-Conquer Strategy</strong>: ABC-Net breaks the problem down into detecting <strong>atom centers</strong> and <strong>bond centers</strong> as independent keypoints.</li>
<li><strong>Keypoint Estimation</strong>: A Fully Convolutional Network (FCN) generates heatmaps for object centers. This is inspired by computer vision techniques like CornerNet and CenterNet.</li>
<li><strong>Angle-Based Bond Detection</strong>: To handle overlapping bonds, the model classifies bond angles into 60 distinct bins ($0-360°$) at detected bond centers, allowing separation of intersecting bonds.</li>
<li><strong>Implicit Hydrogen Prediction</strong>: The model explicitly predicts the number of implicit hydrogens for heterocyclic atoms to resolve ambiguity in dearomatization.</li>
</ul>
<h2 id="experimental-setup-and-synthetic-data">Experimental Setup and Synthetic Data</h2>
<ul>
<li><strong>Dataset Construction</strong>: Synthetic dataset of 100,000 molecules from ChEMBL, rendered using two different engines (RDKit and Indigo) to ensure style diversity.</li>
<li><strong>Baselines</strong>: Compared against two rule-based methods (MolVec, OSRA) and one deep learning method (Img2mol).</li>
<li><strong>Robustness Testing</strong>: Evaluated on the external UOB dataset (real-world images) and synthetic images with varying levels of salt-and-pepper noise (up to $p=0.6$).</li>
<li><strong>Data Efficiency</strong>: Analyzed performance scaling with training set size (10k to 160k images).</li>
</ul>
<h2 id="results-generalization-and-noise-robustness">Results, Generalization, and Noise Robustness</h2>
<ul>
<li><strong>Superior Accuracy</strong>: ABC-Net achieved <strong>94-98% accuracy</strong> across all test sets (Table 1), outperforming MolVec (12-45% on synthetic data, ~83% on UOB), OSRA (26-62% on synthetic, ~82% on UOB), and Img2mol (78-93% on non-stereo subsets).</li>
<li><strong>Generalization</strong>: On the external UOB benchmark, ABC-Net achieved <strong>&gt;95% accuracy</strong>, whereas the deep learning baseline (Img2mol) dropped to 78.2%, indicating better generalization.</li>
<li><strong>Data Efficiency</strong>: The model reached ~95% performance with only 80,000 training images, requiring roughly an order of magnitude less data than captioning-based models like Img2mol (which use millions of training examples).</li>
<li><strong>Noise Robustness</strong>: Performance remained stable (&lt;2% drop) with noise levels up to $p=0.1$. Even at extreme noise ($p=0.6$), Tanimoto similarity remained high, suggesting the model recovers most substructures even when exact matches fail.</li>
</ul>
<h2 id="limitations">Limitations</h2>
<ul>
<li><strong>Drawing style coverage</strong>: The synthetic training data covers only styles available through RDKit and Indigo renderers. Many real-world styles (e.g., hand-drawn structures, atomic group abbreviations) are not represented.</li>
<li><strong>No stereo baseline from Img2mol</strong>: The Img2mol comparison only covers non-stereo subsets because stereo results were not available from the original Img2mol paper.</li>
<li><strong>Scalability to large molecules</strong>: Molecules with more than 50 non-hydrogen atoms are excluded from the dataset, and performance on such large structures is untested.</li>
</ul>
<hr>
<h2 id="reproducibility-details">Reproducibility Details</h2>
<h3 id="artifacts">Artifacts</h3>
<table>
  <thead>
      <tr>
          <th style="text-align: left">Artifact</th>
          <th style="text-align: left">Type</th>
          <th style="text-align: left">License</th>
          <th style="text-align: left">Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td style="text-align: left"><a href="https://github.com/zhang-xuan1314/ABC-Net">ABC-Net Repository</a></td>
          <td style="text-align: left">Code</td>
          <td style="text-align: left">Apache-2.0</td>
          <td style="text-align: left">Official implementation. Missing requirements.txt and pre-trained weights.</td>
      </tr>
  </tbody>
</table>
<p><strong>Reproducibility Status: Partially Reproducible</strong>. The code is provided, but key components like the pre-trained weights, exact training environment dependencies, and the generated synthetic datasets are missing from the open-source release, making exact reproduction difficult.</p>
<h3 id="data">Data</h3>
<p>The authors constructed a synthetic dataset because labeled pixel-wise OCSR data is unavailable.</p>
<ul>
<li><strong>Source</strong>: ChEMBL database</li>
<li><strong>Filtering</strong>: Excluded molecules with &gt;50 non-H atoms or rare atom types/charges (&lt;1000 occurrences).</li>
<li><strong>Sampling</strong>: 100,000 unique SMILES selected such that every atom type/charge appears in at least 1,000 compounds.</li>
<li><strong>Generation</strong>: Images generated via <strong>RDKit</strong> and <strong>Indigo</strong> libraries.
<ul>
<li><em>Augmentation</em>: Varied bond thickness, label mode, orientation, and aromaticity markers.</li>
<li><em>Resolution</em>: $512 \times 512$ pixels.</li>
<li><em>Noise</em>: Salt-and-pepper noise added during training ($P$ = prob of background flip, $Q = 50P$).</li>
</ul>
</li>
</ul>
<table>
  <thead>
      <tr>
          <th>Purpose</th>
          <th>Dataset</th>
          <th>Size</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Training</td>
          <td>ChEMBL (RDKit/Indigo)</td>
          <td>80k</td>
          <td>8:1:1 split (Train/Val/Test)</td>
      </tr>
      <tr>
          <td>Evaluation</td>
          <td>UOB Dataset</td>
          <td>~5.7k images</td>
          <td>External benchmark from Univ. of Birmingham</td>
      </tr>
  </tbody>
</table>
<h3 id="algorithms">Algorithms</h3>
<p><strong>1. Keypoint Detection (Heatmaps)</strong></p>
<ul>
<li>
<p><strong>Down-sampling</strong>: Input $512 \times 512$ → Output $128 \times 128$ (stride 4).</p>
</li>
<li>
<p><strong>Label Softening</strong>: To handle discretization error, ground truth peaks are set to 1, first-order neighbors to 0.95, others to 0.</p>
</li>
<li>
<p><strong>Loss Function</strong>: Penalty-reduced pixel-wise binary focal loss (variants of CornerNet loss). The loss formulation is given as:</p>
<p>$$ L_{det} = - \frac{1}{N} \sum_{x,y} \begin{cases} (1 - \hat{A}_{x,y})^{\alpha} \log(\hat{A}_{x,y}) &amp; \text{if } A_{x,y} = 1 \\ (1 - A_{x,y}) (\hat{A}_{x,y})^{\alpha} \log(1 - \hat{A}_{x,y}) &amp; \text{otherwise} \end{cases} $$</p>
<ul>
<li>$\alpha=2$ (focal parameter). The $(1 - A_{x,y})$ term reduces the penalty for first-order neighbors of ground truth locations.</li>
<li>Property classification losses use a separate focal parameter $\beta=2$ with weight balancing: classes with &lt;10% frequency are weighted 10x.</li>
</ul>
</li>
</ul>
<p><strong>2. Bond Direction Classification</strong></p>
<ul>
<li><strong>Angle Binning</strong>: $360°$ divided into 60 intervals.</li>
<li><strong>Inference</strong>: A bond is detected if the angle probability is a local maximum and exceeds a threshold.</li>
<li><strong>Non-Maximum Suppression (NMS)</strong>: Required for opposite angles (e.g., $30°$ and $210°$) representing the same non-stereo bond.</li>
</ul>
<p><strong>3. Multi-Task Weighting</strong></p>
<ul>
<li>Uses Kendall&rsquo;s uncertainty weighting to balance 8 different loss terms (atom det, bond det, atom type, charge, H-count, bond angle, bond type, bond length).</li>
</ul>
<h3 id="models">Models</h3>
<p><strong>Architecture</strong>: ABC-Net (Custom U-Net / FCN)</p>
<ul>
<li><strong>Input</strong>: $512 \times 512 \times 1$ (Grayscale).</li>
<li><strong>Contracting Path</strong>: 5 steps. Each step has conv-blocks + $2 \times 2$ MaxPool.</li>
<li><strong>Expansive Path</strong>: 3 steps. Transpose-Conv upsampling + Concatenation (Skip Connections).</li>
<li><strong>Heads</strong>: Separate $1 \times 1$ convs for each task map (Atom Heatmap, Bond Heatmap, Property Maps).</li>
<li><strong>Output Dimensions</strong>:
<ul>
<li>Heatmaps: $(1, 128, 128)$</li>
<li>Bond Angles: $(60, 128, 128)$</li>
</ul>
</li>
<li><strong>Pre-trained Weights</strong>: Not included in the public <a href="https://github.com/zhang-xuan1314/ABC-Net">GitHub repository</a>. The paper&rsquo;s availability statement mentions code and training datasets but not weights.</li>
</ul>
<h3 id="evaluation">Evaluation</h3>
<p><strong>Metrics</strong>:</p>
<ul>
<li><strong>Detection</strong>: Precision &amp; Recall (Object detection level).</li>
<li><strong>Regression</strong>: Mean Absolute Error (MAE) for bond lengths.</li>
<li><strong>Structure Recovery</strong>:
<ul>
<li><em>Accuracy</em>: Exact SMILES match rate.</li>
<li><em>Tanimoto</em>: ECFP similarity (fingerprint overlap).</li>
</ul>
</li>
</ul>
<table>
  <thead>
      <tr>
          <th>Metric</th>
          <th>ABC-Net</th>
          <th>Img2mol (Baseline)</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><strong>Accuracy (UOB)</strong></td>
          <td><strong>96.1%</strong></td>
          <td>78.2%</td>
          <td>Non-stereo subset</td>
      </tr>
      <tr>
          <td><strong>Accuracy (Indigo)</strong></td>
          <td><strong>96.4%</strong></td>
          <td>89.5%</td>
          <td>Non-stereo subset</td>
      </tr>
      <tr>
          <td><strong>Tanimoto (UOB)</strong></td>
          <td><strong>0.989</strong></td>
          <td>0.953</td>
          <td>Higher substructure recovery</td>
      </tr>
  </tbody>
</table>
<h3 id="hardware">Hardware</h3>
<ul>
<li><strong>Training Configuration</strong>: 15 epochs, Batch size 64.</li>
<li><strong>Optimization</strong>: Adam Optimizer. LR $2.5 \times 10^{-4}$ (first 5 epochs) → $2.5 \times 10^{-5}$ (last 10).</li>
<li><strong>Repetition</strong>: Every experiment was repeated 3 times with random dataset splitting; mean values are reported.</li>
<li><strong>Compute</strong>: High-Performance Computing Center of Central South University. Specific GPU model not listed.</li>
</ul>
<hr>
<h2 id="paper-information">Paper Information</h2>
<p><strong>Citation</strong>: Zhang, X.-C., Yi, J.-C., Yang, G.-P., Wu, C.-K., Hou, T.-J., &amp; Cao, D.-S. (2022). ABC-Net: A divide-and-conquer based deep learning architecture for SMILES recognition from molecular images. <em>Briefings in Bioinformatics</em>, 23(2), bbac033. <a href="https://doi.org/10.1093/bib/bbac033">https://doi.org/10.1093/bib/bbac033</a></p>
<p><strong>Publication</strong>: Briefings in Bioinformatics 2022</p>
<p><strong>Additional Resources</strong>:</p>
<ul>
<li><a href="https://github.com/zhang-xuan1314/ABC-Net">GitHub Repository</a></li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bibtex" data-lang="bibtex"><span style="display:flex;"><span><span style="color:#a6e22e">@article</span>{zhangABCNetDivideandconquerBased2022,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">title</span> = <span style="color:#e6db74">{ABC-Net: A Divide-and-Conquer Based Deep Learning Architecture for {SMILES} Recognition from Molecular Images}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">author</span> = <span style="color:#e6db74">{Zhang, Xiao-Chen and Yi, Jia-Cai and Yang, Guo-Ping and Wu, Cheng-Kun and Hou, Ting-Jun and Cao, Dong-Sheng}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">journal</span> = <span style="color:#e6db74">{Briefings in Bioinformatics}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">volume</span> = <span style="color:#e6db74">{23}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">number</span> = <span style="color:#e6db74">{2}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">pages</span> = <span style="color:#e6db74">{bbac033}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">year</span> = <span style="color:#e6db74">{2022}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">publisher</span> = <span style="color:#e6db74">{Oxford University Press}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">doi</span> = <span style="color:#e6db74">{10.1093/bib/bbac033}</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div>]]></content:encoded></item><item><title>ChemGrapher: Deep Learning for Chemical Graph OCSR</title><link>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/chemgrapher-2020/</link><pubDate>Wed, 17 Dec 2025 00:00:00 +0000</pubDate><guid>https://hunterheidenreich.com/notes/chemistry/optical-structure-recognition/image-to-graph/chemgrapher-2020/</guid><description>Deep learning OCSR method using semantic segmentation and classification CNNs to reconstruct chemical graphs with improved stereochemistry.</description><content:encoded><![CDATA[<h2 id="classifying-the-methodology">Classifying the Methodology</h2>
<p>This is a <strong>Method</strong> paper. It proposes a novel deep learning architecture and a specific graph-reconstruction algorithm to solve the problem of Optical Chemical Structure Recognition (OCSR). It validates this method by comparing it against the existing standard tool (OSRA), demonstrating superior performance on specific technical challenges like stereochemistry.</p>
<h2 id="the-ocr-stereochemistry-challenge">The OCR Stereochemistry Challenge</h2>
<p>Chemical knowledge is frequently locked in static images within scientific publications. Extracting this structure into machine-readable formats (graphs, SMILES) is essential for drug discovery and database querying. Existing tools, such as OSRA, rely on optical character recognition (OCR) and expert systems or hand-coded rules. These tools struggle with bond multiplicity and stereochemical information, often missing atoms or misinterpreting 3D cues (wedges and dashes). A machine learning approach allows for improvement via data scaling.</p>
<h2 id="decoupled-semantic-segmentation-and-classification-pipeline">Decoupled Semantic Segmentation and Classification Pipeline</h2>
<p>The core novelty is the <strong>segmentation-classification pipeline</strong> which decouples object detection from type assignment:</p>
<ol>
<li><strong>Semantic Segmentation</strong>: The model first predicts pixel-wise maps for atoms, bonds, and charges using a Dense Prediction Convolutional Network built on dilated convolutions.</li>
<li><strong>Graph Building Algorithm</strong>: A specific algorithm iterates over the segmentation maps to generate candidate locations for atoms and bonds.</li>
<li><strong>Refinement via Classification</strong>: Dedicated classification networks take cutouts of the original image combined with the segmentation mask to verify and classify each candidate (e.g., distinguishing a single bond from a double bond, or a wedge from a dash).</li>
</ol>
<p>Additionally, the authors developed a novel method for <strong>synthetic data generation</strong> by modifying the source code of RDKit to output pixel-wise labels during the image drawing process. This solves the lack of labeled training data.</p>
<h2 id="evaluating-synthetics-and-benchmarks">Evaluating Synthetics and Benchmarks</h2>
<ul>
<li><strong>Synthetic Benchmarking</strong>: The authors generated test sets in 3 different stylistic variations. For each style, they tested on both stereo (complex 3D information) and non-stereo compounds.</li>
<li><strong>Baseline Comparison</strong>: They compared the error rates of ChemGrapher against <strong>OSRA</strong> (Optical Structure Recognition Application).</li>
<li><strong>Component-level Evaluation</strong>: They analyzed the F1 scores of the segmentation networks versus the classification networks independently to understand where errors propagated.</li>
<li><strong>Real-world Case Study</strong>: They manually curated 61 images cut from journal articles to test performance on real, non-synthetic data.</li>
</ul>
<h2 id="advancements-over-osra">Advancements Over OSRA</h2>
<ul>
<li><strong>Superior Accuracy</strong>: ChemGrapher consistently achieved lower error rates than OSRA across all synthetic styles, particularly for stereochemical information (wedge and dash bonds).</li>
<li><strong>Component Performance</strong>: The classification networks showed higher F1 scores than the segmentation networks across all prediction types (Figure 4 in the paper). This suggests the two-stage approach allows the classifier to correct segmentation noise.</li>
<li><strong>Real-world Viability</strong>: In the manual case study, ChemGrapher correctly predicted 46 of 61 images, compared to 42 of 61 for OSRA.</li>
<li><strong>Limitations</strong>: The model struggles with thick bond lines in real-world images. Performance is stronger on carbon-only compounds, where no letters appear in the image.</li>
</ul>
<hr>
<h2 id="reproducibility-details">Reproducibility Details</h2>
<h3 id="data">Data</h3>
<p>The authors created a custom synthetic dataset using ChEMBL and RDKit, as no pixel-wise labeled dataset existed.</p>
<table>
  <thead>
      <tr>
          <th>Purpose</th>
          <th>Dataset</th>
          <th>Size</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><strong>Source</strong></td>
          <td>ChEMBL</td>
          <td>1.9M</td>
          <td>Split into training pool (1.5M), val/train pool (300K), and test pools (35K each).</td>
      </tr>
      <tr>
          <td><strong>Segmentation Train</strong></td>
          <td>Synthetic</td>
          <td>~114K</td>
          <td>Sampled from ChEMBL pool such that every atom type appears in &gt;1000 compounds.</td>
      </tr>
      <tr>
          <td><strong>Labels</strong></td>
          <td>Pixel-wise</td>
          <td>N/A</td>
          <td>Generated by modifying <strong>RDKit</strong> source code to output label masks (atom type, bond type, charge) during drawing.</td>
      </tr>
      <tr>
          <td><strong>Candidates (Val)</strong></td>
          <td>Cutouts</td>
          <td>~27K (Atom)<br>~55K (Bond)</td>
          <td>Validation candidates generated from ~450 compounds for evaluating the classification networks.</td>
      </tr>
  </tbody>
</table>
<h3 id="algorithms">Algorithms</h3>
<p><strong>Algorithm 1: Graph Building</strong></p>
<ol>
<li><strong>Segment</strong>: Apply segmentation network $s(x)$ to get maps $S^a$ (atoms), $S^b$ (bonds), $S^c$ (charges).</li>
<li><strong>Atom Candidates</strong>: Identify candidate blobs in $S^a$.</li>
<li><strong>Classify Atoms</strong>: For each candidate, crop the input image and segmentation map. Feed to $c_A$ and $c_C$ to predict Atom Type and Charge. Add to Vertex set $V$ if valid.</li>
<li><strong>Bond Candidates</strong>: Generate all pairs of nodes in $V$ within $2 \times$ bond length distance.</li>
<li><strong>Classify Bonds</strong>: For each pair, create a candidate mask (two rectangles meeting in the middle to encode directionality). Feed to $c_B$ to predict Bond Type (single, double, wedge, etc.). Add to Edge set $E$.</li>
</ol>
<h3 id="models">Models</h3>
<p>The pipeline uses four distinct Convolutional Neural Networks (CNNs).</p>
<p><strong>1. Semantic Segmentation Network ($s$)</strong></p>
<ul>
<li><strong>Architecture</strong>: 8 convolutional layers (3x3) plus a final 1x1 linear layer (Dense Prediction Convolutional Network).</li>
<li><strong>Kernels</strong>: $3 \times 3$ for all convolutional layers; $1 \times 1$ for the final linear layer.</li>
<li><strong>Dilation</strong>: Uses dilated convolutions to expand receptive field without losing resolution. Six of the eight convolutional layers use dilation (factors: 2, 4, 8, 8, 4, 2); the first and last convolutional layers have no dilation.</li>
<li><strong>Input</strong>: Binary B/W image.</li>
<li><strong>Output</strong>: Multi-channel probability maps for Atom Types ($S^a$), Bond Types ($S^b$), and Charges ($S^c$).</li>
</ul>
<p><strong>2. Classification Networks ($c_A, c_B, c_C$)</strong></p>
<ul>
<li><strong>Purpose</strong>: Refines predictions on small image patches.</li>
<li><strong>Architecture</strong>: 5 convolutional layers, followed by a MaxPool layer and a final linear (1x1) layer.
<ul>
<li>Layer 1: <strong>Depthwise separable convolution</strong> (no dilation).</li>
<li>Layers 2-4: Dilated convolutions (factors 2, 4, 8).</li>
<li>Layer 5: Standard convolution (no dilation).</li>
<li>MaxPool: $124 \times 124$.</li>
<li>Final: 1x1 linear layer.</li>
</ul>
</li>
<li><strong>Inputs</strong>:
<ul>
<li>Crop of the binary image ($x^{cut}$).</li>
<li>Crop of the segmentation map ($S^{cut}$).</li>
<li>&ldquo;Highlight&rdquo; mask ($h_L$) indicating the specific candidate location (e.g., a dot for atoms, two rectangles for bonds).</li>
</ul>
</li>
</ul>
<h3 id="evaluation">Evaluation</h3>
<ul>
<li><strong>Metric</strong>: <strong>F1 Score</strong> for individual network performance (segmentation pixels and classification accuracy).</li>
<li><strong>Metric</strong>: <strong>Error Rate</strong> (percentage of incorrect graphs) for overall system. A graph is &ldquo;incorrect&rdquo; if there is at least one mistake in atoms or bonds.</li>
<li><strong>Baselines</strong>: Compared against <strong>OSRA</strong>.</li>
</ul>
<h3 id="hardware">Hardware</h3>
<ul>
<li><strong>GPU</strong>: Training and inference performed on a single <strong>NVIDIA Titan Xp</strong> (donated by NVIDIA).</li>
</ul>
<h3 id="reproducibility-status">Reproducibility Status</h3>
<p><strong>Closed.</strong> The authors did not release source code, pre-trained models, or the synthetic dataset. The data generation pipeline requires modifications to RDKit&rsquo;s internal drawing code, which are not publicly available. The ChEMBL source compounds are public, but the pixel-wise labeling procedure cannot be reproduced without the modified RDKit code.</p>
<hr>
<h2 id="paper-information">Paper Information</h2>
<p><strong>Citation</strong>: Oldenhof, M., Arany, Á., Moreau, Y., &amp; Simm, J. (2020). ChemGrapher: Optical Graph Recognition of Chemical Compounds by Deep Learning. <em>Journal of Chemical Information and Modeling</em>, 60(10), 4506-4517. <a href="https://doi.org/10.1021/acs.jcim.0c00459">https://doi.org/10.1021/acs.jcim.0c00459</a></p>
<p><strong>Publication</strong>: Journal of Chemical Information and Modeling 2020 (arXiv preprint Feb 2020)</p>
<p><strong>Additional Resources</strong>:</p>
<ul>
<li><a href="https://arxiv.org/abs/2002.09914">arXiv Page</a></li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bibtex" data-lang="bibtex"><span style="display:flex;"><span><span style="color:#a6e22e">@article</span>{oldenhof2020chemgrapher,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">title</span>=<span style="color:#e6db74">{ChemGrapher: Optical Graph Recognition of Chemical Compounds by Deep Learning}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">author</span>=<span style="color:#e6db74">{Oldenhof, Martijn and Arany, Ádám and Moreau, Yves and Simm, Jaak}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">journal</span>=<span style="color:#e6db74">{Journal of Chemical Information and Modeling}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">volume</span>=<span style="color:#e6db74">{60}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">number</span>=<span style="color:#e6db74">{10}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">pages</span>=<span style="color:#e6db74">{4506--4517}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">year</span>=<span style="color:#e6db74">{2020}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">publisher</span>=<span style="color:#e6db74">{ACS Publications}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">doi</span>=<span style="color:#e6db74">{10.1021/acs.jcim.0c00459}</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div>]]></content:encoded></item></channel></rss>