# Zero-Shot Detection of Visual Food Safety Hazards via Knowledge-Enhanced Feature Synthesis
## 3 Methodology
### Food Safety Knowledge Graph
#### 3.2.1 FSKG Construction  
We construct the FSKG as a heterogeneous graph \(\mathcal{G}=(\mathcal{N},\mathcal{E})\), where \(\mathcal{N}=\mathcal{F}\cup\mathcal{A}\) represents the node set comprising food categories \(\mathcal{F}=\{f_{1},f_{2},\ldots,f_{m}\}\) and visual safety attributes \(\mathcal{A}=\{a_{1},a_{2},\ldots,a_{n}\}\). The edge set \(\mathcal{E}\) consists of three types of relationships that capture different aspects of food safety knowledge. Figure 2 illustrates a representative subgraph of our FSKG focusing on bread-related hazards. The visualization shows three types of nodes: food categories (e.g., \"White Bread\" and \"Whole Wheat Bread\"), visual attributes (e.g., \"Fuzzy Growth Pattern\" and \"Green-Blue Discoloration\"), and their relationships. Edge thickness represents weight strength, demonstrating how knowledge propagates through the network to enable feature synthesis for unseen hazard classes. **Food-Attribute Relations (\(\mathcal{E}_{FA}\)):** These edges connect food categories to their associated visual safety attributes, with the edge weights reflecting the relevance of each attribute to the particular food category. The edge weight \(w_{ij}^{FA}\) between the food category \(f_{i}\) and attribute \(a_{j}\) is determined as follows:  
\[w_{ij}^{FA}=\alpha\cdot p_{ij}\cdot s_{ij} \tag{1}\]  
where \(p_{ij}\) is the normalized frequency of attribute \(a_{j}\) occurring in food category \(f_{i}\) within our dataset, \(s_{ij}\in[0,1]\) is an expert-assigned importance score, and \(\alpha\) is a normalization constant. For example, the edge weight between \"bread\" and \"mold growth pattern\" is 0.85, reflecting both a high frequency of occurrence (68% of contaminated bread samples)  
Figure 2: A subgraph of the Food Safety Knowledge Graph showing bread-related hazards. Circular nodes represent food categories, diamond nodes represent visual attributes, and edge thickness indicates the strength of the relationship. Numbers on edges show weights: Food–Attribute Relations (e.g., White Bread \(\rightarrow\) Fuzzy Growth Pattern [0.85]), Food–Food Relations (e.g., White Bread \(\leftrightarrow\) Whole Wheat Bread [0.87]), and Attribute–Attribute Relations (e.g., Fuzzy Growth Pattern \(\leftrightarrow\) Green-Blue Discoloration [0.73]). and high expert importance (0.9). Conversely, \"canned vegetables\" and \"mold growth pattern\" have a weight of only 0.15 due to the sterilization process preventing mold growth. **Food-Food Relations (\(\mathcal{E}_{FF}\)):** These edges link related food categories based on their similarity in composition and appearance, and their susceptibility to similar safety hazards. The similarity score \(w_{ij}^{FF}\) between food categories \(f_{i}\) and \(f_{j}\) is computed as follows:  
\[w_{ij}^{FF}=0.4\cdot\text{sim}_{\text{comp}}(f_{i},f_{j})+0.4\cdot\text{sim}_{ \text{hazard}}(f_{i},f_{j})+0.2\cdot\text{sim}_{\text{proc}}(f_{i},f_{j}) \tag{2}\]  
where \(\text{sim}_{\text{comp}}\) measures compositional similarity (water content, pH levels, nutrient profile), \(\text{sim}_{\text{hazard}}\) captures shared susceptibility to hazards, and \(\text{sim}_{\text{proc}}\) reflects processing and storage requirement similarities. For instance, \"fresh strawberries\" and \"fresh raspberries\" achieve a high similarity score of 0.92 due to their comparable water content (90-92%), pH levels (3.2-3.5), and susceptibility to similar mold and bacterial contamination. In contrast, \"fresh strawberries\" and \"dried fruits\" score only 0.28, as dehydration fundamentally alters the hazard profile. **Attribute Relations (\(\mathcal{E}_{AA}\)):** These edges connect visual safety attributes that frequently co-occur or share visual similarities, allowing the model to learn correlations between different manifestations of food safety issues. The co-occurrence weight is calculated based on the conditional probability of observing both attributes in the same food safety incident.