Abstract Piezoelectric transducer based electro-mechanical impedance technology is an effective and reliable detection method for bolt structure loosening under external load. However, temperature change usually causes some non-loosening factors to change the impedance spectrum of bolt structure. In order to reduce the misjudgment of loosening damage caused by temperature change, it is necessary to construct a temperature compensation model for impedance spectrum. In this paper, the convolutional structure in U-net and Transformer are effectively combined to form a TransUnet deep neural network structure suitable for input and output of one-dimensional data. Using impedance data between 10 °C and 50 °C and temperature as input to the network. After convolution operation, the convolutional block attention module is embedded in the U-net to optimize the encoder transmission characteristics and enhance the performance of the skip connection in the traditional U-shaped structure. The temperature compensation rate (TCR) is defined to measure the effect of temperature compensation. Then the lightweight convolutional neural network structure is used to recognize the bolt loosening damage of the compensated impedance signal. The generalization ability of the TransUnet was tested using impedance data that is not in the training dataset. The results show that the TransUnet proposed in the paper can realize the temperature compensation of multi-peak impedance signals. The TCR and recognition accuracy of bolt loose damage reaches reach 0.003 and 95.7%, respectively, which is 11% higher than that without temperature compensation. At 60 °C, the TCR and the identification accuracy of loosening damage can still reach 0.0055 and 90.2%, respectively, which show that the TransUnet has strong generalization ability.