You can troubleshoot MolScribe predictions by comparing ground truth SMILES with predicted SMILES (SMILES), post-processed SMILES (post_SMILES), and graph-derived SMILES (graph_SMILES).
To visualize where the model is failing, you can overlay the predicted molecular graph (nodes and edges) onto the original image. The graph components are typically stored in the prediction CSV as:
node_coords: Normalized coordinates of atoms.node_symbols: Atomic symbols.edges: Adjacency matrix representing bond types.
When visualizing, remember that coordinates in the CSV are normalized; you must scale them by the image width and height to overlay them correctly.
# Example logic for scaling normalized coordinates to image dimensions
h, w, _ = img.shape
x, y = coords[:,0]*w, coords[:,1]*h
# Plotting nodes and symbols
plt.scatter(x, y, color='r', marker='o')
for i in range(len(symbols)):
plt.text(x[i], y[i], symbols[i], color='blue')
# Plotting edges (bonds)
for i in range(len(x)):
for j in range(len(x)):
if edges[i][j] != 0:
# Logic for different bond types (e.g., 5, 6, 1, etc.)
plt.plot([x[i], x[j]], [y[i], y[j]], color)