October 01, 2025
Polarization in ferroelectric domains arises from atomic-scale structural variations that govern macroscopic functionalities. The interfaces between these domains–known as domain walls–host distinct physical responses, making their identification and control critical. Four-dimensional scanning transmission electron microscopy (4D-STEM) enables simultaneous acquisition of real- and reciprocal-space information at the atomic scale, offering a powerful platform for domain mapping. However, conventional analyses rely on computationally intensive processing and manual interpretation, which are time-consuming and prone to misalignment and diffraction artifacts. Here, we present a convolutional neural network that, with minimal training, classifies polarization directions from diffraction data and segments domains in real space. We further introduce an adaptive sampling strategy that prioritizes images from domain wall regions, reducing the number of training images required while improving accuracy and interpretability. We demonstrate this approach for domain mapping in ferroelectric boracite, .
The ability to map polarization of domains and domain walls is essential for understanding functional properties in ferroelectric materials, where subtle structural variations influence electronic and mechanical behaviour. [1]. Advances in electron microscopy techniques, such as four-dimensional scanning transmission electron microscopy (4D-STEM), provide a powerful means to probe these domains by simultaneously capturing real and reciprocal space information. [2] [3] However, extracting meaningful insights from such datasets remains computationally intensive, particularly for complex materials where conventional analysis methods rely on manual interpretation. Artificial intelligence (AI) methods have facilitated a revolution in a vast array of other microscopy domains [4], including the use of autoencoder based methods to de-noise images [5], [6], classification and segmentation of STEM images [7]–[9], and the probing of latent spaces in variational autoencoders to extract features from 4D-STEM datasets [10].
4D-STEM enables high-resolution structural characterization by recording diffraction patterns at each scanned probe position. This microscopy technique generates a four-dimensional dataset, with two spatial dimensions \((N_x, N_y)\) representing the real-space scan coordinates and two reciprocal-space dimensions \((K_x, K_y)\) corresponding to the diffraction data recorded at each scan position. As a result, the dataset forms a four-dimensional array \((N_x, N_y, N_{kx}, N_{ky})\), where each pixel in the real-space image is associated with a full diffraction pattern (system illustrated in Figure 1). The challenge in analyzing polarization domains lies in effectively utilizing this rich cross-modal data set to extract meaningful information about the structural variations that define domains and the boundaries between them.
The analysis of polarization in ferroelectric materials using 4D-STEM typically involves detecting intensity variations in diffraction disks [11] or Kikuchi bands [12]. While this approach is well-established for classic ABO\(_{3}\) ferroelectrics, our study instead focuses on a boracite (M\(_3\)B\(_7\)O\(_{13}\)X) crystal, where symmetry changes introduce additional diffraction features aligned with the polarization direction [13]. These extra diffraction disks–often referred to as ‘ghost’ disks–provide insight into polarization shifts through their displacement in reciprocal space, as demonstrated in Figure 1.
The system we focus on here is the boracite . Boracite is an improper ferroelectric where polarization is not the main order parameter; instead, it arises from spontaneous strain, through a ferroelastic phase transition from cubic F4̄3c to orthorhombic Pca2\(_1\) space groups, accompanied by uniaxial shear and polarization along pseudocubic directions.[14] A characteristic of boracite is its six possible polarization directions, with domain walls and domains responding dynamically to an applied bias. As polarization flips at domain boundaries, neighbouring domains exhibit local variations. Manual 4D-STEM analysis reveals that, at certain angles, these domain walls display an intricate alternating polarization pattern. However, studying these effects at scale is problematic. In situ 4D-STEM experiments generate large amounts of data, often tens of terabytes, placing a high demand on storage and computational resources. Furthermore, the polarization behavior within moving ferroelectric walls does not follow a simple or predictable pattern.
To overcome these limitations, a deep learning model designed to automate the detection of domain walls was developed. This strategy not only streamlines data processing but also mitigates bottlenecks in analysis, ultimately accelerating the investigation of novel ferroelectric materials. In our approach, we pass the full 4D tensor into the model, where the diffraction patterns serve as input features for identifying domain walls. A convolutional neural network (CNN) learns to detect key diffraction-based signatures of polarization changes by analyzing local intensity variations in \((K_{x}, K_{y})\), while simultaneously preserving the spatial context in \((N_{x}, N_{y})\). The trained model then produces a segmentation mask in real space, effectively mapping polarization domains across the sample. By leveraging the expressive power of deep learning, this method enhances the efficiency of 4D-STEM analysis, processing a little over 7000 images in 10 seconds on a standard GPU workstation and enabling rapid and accurate domain segmentation without the need for extensive manual interpretation.
In perovskite ferroelectrics, the ability to determine polarization direction from 4D-STEM diffraction patterns relies on identifying subtle intensity variations in specific diffraction features.[[11]][12] In boracite, instead of tracking changes in diffraction pattern intensity, the relevant effect is a shift in the polarization vector caused by atomic displacements, leading to crystallographic-plane–dependent extinction and the appearance of additional “ghost” disks. To determine how the atomic displacements influence the polarization vector and the resulting diffraction pattern, we performed Density Functional Theory (DFT) relaxations for both the high-symmetry cubic F\(\bar{4}\)3c parent phase and the polar Pca2\(_1\) ground state of Cu\(_3\)B\(7\)O\({13}\)Cl boracite. Starting from experimental lattice parameters, we fully optimized atomic positions and cell dimensions (see Methods). The resulting equilibrium structures (Fig. 2) capture the Cu\(^{2+}\) off‐centering and Cl\(^-\) shifts that generate the net spontaneous polarization, as well as the anti-polar pattern of Cu–Cl displacements in the non-polar phase.
As shown in Figure 3, we first extracted the main polarization vectors obtained from the DFT calculations and the corresponding structural models. Using these as input, we simulated the diffraction pattern with the SingleCrystal software package. The simulated results reveal distinct shifts in the so-called “ghost” diffraction disk positions (Figure 3b), which can be directly associated with changes in crystal symmetry and, consequently, the underlying polarization states. Importantly, when comparing these simulations with the experimental 4D-STEM diffraction data, we observe additional diffraction disks arising from different domains (Figure 3c). The close agreement between simulated and experimental patterns provides strong evidence that the modifications in the diffraction features are indeed linked to domain-dependent variations in symmetry and polarization.
By analyzing diffraction patterns across the sample, we construct spatial maps of polarization domains. Conventional 4D-STEM data processing can be computationally intensive, as disk-detection methods implemented in py4DSTEMpy4DSTEM
[15] or pyxem
[16] require repeated fitting or correlation at every probe position, which is impractical for large datasets. To overcome this limitation, we developed a convolutional neural
network (CNN) to automate domain classification. The network architecture is shown in Figure 4, and its output corresponds to the predicted polarization direction: horizontal, vertical, or no polarization. A softmax
activation normalizes these outputs to probabilities between 0 and 1, providing classification confidence.
The physical origin of this classification is illustrated in Figure 3. Panel (a) shows representative atomic structures for in-plane horizontal, in-plane vertical, and out-of-plane polarization states. Simulated diffraction patterns in panel (b) reveal symmetry breaking and subtle intensity variations characteristic of each state. Experimental 4D-STEM diffraction images in panel (c) confirm these features, which the CNN exploits to reliably distinguish polarization domains. This integration of experiment, simulation, and machine learning enables high-throughput mapping of domain structures with significantly reduced computational cost.
From a total dataset of \(7,004\) diffraction images for a sample, 500 were randomly sampled, and manually labelled based on the direction of the ghost disks, serving as the ground truth for training. The model was
trained for 100 epochs using cross-entropy loss, achieving a validation loss of \(9\times 10^{-4}\). During inference, the trained model processed the entire dataset, producing a three-dimensional output for each
diffraction pattern corresponding to its predicted polarization state. These values were then mapped to an RGB colour space, with each prediction assigned to its respective spatial position in the real space image, generating a segmentation of the
polarization domains. Comparison with manual analysis using py4DSTEM
in Figure 5 shows how the model follows the same polarization trend with a domain wall positioned in the middle section of the
scan. Here, the region around the domain wall is assigned no polarization (red). This assignment is further confirmed in the labelling patterns observed in Figure 7. The absence of this region in the manual
analysis is likely due to the experimental conditions in this experiment, where the Bragg peaks are tightly compact, and the method of using offset filters to capture the ghost disks can fail in some cases.
To assess the robustness and data efficiency of the CNN model, we conducted experiments using progressively smaller training sets. Instead of training on the full set of 1,000 labelled diffraction images, we tested the model performance with subsets of this dataset, containing 50, 100, and 250 randomly sampled images. The number of training epochs was scaled accordingly to ensure adequate learning while avoiding overfitting, with 200 epochs for the 500-image dataset and up to 400 epochs for the 50-image dataset, where the epoch with the lowest validation loss was selected for each model.
Despite the reduced dataset sizes, the model demonstrated an ability to correctly classify polarization directions. As shown for the randomly labelled images d-f in Figure 6, even with only 50 labelled examples, the CNN identified major polarization regions, albeit with some noise at domain boundaries. As the dataset size increased, the ability of the model to resolve finer details improved, with the 100-image and 250-image models producing results closely matching the full dataset model. Notably, the model was better at detecting neutral polarization regions as more training data was incorporated.
While random sampling shows some success, it is likely that features at domain boundaries, which represent a smaller fraction of the data are undersampled. This leads to an overfit of horizontal and vertical polarization, with an absence of red (non-polar) regions in the right hand-side of Figure 6a. To address this overfitting, a targeted sampling strategy can be introduced to ensure that key diffraction images, particularly those associated with domain walls, are well represented even in smaller datasets. The algorithm consisted of two steps (detailed in the Supporting Information):
Coarse sampling in a uniform grid pattern across real space \((N_{x}, N_{y})\) with a step size \(s\). The sampled points are given by: \[\mathbf{p}_i = (N_{xi}, N_{yi}), \quad N_{xi} = i s, \, N_{yj} = j s, \quad i, j \in \mathbb{Z}\] where \(\mathbf{p}_i\) represents the coordinates of the sampled points in the 2D space. The set of sampled points is: \[\mathbf{P} = \{ \mathbf{p}_i : 0 \leq N_{xi} \leq X, 0 \leq N_{yi} \leq Y \}\] where \(X\) and \(Y\) are the dimensions of the image in real space.
Adaptive sampling near label boundaries. For each point \(\mathbf{p}_i \in \mathbf{P}\), the algorithm searched its 8 connected neighbours (i.e., the 8 points within a distance less than or equal to the step size \(s\)). Among these neighbours, it identified the closest point \(\mathbf{p}_j\) such that \(L(\mathbf{p}_j) \neq L(\mathbf{p}_i)\). If such a point was found, a new sample was generated at the midpoint: \[\mathbf{p}_{\text{new}} = \frac{\mathbf{p}_i + \mathbf{p}_j}{2}\] This operation was applied across all current points in \(\mathbf{P}\), generating new samples that densely populate boundary regions.
The labelling process (or additional experiments) can be carried out until the user is satisfied with the number of labels in the dataset. Experiments shown in Table 1 show that high accuracy can be achieved with only 50 images in the training set. This method, illustrated in row b) of Figure 6, resulted in significantly improved representation of the domain wall region across all training set sizes. The sampling regime can also be observed in Figure 7 and the algorithm can be found in the Appendix.
A separate test dataset of 1,000 diffraction images was curated, ensuring that none of these images appeared in any of the training datasets used for the models in Figure 6. All images were hand-labelled, and the accuracy of each model on this test set is reported in Table 1. The advantage of the binary search algorithm is evident in the modest yet meaningful increase in accuracy, particularly in the improved classification of domain boundary images, as shown in Figure 6. Interestingly, increasing the size of the training dataset beyond 50 images does not result in a significant improvement in testing accuracy, highlighting the efficiency of the algorithm with relatively small training sets. Attempts to reduce the training set size below 50 led to poor performance, as the required step size became too large and too few boundary images were included in the search.
Training Data Size | Binary algorithm accuracy | Random algorithm accuracy |
---|---|---|
50 | 96.9% | 95.0% |
100 | 96.3% | 95.7% |
250 | 96.2% | 94.2% |
Electron transparent cross-sections of single crystal were prepared for STEM using a dual-beam focused ion beam (FIB) integrated SEM (Thermo-Fisher Scientific FEI Helios G4 CX). The specimens were mounted onto a DENSsolutions in-situ heating and biasing MEMS chip. Thinning of the samples was done with decreasing accelerating voltage and electron beam current.
All 4D-STEM datasets were acquired on a probe-corrected Thermo Fisher Spectra 300 microscope operating at 300 kV, equipped with a Gatan Continuum energy filter and K3 direct electron detector. The K3 detector was operated in electron counting mode. The convergence angle of the scan was 0.8 mrad, and a 4 × 4 sub-scan was used without drift correction. The scan size was 206 × 34 pixels in real space with a pixel time of 0.02 s. Diffraction patterns were recorded with 512 × 512 pixels.
The py4DSTEM
package [15] was used to process the Gatan 4D-STEM .dm4
files and convert them into a .png
format and were then compressed to a \(256 \times 256\) pixel size to improve model training speeds and inference times. The next step required the manual labelling of sampled
random images from the 4D-STEM scan. The images were labelled as either horizontally polarized, vertically polarized, or with no observable polarization. This labelled dataset was then used to train the CNN model with a 80:20 train/test split for every
experiment, where, to avoid overfitting, the model checkpoint with the lowest validation loss was used at inference and evaluation time.
The model was created and ran using the PyTorch
software package [17]. Training of the model was run on a single Nvidia RTX
A6000 Ada Generation GPU for 100 epochs on the full 1000-image training set. Training completed in approximately 6 minutes for each experimental run. Due to the small size of the CNN model (2.1 million parameters), the model was also able to complete
inference on all \(7,004\) images in the 4D-STEM dataset in 11 seconds. The AdamW optimizer [18] was used for both models with a learning rate of \(4\times10^{-4}\), weight decay of \(2\times10^{-3}\), momentum of 0.9 and betas of 0.9 and 0.999. A
plateau learning rate scheduler was used with a patience of 2, a minimum learning rate of \(3\times10^{-5}\) and a maximum learning rate of \(5\times10^{-5}\).
First-principles calculations were performed within DFT as implemented in the Vienna Ab Initio Software Package (VASP) [19]. The projector-augmented wave method [20], [21] was employed, with the following valence configurations: O (2s\(^2\)2p\(^4\)), Cl (3s\(^2\)3p\(^5\)), B (2s\(^2\)2p\(^1\)), and Cu (3p\(^6\)3d\(^{10}\)4s\(^1\)). Exchange-correlation effects were treated using the PBE functional. Spin-polarized calculations were carried out with an on-site Hubbard \(U\) of 4 eV applied to Cu \(d\) states. This value was chosen by comparing the calculated magnetic properties (magnetic moments and relative energies of magnetic orders) for a range of \(U\) values to the metaGGA r2SCAN functional, which is known to have improved accuracy for magnetic materials. For all calculations, we used a plane-wave cut-off energy of 600 eV. The Brillouin zone was sampled with a \(4\times4\times4\) and a \(3\times3\times2\) Monkhorst-Pack \(k\)-point grid for the cubic and orthorhombic structures, respectively. The electronic convergence criterion is set to \(10^{-7}\) eV and the force convergence criterion is set to 0.002 eV/Å, finding good agreement with experimentally reported lattice constants. We do not include spin-orbit coupling in these calculations as it was found to have a negligible impact on the structural phases.
In summary, we demonstrate that CNNs enable automated identification and segmentation of polarization domains in ferroelectric materials from 4D-STEM diffraction data. This deep learning approach overcomes the limitations of conventional manual analysis, substantially improving both the speed and accuracy of domain mapping. The trained model reliably classifies polarization directions from diffraction features and produces real-space segmentation maps consistent with traditional interpretations.
Beyond domain mapping, our framework highlights the broader potential of machine learning in electron microscopy for the rapid and scalable analysis of large, information-rich 4D-STEM datasets. The ability of the CNN to achieve high accuracy with a minimal training set suggests general applicability to other material systems where subtle structural variations are critical. Furthermore, the labelling algorithm developed here provides a principled means of sampling diffraction data, enabling accurate classification even at domain walls.
Future efforts will extend this methodology to capture dynamic polarization responses under external stimuli and to integrate real-time inference for in situ studies. Together, these advances establish a pathway toward accelerating quantitative analysis and discovery in ferroic materials and related complex systems.
A repository with the open-source code is available at: https://github.com/FinHardy/ghost-hunter.
This work was made possible by the EPSRC Cryo-Enabled Multi-microscopy for Nanoscale Analysis in the Engineering and Physical Sciences EP/V007661/1. F. H., M.P., Y.L., and M.S.C. acknowledge funding from the Royal Society Tata University Research Fellowship (URF\R1\201318) and Royal Society Enhancement Award RF\ERE\210200EM1. M.S.C. acknowledges funding that supported this work from ERC CoG DISCO grant 101171966 and EPSRC grant EP/V001914/1. G.T. acknowledges funding from the EPSRC Centre for Doctoral Training in the Advanced Characterisation of Materials (CDTACM)(EP/S023259/1) and Cameca Ltd. for funding their PhD studentship. This work was funded in part by the U.S. Department of Energy, Office of Science, Office of Basic Energy Sciences, Materials Sciences and Engineering Division under Contract No. DE-AC02-05-CH11231 within the Theory of Materials program (first-principles calculations). Computational resources were provided by the National Energy Research Scientific Computing Center and the Molecular Foundry, DOE Office of Science User Facilities supported by the Office of Science, U.S. Department of Energy under Contract No. DEAC02-05CH11231. The work performed at the Molecular Foundry was supported by the Office of Science, Office of Basic Energy Sciences, of the U.S. Department of Energy under the same contract.