The pre-operative non-invasive differential diagnosis of hepatocellular carcinoma (HCC) and intrahepatic cholangiocarcinoma (ICC) mainly depends on imaging. However, the accuracy of conventional imaging and radiomics methods in differentiating between the two carcinomas is unsatisfactory. In this study, we aimed to establish a novel deep learning model based on computed tomography (CT) images to provide an effective and non-invasive pre-operative differential diagnosis method for HCC and ICC. We retrospectively investigated the CT images of 395 HCC patients and 99 ICC patients who were diagnosed based on pathological analysis. To differentiate between HCC and ICC we developed a deep learning model called CSAM-Net based on channel and spatial attention mechanisms. We compared the proposed CSAM-Net with conventional radiomic models such as conventional logistic regression, least absolute shrinkage and selection operator regression, support vector machine, and random forest models. With respect to differentiating between HCC and ICC, the CSAM-Net model showed area under the receiver operating characteristic curve (AUC) values of 0.987 (accuracy = 0.939), 0.969 (accuracy = 0.914), and 0.959 (accuracy = 0.912) for the training, validation, and test sets, respectively, which were significantly higher than those of the conventional radiomics models (0.736-0.913 [accuracy = 0.735-0.912], 0.602-0.828 [accuracy = 0.647-0.818], and 0.638-0.845 [accuracy = 0.618-0.849], respectively. The decision curve analysis showed a high net benefit of the CSAM-Net model, which suggests potential efficacy in differentiating between HCC and ICC in the diagnosis of liver cancers. The proposed CSAM-Net model based on channel and spatial attention mechanisms provides an effective and non-invasive tool for the differential diagnosis of HCC and ICC on CT images, and has potential applications in diagnosis of liver cancers.