layer-by-layer inference