The temperature field within porous media is considerably affected by different boundary conditions, and effective thermal conductivity varies with spatial structure morphologies. At present, traditional prediction methods for the temperature field are expensive and time consuming, particularly for large structures and dimensions, whereas deep learning surrogate models have limitations related to constant boundary conditions and two-dimensional input slices, lacking the three-dimensional topology and spatial correlations. Herein, a constraint-incorporated model using U-Net architecture as the backbone is proposed to predict the temperature field and effective thermal conductivity of sphere-packed porous media, considering diverse external heat fluxes. A total of 510 original samples of temperature fields are generated through lattice Boltzmann method (LBM) simulations, which are further augmented to 33,150 samples using the self-amplification method for the training. Physical prior knowledge is incorporated into the model to constrain the training direction by adding physical constraint terms as well as adaptive weights to the loss function. Input vectors with different heat fluxes and porosities are embedded into latent features for predicting different boundary conditions. Results indicate that the constraint-incorporated model has a mean relative error ranging between 1.1 % and 5.7 % compared with the LBM results in the testing set. It exhibits weak dependence on the database size and substantially reduces computational time, with a maximum speedup ratio of 7.14 × 106. This study presents a deep learning model with physical constraints for predicting heat conduction in porous media, alleviating the burden of extensive experiments and simulations.