Thank you for your reply!
Currently I have this function inside a class Recognition:
    def recognition_output(self, input_dir):
        try:
            self.prepare_data(input_dir=input_dir)
        except Exception as e:
            logging.info(f"{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')} failed to prepare data")
            logging.exception(f"{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')} exception caused - {e}")

        with torch.no_grad():
            for image_tensors, image_path_list in self.demo_loader:
                # do something

First I am creating an object of Recognition class and then calling this function from another file.
Can you please tell me where I am supposed (in which file) to put the if-clause protection statement?
Thank you!