Roller compaction is a crucial unit operation in pharmaceutical manufacturing, with its ribbon porosity widely recognised as a critical quality attribute. Terahertz spectroscopy has emerged as a fast and non-destructive technique to measure porosity in pharmaceutical products. From a sensing perspective, the irregular shape and uneven surface of fragmented ribbon pieces can affect the accuracy and precision of the measurements, particularly for techniques that probe only a small sampling volume. It is known that the porosity is not uniform within the ribbon structure, with variations expected across the width of the ribbon and in the microstructure corresponding to its surface texture. However, typical pharmaceutical analysis methods, such as envelope density, only report an average bulk porosity, are slow to operate and limited in accuracy. To address this challenge, we developed and trained convolutional neural network models using THz spectra as input to classify four types of topography typically encountered in ribbons: ridge, valley, flat plane and edge points. The classifiers achieved 91% validation accuracy in both identifying outliers and differentiating between ribbons of smooth and knurled surfaces. For the more challenging task of distinguishing between the ridges and valleys of knurled surfaces, an 81% testing accuracy was achieved. Once each measurement is paired with its topography, resolving the density distribution within the sample is possible. This data can be combined to arrive at an average bulk porosity value compatible with conventional pharmaceutical analysis.