Accurate diagnosis and prognosis prediction of gastric cancer using deep learning on digital pathological images: A retrospective multicentre study
We first searched PubMed and learned about relevant researches, and then carried out our project (Dec. 5, 2019). We searched for the keywords “gastric cancer” AND “deep learning” OR "artificial intelligence", with no restrictions on language or publication date. We learned that gastric cancer (GC) was the fifth most common type of malignant disease, and it ranks as the third leading cause of cancer-related deaths worldwide. Pathological evaluation remains the gold standard for the diagnosis of GC. When deciding on the necessity for further expensive and painful adjuvant treatments after surgery, clinicians tend to make decisions according to evidence-based information about the risk of death. Convolutional neural network (CNN) is a high-efficient deep learning method for image recognition and has excelled in quite a few image interpretation tasks and might be utilized to abstract additional characteristics from pathological images of GC patients. There had been a number of AI studies focusing on GC, most of which relied on endoscopy and medical radiologic technology. A few articles had focused on the application of deep learning algorithm to pathology of GC. There was still much room for improvement in developing AI models to diagnose GC and predict survival outcome through pathological pictures, especially to improve the performance of AI models.   In this study, we designed a CNN-based model, GastroMIL, for the accurate diagnosis of GC directly from digital H&E-stained pictures. Encouragingly, this diagnosis model achieved excellent performance in differentiating GC from normal tissues in the training and internal validation sets (AUC nearly 1.000). Moreover, we have successfully developed a deep learning-based model, MIL-GC, to automatically predict OS in patients with GC with C-index of 0.728 and 0.671 in the training and internal validation sets. And we also used an independent external validation set, and the two models showed good diagnostic (AUC = 0.978) and prognostic (C-index = 0.657) prediction performance, indicating good robustness of the two designed models. And the risk score computed by MIL-GC was proved to be of independent prognostic value of GC by univariate and multivariable Cox analyze. In the comparison with human pathologists, the diagnostic model (GastroMIL) achieved accuracy better than that of the junior pathologist and comparable to that of expert pathologists. More importantly, we further constructed the first webpage (https://baigao.github.io/Pathologic-Prognostic-Analysis/) for the automatic diagnosis of GC and survival prediction.   Our models can be adopted to make diagnosis with high accuracy and help clinicians select the appropriate adjuvant therapy following surgery, by identifying patients at high risk who would benefit from intensive regimens as well as patients at low risk who might be cured through surgery alone. It will help improve the survival status of GC patients and reduce the high mortality.   Gastric cancer (GC) is the fifth most common type of malignant disease, and it ranks as the third leading cause of cancer-related deaths worldwide . For patients with early GC, the 5-year survival rate can exceed 90% . However, approximately half of patients with GC already proceed the advanced stage at the time of diagnosis, with the 5-year survival rate dropping below 30% . To reduce the mortality of GC, early detection and appropriate treatment are crucial, and precise and efficient pathology services are indispensable to realize this goal. Pathological evaluation remains the gold standard for the diagnosis of GC. Conventionally carried out by pathologists, this method is labor-intensive, tedious, and time-consuming. A severe shortage of pathologists and a heavy workload of diagnosis are widespread problems globally, which negatively affect the diagnostic accuracy . Accordingly, it is necessary to design a new method to conveniently and accurately diagnose GC using pathological pictures. Surgery is the main treatment for GC, followed by adjuvant treatments including chemoradiotherapy and molecular targeted therapy , , . When deciding on the necessity for further expensive and painful adjuvant treatments, clinicians tend to make decisions according to evidence-based information about the risk of death. Clinical practice has confirmed that prognoses of almost all human cancers, including GC, are closely related to pathological criteria , especially the tumour-node-metastasis (TNM) staging system specified and revised by the American Joint Committee on Cancer (AJCC) . However, manual histological analysis of tumour tissues is still not accurate enough to stratify and identify those who may benefit from adjuvant treatment. Hence, there is an urgent need to develop succinct and reliable methods to predict overall survival (OS) of patients with GC, which could assist in developing individualized therapeutic strategies and maximizing the benefits. In recent years, deep learning has gradually attracted the attention of oncologists. Deep learning belongs to the class of machine learning that can successively identify more abstract information from the input data , , . Deep learning has progressed remarkably in the field of oncology, and has been demonstrated to be superior to conventional machine learning techniques . Convolutional neural network (CNN) is a high-efficient deep learning method for image recognition and has excelled in quite a few images interpretation tasks . Many studies have reported that artificial intelligence (AI) trained with endoscopic images could detect GC precisely , , , . When it comes to the field of tumour detection and prediction of prognosis of GC using AI through pathological images, some progress has been made. Song et al. reported a histopathological diagnosis system for GC detection using deep learning with the sensitivity near 100% and average specificity of 80.6%. Another research developed recalibrated multi-instance deep learning for whole slide gastric image classification with 86% accuracy . Wang et al. successfully predicted GC outcome from resected lymph node histopathology images using deep learning. Before proposing our models, we had established a number of challenges that needed to be overcome in order to make the developed AI models better applicable to clinical practice. First of all, a large sample size from multiple centres should be available for training and validating the proposed model to ensure the robustness. While ensuring the effectiveness of model training, it is preferable not to rely on extensive manual pixel-level annotation, which would be laborious and time consuming and might hinder the development of AI in the field of pathology. The developed model should be able to be applied in clinical practice, and it should be simple, affordable and accessible enough to be easily used by people without an AI background or in places where the economy is not particularly developed. We hoped to accomplish these challenges better than previous studies. In this study, we developed deep learning-based models, named GastroMIL and MIL-GC, for precisely and conveniently detecting tumour and predicting outcome of GC by analyzing pathological pictures, respectively. GastroMIL and MIL-GC were proved to be novel and strong predictors for diagnosis and outcome of GC patients on both internal and independent external validation sets. In the comparison with human pathologists, our GastroMIL model outperformed the junior pathologist and achieved a great agreement with expert pathologists. Furthermore, we designed an online website ( https://baigao.github.io/Pathologic-Prognostic-Analysis/ ) based on our analysis to make this prediction more available to users who have no knowledge of AI.   Patient Population Three different cohorts were retrospectively collected to achieve a broad patient representation and thereby improve the ability to generalize results to other cohorts. In the Renmin Hospital of Wuhan University (RHWU; Wuhan, Hubei, China), we continuously collected 871 candidate patients with GC from 2012 to 2017, together with corresponding 588 tumour tissue blocks (made from surgically removed tumour tissue, which was formalin-fixed and paraffin-embedded) and 1276 pathological images. 1057 digital H&E-stained pictures of 449 GC patients from The Cancer Genome Atlas (TCGA) public dataset were collected, 934 of which were malignant and 123 were normal. In addition, 91 GC patients with 175 digital pictures were acquired from National Human Genetic Resources Sharing Service Platform (NHGRP; Shanghai, China) and served as the independent validation set to evaluate the robustness of our models. We adopted the following inclusion criteria for developing the diagnostic model: (a) patients unequivocal diagnosed with GC by preoperative biopsy or postoperative pathological examination; (b) patients older than 18 years old and assentient to participate in this study; and (c) pathological images available and clear rather than loss, destruction or mildew. Pictures used in the diagnostic model were excluded from the prognostic model when they met the following conditions: (a) identified as normal; (b) lack of follow-up information; and (c) no critical clinicopathologic information available. Sample collection Digital images of H&E-stained pathological images were used to construct the computer frameworks. For each GC patient, we selected two representative images in principle, which included tissues from not only GC tumour but also surrounding normal gastric tissues. For candidate patients from RHWU, the corresponding formalin-fixed, paraffin-embedded tumour tissue blocks, made from surgically removed tumour tissue, and their H&E-stained slides were obtained. Next, two expert pathologists A and B selected preferred blocks and marked areas that were cancerous or normal independently. When it came to a disagreement between them, the diagnostic opinion of another expert pathologist C was final adopted. Expert pathologists A and B were associate chief pathologists, while expert pathologists C was chief pathologist. The marked areas were utilized to construct tissue microarrays (TMAs), which were then photographed to obtain 1276 digital H&E-stained images, of which 640 were malignant and 636 were normal. For the TCGA cohort, 1057 pathological pictures (malignant 936, normal 123) were downloaded from the website ( https://www.cbioportal.org/study/summary?id=lihc_tcga ). In view of the uneven number of cancerous and normal pictures in the TCGA cohort, the data augmentation technique was used to equalize the distribution of images. In the external validation cohort from NHGRP, there were 91 malignant digital pathological images and 84 normal. Clinical and pathological information was additionally needed for survival analysis, including survival state, OS time, age, sex, tumour size, neoplasm histologic grade, and pathologic T,N, M and TNM stages (according to the American Joint Committee on Cancer (AJCC) Cancer Staging Manual, Eighth Edition, 2017) . Clinicopathological data of patients from the RHWU cohort were collected through electronic medical records, and those of the TCGA and NHGRP cohorts were downloaded directly from the official website. This retrospective study was checked and approved by the clinical ethics committees of RHWU (No. WDRY2021-K002). And informed consents were gained from patients. Diagnostic Model Firstly, we designed a diagnostic model, named GastroMIL, to distinguish GC images from normal gastric tissue images. In order to avoid complex manual annotation, we applied weak supervised learning to our algorithm framework, specifically multiple instance learning (MIL) , , , . Based on the assumption of MIL, each input image was a bag, and the tiles it contained were the example instances. To develop the model, we only needed coarse-grained labels of bags, that is, pathological diagnosis of each image. When the target picture was marked positive, at least one tile was positive; if the target picture was marked negative, all tiles should be negative. Given that the images used to train the model had different magnifications, specifical the original magnification of images from TCGA was 20 × (without fixed size, could larger than 30000*30000 pixels), whereas that of RHWU was 30 × (3200*2400 pixels), we uniformly processed these images into 5 ×, 10 ×, and 20 × magnification and use them to develop the algorithm separately. Our GastroMIL model comprised two-step algorithms ( a-b). First of all, each input image was split into fixed-size tiles with 224 × 224 pixels, the labels of which were the same as the pathological diagnoses of the image itself. These tiles were used as training data for the first step algorithm, the MIL classifier. There were 10548460 tiles used for training and 4523755 tiles used for internal validation. Considering accuracy and efficiency, we chose RegNet developed by Facebook to constitute the backbone of MIL. The output of RegNet was the probability of these tiles being malignant. To obtain the inference results of the complete pictures, we introduced a recurrent neural network (RNN) as the second step classifier. Feature vectors with dimension 608 of the 32 most suspicious tiles gained from each picture by the first step were sequentially passed on to the RNN classifier to predict the probability of malignancy of the entire picture. The GastroMIL model could thus not only distinguish malignant images from normal, but also identify regions of interest (ROIs) by the segmentation and analysis of tiles. ROI indicated the area recognized as malignant by GastroMIL, which could be visualized in the form of heat map ( b) and provide additional guiding information for clinicians. Prognostic Model After identifying the malignant images, we developed another model, MIL-GC, to predict the prognosis of GC patients. As shown in a-c, the first step of MIL-GC was similar to that of the GastroMIL model, and the 128 most suspicious tiles were selected and output as feature vectors with dimension 608. In the second step, each feature vector would finally yield a probability value between 0 and 1, through a multilayer perceptron (MLP) algorithm. Probability values of the 128 most suspicious tiles of the input picture were merged to generate an average value as the output risk score. Statistical analysis Receiver operating characteristic (ROC) curves and areas under the curve (AUCs), analysed with scikit-learn, a Python software package for machine learning, were used to quantify the performance of the diagnostic classifier as well as accuracy, sensitivity, and specificity. The cut-off value of ROC curves was set as 0.5. Cohen's kappa coefficient was used to assess the inter-observer agreement of the diagnostic model (GastroMIL) and human pathologists. To assess the predictive performance of the prognostic classifier, we adopted Harrell's concordance index (C-index) as a metric. Kaplan-Meier survival curve plotted with GraphPad Prism_9 was used to evaluate the correlation between risk score generated by prognostic models and OS of GC patients and Log-Rank test was performed. Prognostic factors were identified using univariate and multivariate Cox proportional hazards models implemented in SPSS26.0. The statistical significance level was set at 0.05 (two-tailed). Statistical significance threshold was adjusted for multiple comparisons using the Bonferroni correction. Python and Pytorch were employed to build the algorithm. Role of the funding source Not applicable.   Three different cohorts were retrospectively collected to achieve a broad patient representation and thereby improve the ability to generalize results to other cohorts. In the Renmin Hospital of Wuhan University (RHWU; Wuhan, Hubei, China), we continuously collected 871 candidate patients with GC from 2012 to 2017, together with corresponding 588 tumour tissue blocks (made from surgically removed tumour tissue, which was formalin-fixed and paraffin-embedded) and 1276 pathological images. 1057 digital H&E-stained pictures of 449 GC patients from The Cancer Genome Atlas (TCGA) public dataset were collected, 934 of which were malignant and 123 were normal. In addition, 91 GC patients with 175 digital pictures were acquired from National Human Genetic Resources Sharing Service Platform (NHGRP; Shanghai, China) and served as the independent validation set to evaluate the robustness of our models. We adopted the following inclusion criteria for developing the diagnostic model: (a) patients unequivocal diagnosed with GC by preoperative biopsy or postoperative pathological examination; (b) patients older than 18 years old and assentient to participate in this study; and (c) pathological images available and clear rather than loss, destruction or mildew. Pictures used in the diagnostic model were excluded from the prognostic model when they met the following conditions: (a) identified as normal; (b) lack of follow-up information; and (c) no critical clinicopathologic information available.   Digital images of H&E-stained pathological images were used to construct the computer frameworks. For each GC patient, we selected two representative images in principle, which included tissues from not only GC tumour but also surrounding normal gastric tissues. For candidate patients from RHWU, the corresponding formalin-fixed, paraffin-embedded tumour tissue blocks, made from surgically removed tumour tissue, and their H&E-stained slides were obtained. Next, two expert pathologists A and B selected preferred blocks and marked areas that were cancerous or normal independently. When it came to a disagreement between them, the diagnostic opinion of another expert pathologist C was final adopted. Expert pathologists A and B were associate chief pathologists, while expert pathologists C was chief pathologist. The marked areas were utilized to construct tissue microarrays (TMAs), which were then photographed to obtain 1276 digital H&E-stained images, of which 640 were malignant and 636 were normal. For the TCGA cohort, 1057 pathological pictures (malignant 936, normal 123) were downloaded from the website ( https://www.cbioportal.org/study/summary?id=lihc_tcga ). In view of the uneven number of cancerous and normal pictures in the TCGA cohort, the data augmentation technique was used to equalize the distribution of images. In the external validation cohort from NHGRP, there were 91 malignant digital pathological images and 84 normal. Clinical and pathological information was additionally needed for survival analysis, including survival state, OS time, age, sex, tumour size, neoplasm histologic grade, and pathologic T,N, M and TNM stages (according to the American Joint Committee on Cancer (AJCC) Cancer Staging Manual, Eighth Edition, 2017) . Clinicopathological data of patients from the RHWU cohort were collected through electronic medical records, and those of the TCGA and NHGRP cohorts were downloaded directly from the official website. This retrospective study was checked and approved by the clinical ethics committees of RHWU (No. WDRY2021-K002). And informed consents were gained from patients.   Firstly, we designed a diagnostic model, named GastroMIL, to distinguish GC images from normal gastric tissue images. In order to avoid complex manual annotation, we applied weak supervised learning to our algorithm framework, specifically multiple instance learning (MIL) , , , . Based on the assumption of MIL, each input image was a bag, and the tiles it contained were the example instances. To develop the model, we only needed coarse-grained labels of bags, that is, pathological diagnosis of each image. When the target picture was marked positive, at least one tile was positive; if the target picture was marked negative, all tiles should be negative. Given that the images used to train the model had different magnifications, specifical the original magnification of images from TCGA was 20 × (without fixed size, could larger than 30000*30000 pixels), whereas that of RHWU was 30 × (3200*2400 pixels), we uniformly processed these images into 5 ×, 10 ×, and 20 × magnification and use them to develop the algorithm separately. Our GastroMIL model comprised two-step algorithms ( a-b). First of all, each input image was split into fixed-size tiles with 224 × 224 pixels, the labels of which were the same as the pathological diagnoses of the image itself. These tiles were used as training data for the first step algorithm, the MIL classifier. There were 10548460 tiles used for training and 4523755 tiles used for internal validation. Considering accuracy and efficiency, we chose RegNet developed by Facebook to constitute the backbone of MIL. The output of RegNet was the probability of these tiles being malignant. To obtain the inference results of the complete pictures, we introduced a recurrent neural network (RNN) as the second step classifier. Feature vectors with dimension 608 of the 32 most suspicious tiles gained from each picture by the first step were sequentially passed on to the RNN classifier to predict the probability of malignancy of the entire picture. The GastroMIL model could thus not only distinguish malignant images from normal, but also identify regions of interest (ROIs) by the segmentation and analysis of tiles. ROI indicated the area recognized as malignant by GastroMIL, which could be visualized in the form of heat map ( b) and provide additional guiding information for clinicians.   After identifying the malignant images, we developed another model, MIL-GC, to predict the prognosis of GC patients. As shown in a-c, the first step of MIL-GC was similar to that of the GastroMIL model, and the 128 most suspicious tiles were selected and output as feature vectors with dimension 608. In the second step, each feature vector would finally yield a probability value between 0 and 1, through a multilayer perceptron (MLP) algorithm. Probability values of the 128 most suspicious tiles of the input picture were merged to generate an average value as the output risk score.   Receiver operating characteristic (ROC) curves and areas under the curve (AUCs), analysed with scikit-learn, a Python software package for machine learning, were used to quantify the performance of the diagnostic classifier as well as accuracy, sensitivity, and specificity. The cut-off value of ROC curves was set as 0.5. Cohen's kappa coefficient was used to assess the inter-observer agreement of the diagnostic model (GastroMIL) and human pathologists. To assess the predictive performance of the prognostic classifier, we adopted Harrell's concordance index (C-index) as a metric. Kaplan-Meier survival curve plotted with GraphPad Prism_9 was used to evaluate the correlation between risk score generated by prognostic models and OS of GC patients and Log-Rank test was performed. Prognostic factors were identified using univariate and multivariate Cox proportional hazards models implemented in SPSS26.0. The statistical significance level was set at 0.05 (two-tailed). Statistical significance threshold was adjusted for multiple comparisons using the Bonferroni correction. Python and Pytorch were employed to build the algorithm.   Not applicable.   Patient characteristics A total of 871 GC patients were initially screened from the RHWU cohort, and 588 with tumour tissue blocks were eligible for the study. There were 449 GC patients with digital H&E-stained pathological images were eligible for this study in the TCGA cohort and 91 in the NHGRP cohort. A total of 1276 images from the RHWU cohort and 1057 images from the TCGA cohort were obtained for the development of the GastroMIL model. Through data augmentation, 3221 pictures (malignant: normal = 1574: 1647) were finally enrolled in the GastroMIL model and 70% ( N = 2261) were randomly assigned to the training set while the remaining 30% ( N = 960) were included in the internal validation set. 175 pictures from the independent NHGRP cohort were used as the external validation set. The detailed data distribution was shown in Supplementary Table 1. A total of 199 malignant pathological pictures with intact follow-up and clinicopathological information from the RHWU cohort and 440 from the TCGA cohort participated in the construction of the prognostic model and then randomly spilt into training set ( N = 443) and internal validation set ( N = 196) at a ratio of 70: 30. 91 GC digital pathological pictures with the required information from NHGRP were included in the external validation set. exhibits the baseline characteristics of the pictures used in MIL-GC. It is worth noting that the OS time of the TCGA cohort was significantly lower than that of the RHWU cohort (median of 13.8 months vs. 43 months, P < 0.0001, Kruskal-Wallis nonparametric test) (Bonferroni-adjusted significance threshold P’ < 0.017) and NHGRP cohort (median of 13.8 months vs. 44 months, P < 0.0001, Kruskal-Wallis nonparametric test) (Bonferroni-adjusted significance threshold P’ < 0.017) (Supplementary Fig. 1a). Differences between the RHWU cohort (median 43 months) and NHGRP cohort (median 44 months) were not statistically significant ( P = 0.075, Kruskal-Wallis nonparametric test) (Bonferroni-adjusted significance threshold P’ < 0.017). Since pictures in the TCGA cohort were collected from different medical centres, the distribution of their OS time was much more heterogeneous. To better adapt our models to the heterogeneity caused by patients from different sources and to improve the generalizability of the developed models, we used a mixture of images from the RHWU and TCGA cohort together as the training and internal validation sets. The independent NHGRP cohort of images was used as the external validation set. The OS time of the external validation set (median 44 months) was significantly higher compared with the training set (median 20.2 months, P < 0.0001, Kruskal-Wallis nonparametric test) (Bonferroni-adjusted significance threshold P’ < 0.017) and the internal validation set (median 22.4 months, P < 0.0001, Kruskal-Wallis nonparametric test) (Bonferroni-adjusted significance threshold P’ < 0.017) (Supplementary Fig. 1b). Performance of the Diagnostic Model In the diagnostic model, GastroMIL, all 3221 pictures after data augmentation were mixed and then randomly split into the training set and the internal validation set at a ratio of 7: 3. As shown in , ROC curves and AUCs represented the ability to discriminate malignant pathological images of the GastroMIL model when pictures were at 5 ×, 10 × and 20 × magnification. The accuracy (Acc), sensitivity (Sen), and specificity (Spe) of each magnification in the training ( d) and internal validation ( h) sets are shown in a. In the training set, the AUCs achieved 1.000 at three different magnifications. The differences of Acc between the three groups was statistically significant ( P = 0.003, Chi-square test) (significance threshold P < 0.05). The group of 10 × magnification (Acc = 1.000) outperformed that of 20 × (Acc = 0.996) ( P = 0.004, Chi-square test) (Bonferroni-adjusted significance threshold P’ < 0.017). There was no statistically significant difference in Acc between the groups of 5 × and 10 × (0.999 vs. 1.000, P = 0.250, Chi-square test) (Bonferroni-adjusted significance threshold P’ < 0.017) and between the groups of 5 × and 20 × (0.999 vs. 0.996, P = 0.109, Chi-square test) (Bonferroni-adjusted significance threshold P’ < 0.017). In the internal validation set, the AUC achieved 0.995 when pictures were magnified 10 times. The AUCs were also very close to it when images were magnified 5 times (AUC = 0.995) and 20 times (AUC = 0.994). The differences in Acc among the three groups of different magnifications (0.976, 0.976, and 0.979) were not statistically significant ( P = 0.870, Chi-square test) (Bonferroni-adjusted significance threshold P’ < 0.017). It can be seen that our GastroMIL model achieved excellent diagnostic ability for the differentiation of malignant and normal gastric pathological pictures, and the generalization performance was excellent for images at these three magnifications. The diagnosis prediction by the GastroMIL model was based on the classification probability output of all tiles, which can be used to visualize the localization of highly suspected lesions on positive sections. That is, tiles predicted positive could show chromatic aberration, and through appropriate strides, suspected areas would overlap many times, colour of which thus became warmer and darker than other areas. The warmer the colour, the higher the probability that GastroMIL predicted malignant in this area. b showed how heat maps generated by GastroMIL. Heat maps of the RHWU  and TCGA (Supplementary Fig. 2) cohorts could almost accurately outline the area where the tumour was located, regardless of different cohorts or pathological TNM stage, indicating excellent generalization performance of GastroMIL. Performance of the prognostic models In the process of outcome prediction, 639 malignant images from RHWU and TCGA cohorts were mixed and then randomly divided into the training set and the internal validation set at a 7:3 ratio. Considering that the discriminatory power of the GastroMIL model for different magnification images was basically identical to each other, we chose 10 × images to be applied in the prognosis model. The MIL-GC model performed well in both the training set and the internal validation set, with C-index of 0.728 and 0.671, respectively. Prognostic model assigned risk score to each picture, and we divided the GC patients into high-risk and low-risk score groups. We used the median value of risk score in the training set as the threshold for stratifying patients. Then we adopted Kaplan-Meier plots and univariate and multivariable Cox models to assess the association between risk score and prognosis among patients with GC. In the training set, the MIL-GC classifier was a strong predictor of survival in the univariate analysis (HR = 4.209, P < 0.0001, Cox analyse; Supplementary Table 2 and Supplementary Fig. 3). The classifier remained strong in multivariable analysis (HR = 3.549, P < 0.0001, Cox analyse; Supplementary Table 2) after adjusting for significant prognostic indexes in univariable analyses: age, pT stage, pN stage, pM stage and pTNM stage. In the internal validation set, our model stratified the population accurately based on univariate analysis (HR = 3.249, P < 0.0001, Cox analyse; a and c). The MIL-GC classifier predicted survival even after stratification for other features (such as age, histologic grade, pT grade, pN grade and pTNM grade; ). The risk score computed by MIL-GC was of independent prognostic value (HR = 2.976, P < 0.0001, Cox analyse; b). The results showed that the prognostic model based on CNN was equipped to predict OS of GC and might provide a basis for the choice of treatment. Independent external validation of developed models Figures from the independent NHGRP cohort were employed as the external validation set for the diagnosis prediction model, GastroMIL and outcome prediction model, MIL-GC. The magnification of the original images is 20 × (3900*3900 pixels), and we pre-processed them into 10 × magnification. The GastroMIL model showed good performance in identifying malignant pathological images on the external validation set (AUC = 0.978, a). Heat maps of the independent external validation set were displayed in Supplementary Fig. 4. The C-index of MIL-GC in the external validation set was 0.657. The MIL-GC classifier was a strong predictor of OS in the univariate analysis (HR = 2.414, P < 0.0001, Cox analyse; b and c). The MIL-GC classifier predicted survival among the various subgroups (such as age > 60, tumour size ≤ 5, histologic grade 3, pT stage 3, pN stage 0 and 3, pM stage 0, pTNM stage II and pTNM stage III; ). After adjusting for significant prognostic indexes in univariable analyses: histologic grade, pT stage, pN stage, pM stage and pTNM stage, the risk score output by MIL-GC remained strong in multivariable analysis (HR = 1.803, P = 0.043, Cox analyse; d). Good diagnostic and prognostic prediction performance demonstrated on the external validation set, indicating good robustness of the two designed models. Comparing diagnostic performance with human pathologists To explore how the diagnostic performance of our model compared to that of human pathologists, we employed three expert pathologists D, E, and F who were chief or associate chief pathologists and one junior pathologist G who was under training to diagnose images in the external validation set. Human pathologists were blind for patients’ information before examination. The accuracy, sensitivity, and specificity of manual diagnosis were exhibited in Table 2c. The performance of our GastroMIL model (Accuracy = 0.920) was significantly better than the junior pathologist G (Accuracy = 0.874) ( P < 0.0001, paired chi‐square test). There was no significantly difference when our model compared to expert pathologist D (Accuracy = 0.971) ( P > 0.05, paired chi‐square test), expert pathologist E (Accuracy = 0.983) ( P > 0.05, paired chi‐square test), and expert pathologist F (Accuracy = 0.983) ( P > 0.05, paired chi‐square test), respectively. And the diagnostic model achieved substantial interobserver agreement with the expert pathologists ( kappa = 0.805, 0.806, and 0.806, respectively). Moreover, we designed an online website ( https://baigao.github.io/Pathologic-Prognostic-Analysis/ ) to make the process of prediction more available and much easier for users without AI knowledge. The detail process of prediction is seen in Supplementary Fig. 5. Analysis of representative predictive tiles Our models predicted diagnosis and outcome of GC patients from the 32 and 128 most suspicious tiles automatically gained from the input HE-stained pathological pictures, respectively. We extracted these suspicious tiles and had them reviewed by expert pathologists A and B. Here we displayed some representative predictive tiles with interpretation by pathological experts . These tiles were of obvious tumour heterogeneity, including necrosis, nerve invasion, signet ring cell, intravasated cancer cells, muscularis propria invasion, and mucous secretion, hiding significant diagnostic and prognostic information. These suspicious tiles provide a preliminary indication that our model could automatically identify regions of pathological significance and classify GC pathology images based on these regions. Further details on the analysis of deep learning, which has been traditionally treated as a black box, deserve our further study in the future.   A total of 871 GC patients were initially screened from the RHWU cohort, and 588 with tumour tissue blocks were eligible for the study. There were 449 GC patients with digital H&E-stained pathological images were eligible for this study in the TCGA cohort and 91 in the NHGRP cohort. A total of 1276 images from the RHWU cohort and 1057 images from the TCGA cohort were obtained for the development of the GastroMIL model. Through data augmentation, 3221 pictures (malignant: normal = 1574: 1647) were finally enrolled in the GastroMIL model and 70% ( N = 2261) were randomly assigned to the training set while the remaining 30% ( N = 960) were included in the internal validation set. 175 pictures from the independent NHGRP cohort were used as the external validation set. The detailed data distribution was shown in Supplementary Table 1. A total of 199 malignant pathological pictures with intact follow-up and clinicopathological information from the RHWU cohort and 440 from the TCGA cohort participated in the construction of the prognostic model and then randomly spilt into training set ( N = 443) and internal validation set ( N = 196) at a ratio of 70: 30. 91 GC digital pathological pictures with the required information from NHGRP were included in the external validation set. exhibits the baseline characteristics of the pictures used in MIL-GC. It is worth noting that the OS time of the TCGA cohort was significantly lower than that of the RHWU cohort (median of 13.8 months vs. 43 months, P < 0.0001, Kruskal-Wallis nonparametric test) (Bonferroni-adjusted significance threshold P’ < 0.017) and NHGRP cohort (median of 13.8 months vs. 44 months, P < 0.0001, Kruskal-Wallis nonparametric test) (Bonferroni-adjusted significance threshold P’ < 0.017) (Supplementary Fig. 1a). Differences between the RHWU cohort (median 43 months) and NHGRP cohort (median 44 months) were not statistically significant ( P = 0.075, Kruskal-Wallis nonparametric test) (Bonferroni-adjusted significance threshold P’ < 0.017). Since pictures in the TCGA cohort were collected from different medical centres, the distribution of their OS time was much more heterogeneous. To better adapt our models to the heterogeneity caused by patients from different sources and to improve the generalizability of the developed models, we used a mixture of images from the RHWU and TCGA cohort together as the training and internal validation sets. The independent NHGRP cohort of images was used as the external validation set. The OS time of the external validation set (median 44 months) was significantly higher compared with the training set (median 20.2 months, P < 0.0001, Kruskal-Wallis nonparametric test) (Bonferroni-adjusted significance threshold P’ < 0.017) and the internal validation set (median 22.4 months, P < 0.0001, Kruskal-Wallis nonparametric test) (Bonferroni-adjusted significance threshold P’ < 0.017) (Supplementary Fig. 1b).   In the diagnostic model, GastroMIL, all 3221 pictures after data augmentation were mixed and then randomly split into the training set and the internal validation set at a ratio of 7: 3. As shown in , ROC curves and AUCs represented the ability to discriminate malignant pathological images of the GastroMIL model when pictures were at 5 ×, 10 × and 20 × magnification. The accuracy (Acc), sensitivity (Sen), and specificity (Spe) of each magnification in the training ( d) and internal validation ( h) sets are shown in a. In the training set, the AUCs achieved 1.000 at three different magnifications. The differences of Acc between the three groups was statistically significant ( P = 0.003, Chi-square test) (significance threshold P < 0.05). The group of 10 × magnification (Acc = 1.000) outperformed that of 20 × (Acc = 0.996) ( P = 0.004, Chi-square test) (Bonferroni-adjusted significance threshold P’ < 0.017). There was no statistically significant difference in Acc between the groups of 5 × and 10 × (0.999 vs. 1.000, P = 0.250, Chi-square test) (Bonferroni-adjusted significance threshold P’ < 0.017) and between the groups of 5 × and 20 × (0.999 vs. 0.996, P = 0.109, Chi-square test) (Bonferroni-adjusted significance threshold P’ < 0.017). In the internal validation set, the AUC achieved 0.995 when pictures were magnified 10 times. The AUCs were also very close to it when images were magnified 5 times (AUC = 0.995) and 20 times (AUC = 0.994). The differences in Acc among the three groups of different magnifications (0.976, 0.976, and 0.979) were not statistically significant ( P = 0.870, Chi-square test) (Bonferroni-adjusted significance threshold P’ < 0.017). It can be seen that our GastroMIL model achieved excellent diagnostic ability for the differentiation of malignant and normal gastric pathological pictures, and the generalization performance was excellent for images at these three magnifications. The diagnosis prediction by the GastroMIL model was based on the classification probability output of all tiles, which can be used to visualize the localization of highly suspected lesions on positive sections. That is, tiles predicted positive could show chromatic aberration, and through appropriate strides, suspected areas would overlap many times, colour of which thus became warmer and darker than other areas. The warmer the colour, the higher the probability that GastroMIL predicted malignant in this area. b showed how heat maps generated by GastroMIL. Heat maps of the RHWU  and TCGA (Supplementary Fig. 2) cohorts could almost accurately outline the area where the tumour was located, regardless of different cohorts or pathological TNM stage, indicating excellent generalization performance of GastroMIL.   In the process of outcome prediction, 639 malignant images from RHWU and TCGA cohorts were mixed and then randomly divided into the training set and the internal validation set at a 7:3 ratio. Considering that the discriminatory power of the GastroMIL model for different magnification images was basically identical to each other, we chose 10 × images to be applied in the prognosis model. The MIL-GC model performed well in both the training set and the internal validation set, with C-index of 0.728 and 0.671, respectively. Prognostic model assigned risk score to each picture, and we divided the GC patients into high-risk and low-risk score groups. We used the median value of risk score in the training set as the threshold for stratifying patients. Then we adopted Kaplan-Meier plots and univariate and multivariable Cox models to assess the association between risk score and prognosis among patients with GC. In the training set, the MIL-GC classifier was a strong predictor of survival in the univariate analysis (HR = 4.209, P < 0.0001, Cox analyse; Supplementary Table 2 and Supplementary Fig. 3). The classifier remained strong in multivariable analysis (HR = 3.549, P < 0.0001, Cox analyse; Supplementary Table 2) after adjusting for significant prognostic indexes in univariable analyses: age, pT stage, pN stage, pM stage and pTNM stage. In the internal validation set, our model stratified the population accurately based on univariate analysis (HR = 3.249, P < 0.0001, Cox analyse; a and c). The MIL-GC classifier predicted survival even after stratification for other features (such as age, histologic grade, pT grade, pN grade and pTNM grade; ). The risk score computed by MIL-GC was of independent prognostic value (HR = 2.976, P < 0.0001, Cox analyse; b). The results showed that the prognostic model based on CNN was equipped to predict OS of GC and might provide a basis for the choice of treatment.   Figures from the independent NHGRP cohort were employed as the external validation set for the diagnosis prediction model, GastroMIL and outcome prediction model, MIL-GC. The magnification of the original images is 20 × (3900*3900 pixels), and we pre-processed them into 10 × magnification. The GastroMIL model showed good performance in identifying malignant pathological images on the external validation set (AUC = 0.978, a). Heat maps of the independent external validation set were displayed in Supplementary Fig. 4. The C-index of MIL-GC in the external validation set was 0.657. The MIL-GC classifier was a strong predictor of OS in the univariate analysis (HR = 2.414, P < 0.0001, Cox analyse; b and c). The MIL-GC classifier predicted survival among the various subgroups (such as age > 60, tumour size ≤ 5, histologic grade 3, pT stage 3, pN stage 0 and 3, pM stage 0, pTNM stage II and pTNM stage III; ). After adjusting for significant prognostic indexes in univariable analyses: histologic grade, pT stage, pN stage, pM stage and pTNM stage, the risk score output by MIL-GC remained strong in multivariable analysis (HR = 1.803, P = 0.043, Cox analyse; d). Good diagnostic and prognostic prediction performance demonstrated on the external validation set, indicating good robustness of the two designed models.   To explore how the diagnostic performance of our model compared to that of human pathologists, we employed three expert pathologists D, E, and F who were chief or associate chief pathologists and one junior pathologist G who was under training to diagnose images in the external validation set. Human pathologists were blind for patients’ information before examination. The accuracy, sensitivity, and specificity of manual diagnosis were exhibited in Table 2c. The performance of our GastroMIL model (Accuracy = 0.920) was significantly better than the junior pathologist G (Accuracy = 0.874) ( P < 0.0001, paired chi‐square test). There was no significantly difference when our model compared to expert pathologist D (Accuracy = 0.971) ( P > 0.05, paired chi‐square test), expert pathologist E (Accuracy = 0.983) ( P > 0.05, paired chi‐square test), and expert pathologist F (Accuracy = 0.983) ( P > 0.05, paired chi‐square test), respectively. And the diagnostic model achieved substantial interobserver agreement with the expert pathologists ( kappa = 0.805, 0.806, and 0.806, respectively). Moreover, we designed an online website ( https://baigao.github.io/Pathologic-Prognostic-Analysis/ ) to make the process of prediction more available and much easier for users without AI knowledge. The detail process of prediction is seen in Supplementary Fig. 5.   Our models predicted diagnosis and outcome of GC patients from the 32 and 128 most suspicious tiles automatically gained from the input HE-stained pathological pictures, respectively. We extracted these suspicious tiles and had them reviewed by expert pathologists A and B. Here we displayed some representative predictive tiles with interpretation by pathological experts . These tiles were of obvious tumour heterogeneity, including necrosis, nerve invasion, signet ring cell, intravasated cancer cells, muscularis propria invasion, and mucous secretion, hiding significant diagnostic and prognostic information. These suspicious tiles provide a preliminary indication that our model could automatically identify regions of pathological significance and classify GC pathology images based on these regions. Further details on the analysis of deep learning, which has been traditionally treated as a black box, deserve our further study in the future.   In this study, we designed a CNN-based model, Gastro-MIL, for the accurate diagnosis of GC directly from digital H&E-stained pictures. Encouragingly, this diagnosis model achieved excellent performance in differentiating GC from normal tissues in the training and internal validation sets (AUC nearly 1.000). Moreover, we have successfully employed deep learning to automatically predict OS in patients with GC with C-index of 0.728 and 0.671 in the training and internal validation sets. The predictive models can be adopted to help clinicians select the appropriate adjuvant therapy following surgery, by identifying patients at high risk who would benefit from intensive regimens as well as patients at low risk who might be cured through surgery alone. And we also used an independent external validation set, and the two models showed good diagnostic (AUC = 0.978) and prognostic (C-index = 0.657) prediction performance, indicating good robustness of the two designed models. Moreover, the risk score computed by MIL-GC was proved to be of independent prognostic value of GC by univariate and multivariable Cox analyse. In the comparison with human pathologists, our diagnostic model GastroMIL outperformed the junior pathologists and demonstrated a high degree of consistence with expert pathologists ( kappa > 0.8). More importantly, we further constructed the first webpage ( https://baigao.github.io/Pathologic-Prognostic-Analysis/ ) for the automatic diagnosis of GC and survival prediction. In recent years, deep learning, such as CNN, has attracted much attention and has achieved particular success in computer vision tasks. In our previous study, we developed an AI model to distinguish abnormal images from normal images in small bowel capsule endoscopy, and it was validated to exceed human performance . In this study, we adopted CNN to analyse digital H&E-stained GC pathological images. Song et al. reported deep learning model for GC detection by analysing histopathological images with validation in multicentre sample. They reached good performance and developed the system for pathologists to use the proposed model. However, they applied a large number of pixel-level manual annotations to train the model, which consumed a lot of time and effort of pathologists. The need for extensive manual annotation was also seen in the studies using AI for GC and bladder pathological diagnosis, different from the models proposed in our study. Due to the adoption of a weakly supervised model (specifical MIL) in our study, the only label we needed for training was the reported diagnoses made by pathologists in the course of their daily work, eliminating large manually annotated tasks that used to hinder the development and clinical practice of AI in pathology. And the system Song et al. have developed may be too expensive (Small hospital: $84, 000-$87, 000; Large hospital: $161, 000-$164, 000) for economically underdeveloped areas with a shortage of pathologists, limiting its promotion in primary hospitals to a certain extent. We designed a website based on our analysis, simple and easy to use, and all the users need is a computer with an Internet connection or even an Internet-connected phone or tablet. When a histological image is uploaded without any professional annotation, the webpage will show a brief result of the primary type and survival prediction. The website identifies suspicious areas, thus improving diagnostic accuracy in a limited amount time, which will prove particularly useful in areas with a shortage of pathologists and in improving the diagnosis performance of junior pathologists who are under training. There have been a number of AI studies focusing on GC . Most of these previous studies relied on endoscopy, and a small amount of selected medical radiologic technology, such as computed tomography. Moreover, previous studies generally employed a small sample size from a single centre, lacking effective proof to validate the robustness of models. We constructed models on much larger datasets from two different cohorts, and validated on another independent external validation set, greatly enhancing the universality of the diagnostic and survival models. In the meantime, images in the external validation were diagnosed by human pathologists. By comparing the diagnosis performance of our model with that of junior and expert pathologists, the accuracy and reliability of our model was further confirmed. For survival prediction, we designed MIL-GC algorithm in this study. The risk score generated by MIL-GC exhibited a distinguished performance in predicting OS among patients with GC, as reflected by the C-index of 0.728, 0.671, and 0.657 in the training, internal validation and external validation sets, respectively. Furthermore, we applied Cox regression analysis to determine whether the risk score generated by MIL-GC was an independent biomarker for the prediction of OS in GC patients. Fortunately, the risk score generated by MIL-GC remained strong in multivariate regression (HR = 2.976, P < 0.0001 in the internal validation set, and HR = 1.803, P = 0.043 in the external validation set) after the adjustment for established prognostic features, indicating that the risk score generated by MIL-GC will be a promising supplement to the established markers and help refine risk stratification among GC patients. A recent study predicting the outcome of GC from resected lymph node histopathology images also yielded meaningful results. Our study focused on the pathological histological features from the stomach tissue, while their study concentrated on the lymph node metastasis of GC. Both of these two studies able to make predictions about the prognosis of patients with GC. If the key points of the two researches could be combined in the future, we may achieve a more satisfactory performance in predicting GC patients’ prognosis. Furthermore, our webpage could conveniently provide predictions of patient prognosis, serving as an important reference for selection of adjuvant therapy after surgery in patients with GC. There are some limitations to our study. First, the survival time of GC individuals from the TGCA cohort was different from that in the RHWU cohort due to the progress of treatment. Therefore, it is not appropriate for us to use the TCGA or RHWU cohort as the training set and the other as the validation set. Hence, we mixed them together and randomly split them into the training or internal validation set. Furthermore, datasets we collected in the RHWU, TCGA and NHGRP cohorts were retrospective and thus suffered from inherent biases. In the future, we plan to conduct a prospective, randomized, multicentre clinical trial to validate the performance of precisely diagnosing GC and stratifying patients into high-risk and low-risk score groups to assist in selecting the suitable individualized adjuvant treatment regiments. In conclusion, we developed deep learning models to diagnose GC and predict the survival outcomes of GC patients by analyzing H&E-stained pathological images. To make our models more intuitive and easier to use, an online website ( https://baigao.github.io/Pathologic-Prognostic-Analysis/ ) based on developed algorithms was designed. Our models assist oncologists in the identification of GC and selection of appropriate treatment, thus reducing the physical and economic burdens of patients.   W.D. was associated with Conceptualization, Funding acquisition, Resources, and Supervision of the study. B.H., S.T., N.Z., J.M., Y.L., P.H., B.D., and J.H. conducted Data curation. Z.H., C.Z., H.Z., and F.M. took charge of Formal analysis, Methodology and Software. B.H., S.T., N.Z., and J.M. performed the Investigation and Project administration. S.T., B.H., Z.H., C.Z., H.Z., and F.M. completed the Validation and Visualization. B.H. and S.T. completed Writing – original draft. W.D., B.H., S.T., F.L., M.J., and J.Z. conducted Writing – review & editing. All authors verified the underlying data and reviewed and approved the final manuscript.   All authors have no conflicts of interest to disclose.   