How to convert output of each hidden layer to local binary pattern (LBP) and feed it to next layer's input in pytorch

Hi
I want to convert output of each hidden layer to local binary pattern (LBP) and feed it to next layer’s input in PyTorch,
In the other word I want to classify my input images (RGB or LBP) via extract the features in each layer in ResNet18!

Thanks.