# Zero-Shot Detection of Visual Food Safety Hazards via Knowledge-Enhanced Feature Synthesis
## 3 Methodology
### Knowledge-Enhanced Feature Synthesizer
#### 3.3.1 Multi-Source Graph Fusion Module  
The MSGF module fuses knowledge from three complementary sources to create a comprehensive representation of food safety knowledge. The Food Safety Knowledge Graph provides domain-specific information about visual safety attributes and their relationships with food categories, offering a fine-grained semantic understanding of how safety issues manifest visually across different food types. The Hyperclass Graph models hierarchical relationships between hazard classes based on their taxonomic classification, enabling knowledge transfer from broader categories to specific instances. The Co-occurrence Graph captures statistical correlations between hazard classes based on their co-occurrence patterns in food safety datasets, leveraging empirical data on how different types of safety issues tend to appear together in real-world scenarios. By integrating these complementary knowledge sources, the MSGF module creates a rich semantic representation that captures both expert domain knowledge and empirical patterns observed in food safety data. For each graph source \(k\in\{1,2,3\}\), we define an adjacency matrix \(\mathbf{A}^{k}\in\mathbb{R}^{C\times C}\), where \(C\) is the total number of hazard classes. The first adjacency matrix \(\mathbf{A}^{1}\) represents the Food Safety Knowledge Graph, where \(\mathbf{A}^{1}_{ij}\) indicates the similarity between hazard classes \(i\) and \(j\) based on their shared visual attributes:  
\[\mathbf{A}^{1}_{ij}=\frac{|\mathcal{A}_{i}\cap\mathcal{A}_{j}|}{|\mathcal{A}_{i }\cup\mathcal{A}_{j}|} \tag{6}\]  
where \(\mathcal{A}_{i}\) and \(\mathcal{A}_{j}\) are the sets of visual attributes associated with hazard classes \(i\) and \(j\), respectively. The second adjacency matrix \(\mathbf{A}^{2}\) represents the Hyperclass Graph, where \(\mathbf{A}^{2}_{ij}\) is determined by the hierarchical relationship between classes \(i\) and \(j\):  
\[\mathbf{A}^{2}_{ij}= \begin{cases}l,&\text{if classes $i$ and $j$ share an ancestor at level $l$}\\ 0,&\text{otherwise}\end{cases}  \tag{7}\]  
where \(l\) denotes the level of the shared ancestor in the class hierarchy, with higher values indicating closer relationships. The third adjacency matrix \(\mathbf{A}^{3}\) represents the Co-occurrence Graph, where \(\mathbf{A}^{3}_{ij}\) is the conditional probability of class \(j\) given class \(i\):  
\[\mathbf{A}^{3}_{ij}=\frac{O_{ij}}{T_{i}} \tag{8}\]  
where \(O_{ij}\) is the number of instances where classes \(i\) and \(j\) co-occur, and \(T_{i}\) is the total number of instances of class \(i\). Each adjacency matrix is normalized and binarized using a threshold \(\tau\):  
\[\hat{\mathbf{A}}^{k}_{ij}= \begin{cases}1,&\text{if }\mathbf{A}^{k}_{ij}\geq \tau\\ 0,&\text{otherwise}\end{cases}  \tag{9}\]  
For each graph source \(k\), we compute graph embeddings using a graph convolutional network:  
\[\mathbf{E}^{k}=\psi^{k}(\mathbf{V})=\hat{\mathbf{A}}^{k}\sigma(\hat{\mathbf{A} }^{k}\mathbf{V}\mathbf{W}^{k}_{1})\mathbf{W}^{k}_{2} \tag{10}\]  
where \(\mathbf{V}\in\mathbb{R}^{C\times d_{v}}\) is the matrix of semantic vectors for all classes, \(\hat{\mathbf{A}}^{k}=\mathbf{D}^{-\frac{1}{2}}_{k}\hat{\mathbf{A}}^{k}\mathbf{ D}^{-\frac{1}{2}}_{k}\) is the normalized adjacency matrix, \(\mathbf{D}_{k}\) is the diagonal degree matrix of \(\hat{\mathbf{A}}^{k}\), and \(\mathbf{W}^{k}_{1}\in\mathbb{R}^{d_{v}\times d_{h}}\) and \(\mathbf{W}^{k}_{2}\in\mathbb{R}^{d_{h}\times d_{e}}\) are learnable weight matrices.