Authors’ overview
We present the tool VoxLogicA2, a spatial model checker aimed at Computer Vision, with applications in high-resolution 2D and 3D medical imaging. The new version of the tool combines logical primitives, non-logical primitives, and training and prediction primitives of state-of-the-art neural networks, freely interleaved with the symbolic tool functionality. The primary application field is neuro-symbolic medical image analysis. VoxLogicA2 is a fast, parallelising spatial model checker with a declarative domain-specific language, capable of describing both the learning procedures and the spatial logic procedures of an analysis in one program. We validate our approach by verifying its improved efficiency, and by using the new constructs of the language to describe case studies of previous work, which were based on Python, with a specification that uses VoxLogicA2 only
Introduction
Medical image analysis requires perception abilities as well as symbolic reasoning and knowledge representation capabilities. When analysing an image, we may be interested in enforcing some constraints, or exploit domain specific knowledge. Today this analysis is most often carried out by neural networks, which perceive at the level of a human expert but do not reason symbolically. The BraTS challenge is a competition among different methods performing high grade glioblastoma segmentation. Machine Learning (ML) methods achieve very high accuracy, which is crucial as segmentation is the basis for follow up therapies, like radiotherapy. Still, the predictions are not explainable nor auditable, which are desired properties for a physician to understand the procedure leading to a certain result. It is thus natural to ask whether it is possible to combine these two approaches in order to get efficient, accurate, auditable, reproducible and explainable results.
The field that combines symbolic and neural methods, neuro-symbolic AI, is a particularly active area of research (see e.g. ). Its application to image analysis is motivated by the complementary strengths and weaknesses of neural and symbolic representations: neural models are effective at extracting semantic information from visual data, but are weak in providing explanations for their results. Symbolic representations, instead, can explicitly capture domain knowledge and relations between the spatial entities identified in an image, but are weaker in capturing the variability of real-world datasets. A careful combination of the two approaches may give the advantages of both and increase the reliability and the explainability of the image analysis. This requires however a suitable platform to operate such combined methods that is transparent, auditable and permits easy and controlled replication of the results. This is the main aim of VoxLogicA2.
In recent years, spatial logic emerged as a suitable symbolic language to express properties (such as reachability, distance, similarity, shape and proximity) of entities located in logical or physical spaces, among which general graphs, polyhedra and digital images. Ciancia et al. introduced the Spatial Logic for Closure Spaces (SLCS), a spatial logic interpreted over Cêch closure spaces, a generalisation of topological spaces. Digital images are symmetric regular graphs, whose nodes are pixels (voxels in 3D) and whose edges are given by adjacency, so SLCS can state properties of images.
Along with SLCS various spatial model checkers have been developed, among which VoxLogicA, which is specialised and highly optimised for digital images. VoxLogicA obtained results on par with the state of the art on the Brain Tumour Segmentation challenge (BraTS) dataset, both in terms of accuracy, compared to provided expert ground truth segmentation, and in terms of performance, i.e. computational resources and time needed to obtain the results. See for an overview on recent work on spatial model checking and for a hands-on tutorial for VoxLogicA.
AI for imaging and nnU-Net
Biomedical image analysis increasingly relies on deep neural networks, and in particular on U-Net, the most widely adopted architecture for medical image segmentation, to automatically extract meaningful representations from medical images. Among these tasks, semantic segmentation aims at assigning a semantic label to each pixel or voxel of such images, enabling the delineation of anatomical structures or pathological regions of interest.
Despite their accuracy, the deployment of such networks in actual medical workflows is often hindered by the expertise required to configure them and by the black-box nature of the resulting learned model. Achieving high quality segmentation typically requires substantial dataset-specific choices concerning preprocessing, network configuration, training, and post-processing. nnU-Net addresses the first problem with a self-configuring method for medical image segmentation, a strong baseline that often matches or outperforms highly specialised methods. The second problem, the lack of explainability and transparency, cannot be solved by configuration; here the symbolic approach plays a complementary role, providing a domain-oriented, logic-based description of the segmentation.
Tool Architecture and Implementation
The implementation of the precursor of VoxLogicA2, VoxLogicA, is written in F# and is itself parallelised on CPU; an on-GPU version, used for video-stream analysis, was introduced in, as well as a temporal extension for the analysis of spatio-temporal properties, according to the language introduced in. VoxLogicA2 is implemented entirely in Python, as it is the preferred language in the area of neural networks. Although Python is interpreted, VoxLogicA2 matches the speed of VoxLogicA on a single case and is faster on a whole dataset (Section 5), thanks to native libraries, the Numba just-in-time compiler, and the release of the global interpreter lock in modern Python.
Front-end of VoxLogicA2
VoxLogicA2 takes as input a declarative specification in the Image Query Language (ImgQL). The module Parser parses this into an Abstract Syntax Tree (AST). The Reducer turns the AST into the SymbolicPlan, an append-only Merkle DAG in which two identical sub-expressions have the same identity and are stored once, whatever the order in which the graph was built. Nothing is executed at this stage: the plan only records what the engine will compute.
The declarative language ImgQL includes all the SLCS operators, a number of domain specific derived operators, and operators for manipulating images. For VoxLogicA2 the language has been extended, since Python gives a faster path to many libraries that are useful in the application domain. A wide range of imaging primitives, based on the Insight Tool Kit (ITK), an open source, cross platform library for (medical) image analysis, through SimpleITK, now covers the whole spectrum of image analysis, and all the primitives of VoxLogicA are available as well. The language also has primitives for managing collections of data. Among them, map applies a function to every element of a sequence, and fold combines the elements of a sequence into a single value, using an operator such as addition or maximum.
Node table and store
The node table records, for each node of the plan, its state and, once computed, its value. Since the identity of a node is a hash of its contents, it is the same across threads and processes, and it serves as the key of a two-level cache: values in use are kept in memory, and every computed value is also written to a store on disk together with its recipe, that is, the operator, the identities of the arguments and the attributes (such as the value of a constant). Recipes and small values are kept in an SQLite database, while large values such as images are written as separate files next to it, outside the database. A cache hit is therefore not limited to the current session: running the same program twice returns immediately on the second run, and so does a different program that shares sub-expressions with the first one. A node is dispatched at most once. The cache can be disabled via program options.
Dependency graph
A node becomes ready to run when the last of its inputs has been computed, as in Kahn’s topological sorting applied incrementally: when a node completes, only the nodes that consume it are updated, so the cost of scheduling depends on the frontier of the computation and not on the size of the plan. The graph also counts, for each value, the consumers that still have to run; a value is dropped from memory as soon as its last consumer has run, so the working set follows the frontier of the computation. Dropping a value is always safe, because readiness depends on completion and not on the value being in memory: an evicted value costs at most a reload from the store, or a recomputation when the store is disabled.
Fusion
Many operations of an image analysis are element-wise: the value of each voxel of the result depends only on the same voxel of the inputs, as for thresholds, Boolean connectives and arithmetic. When a worker takes such an operation from the ready queue, the engine groups it with the element-wise operations that consume its result and whose other inputs are already available, up to a fixed size. The group, called a cone, never includes ITK filters such as distance transforms or morphology, which end it. The cone is dispatched as a single task and, when possible, compiled with Numba into a single loop over the voxels, so the intermediate images inside the cone are never stored. Section 5 measures the effect of fusion.
Memory governor
The governor bounds the resident memory of the process as measured by the operating system, rather than the engine’s own count of the values it holds, which misses, for example, the internal buffers of the imaging libraries.
Primitives such as map and fold are not easy to implement in a semantics based on nodes such as ours: the identity of a node is fixed by the expression it computes, but the elements of a sequence, and often their number, are only known once the sequence has been computed, so the nodes that a map stands for cannot all be created before execution starts.
Iteration has a single semantics, which is reduction. The body of a for or a map is never interpreted to a value: as soon as the iterable is computed, the body is reduced once per element into new nodes, exactly as the reducer does at compile time for a constant sequence, and the resulting nodes are hash-compared against the ones already known, so whatever the elements share is computed once. Iteration therefore re-enters the same scheduling cycle as every other node, and the DAG remains the only place where the meaning of a program lives.
An interrupted computation can be resumed from the cache. The computation boundary (the nodes that are ready but not yet computed) is written to the store at a fixed interval, and when the body of a for has been reduced over every element of a sequence, the fact that the reduction is complete is recorded together with the nodes it produced, so that a later run is not obliged to reduce the body again merely to learn the names of nodes whose values it already holds.
Symbolic Whole Tumour Segmentation and Threshold Sweep
The function preprocess normalises the FLAIR image. Images acquired with different scanners and protocols may vary in absolute intensity, so thresholds are applied to percentiles rather than to intensities. The background consists of the voxels from which the border of the image can be reached only passing through very low intensity voxels; percentiles are computed over the remaining voxels, i.e. those being part of the brain. The function segment computes the hyper-intense voxels (above hi_thr, the 7% most intense voxels) and the very intense ones (those above the vi_thr threshold), smoothens them with radius 5 and 2 mm respectively, and grows the former, high intense area, into the touching parts of the latter, very intense, areas. The reference ground truth (whole_tumour) image consists of the voxels with a tumour label, i.e. of value 1 or more in the ground truth image that was segmented manually by domain experts. The function dice shows how the similarity index is calculated between a segmentation a and a reference segmentation b. It makes use of the function volume that counts the number of voxels in a given area. The function and of two segmentations a and b gives the voxels where a and b overlap.
For each case i, sweep_of computes the Dice index of the segmentation against the expert annotation for each of the 21 thresholds from 0.72 to 0.92; best_dice and best_vi_thr collect, per case, the best Dice and the threshold that achieves it, over the 20 evaluated cases.44 4 We report results on only 20 cases, consistent with the artifact accompanying this paper, to keep testing times reasonable. Although these results are generally good, these 20 cases include some outliers. Therefore Dice scores for a much larger set of cases reported in are considerably higher.
Neuro-symbolic Whole Tumour Segmentation
Program 2 trains a nnU-Net model on the four modalities of the 50 training cases, with the expert annotation flattened to one whole-tumour class, and builds a predictor from it. All the configuration parameters of nnU-Net are explicit in the program, so that the procedure can be inspected, audited and replicated. Most importantly, training and prediction are ordinary nodes of the plan: their results are stored in the cache, so running the specification again reuses the trained model and predictor instead of training the network again.
With these definitions in place, the neuro-symbolic experiment requires a single change to Program 1: the reference truth in sweep_of becomes truth_of(i), the prediction of the network, instead of the expert annotation. The threshold is thus chosen per case without any expert input. This mimicks the case in which one is dealing with new patient data for which no expert segmentation is available yet, which is the typical situation in a clinical setting. For comparison, the program also computes the Dice index, sensitivity and specificity of the predicted segmentation by the network itself against the expert annotation, and of the best symbolic segmentation against the segmentation predicted by the network.
Related Work
Manual segmentation is still the standard for in vivo images. However, this method is expensive and time-consuming, difficult to reproduce and possibly inaccurate due to human error. In areas where large, reliable datasets are available, machine learning and deep learning approaches have shown promising results in pattern recognition. Deep learning is based on the use of artificial neural networks, consisting of several layers, that can extract a hierarchy of features from raw input data. These methods often depend heavily on the availability of large training datasets. An interesting recent survey on such methods can be found in Akkus et al. and in work by Xia et al.. The latter work is based on self-supervised learning and semi-supervised medical image segmentation of CT scans. The work in exploits the enlarged discrepancies at the feature level to train differential decoders and then learn from these differential features in an iterative way.
Spatial model checking for the analysis of medical images is relatively recent and there are only a few articles exploring this field so far. In work by Sundstrom et al., spatio-temporal model checking techniques are used for the detection of tumours. The work is inspired by that of Grosu et al. and aims at pursuing machine learning of the logical structure of image features. In contrast, the tool VoxLogicA2 focuses on human-intelligible logical descriptions that can be reused and extended. In earlier work by Grosu et al., a variant of spatial logic is proposed where spatial properties are expressed using quad trees. The combination of the latter logic with linear time signal temporal logic has led to the spatio-temporal logic SpaTeL. A further variant combining spatial logic and signal temporal logic is the Signal Spatio-Temporal Logic (SSTL). There a bounded surround operator is introduced that is inspired by the surround operator of an earlier version of the logic SLCS.
Conclusions
As future work, we plan to integrate formal verification in the development of VoxLogicA2, in order to obtain formal guarantees about the correctness of the coordination and scheduling layer. Testing gives us confidence in the programs we run, while formal analysis of the coordination and scheduling model can ensure correctness on any run, even with millions of nodes involved.
The nondeterminism of training remains an open problem: a network trained twice on the same data need not give the same predictions, and hence the same calibrated thresholds. Future work should study mechanisms to make models “deterministic enough”, with results that are stable and depend only on a pseudo-random seed, and the stability of nnU-Net and other networks under retraining in different random conditions. Moreover, we plan to validate the tool with experiments involving physicians, in order to evaluate usability and clarity of the tool.


