I am trying to create a custom Transform for the following kaggle competition.
The input are actually signals from detectors and the transform which I have created generates spectograms for these signals using nnAudio.
Here is my code for the same →
class NNAudioTransform(Transform): """Custom Transform which uses nnAudio transforms to extract spectogram on the fly""" def __init__(self, df, x_col:str, y_col: str): self.df = df self.x_col = x_col self.y_col = y_col def encodes(self, img_path): label = self.df[self.df[self.x_col] == img_path][self.y_col].values img = qtfms(img_path) #img = img.squeeze().numpy() return NNAudioImage(img, label)
Here is the notebook describing what i have done and the support functions (show method etc.) which I have created.
My transform is working good and I can successfully train the model on the data. However, the thing which I can’t figure out is that how to use this same transform during inference. The transform in the current state would output a tuple of the transformed image and the label but during inference I won’t have a label for the transformed (test) image.
How should I modify my transform so that the same can be used during training as well as during inference ?
On of the way that I can think of is to refactor my transform so that it only returns a tuple with just the image and not the label but then how would I pass the corresponding labels for the transformed image during training time?