How Can Torchaudio.transform.resample Be Called Without __call__ Function Inside?
if sample_rate != sr: waveform = torchaudio.transforms.Resample(sample_rate, sr)(waveform) sample_rate = sr I was wondering how this Resamle works in there. So too
Solution 1:
Here's simple similar demonstrates of how forward
function works in PyTorch
.
Check this:
from typing importCallable, Anyclassparent:
def_unimplemented_forward(self, *input):
raise NotImplementedError
def_call_impl(self, *args):
# original nn.Module _call_impl function contains lot more code# to handle exceptions, to handle hooks and for other purposes
self.forward(*args)
forward : Callable[..., Any] = _unimplemented_forward
__call__ : Callable[..., Any] = _call_impl
classchild(parent):
defforward(self, *args):
print('forward function')
classchild_2(parent):
pass
Runtime:
>>> c1 = child_1()
>>> c1()
forward function
>>> c2 = child_2()
>>> c2()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".\callable.py", line 8, in _call_impl
self.forward(*args)
File ".\callable.py", line 5, in _unimplemented_forward
raise NotImplementedError
NotImplementedError
Post a Comment for "How Can Torchaudio.transform.resample Be Called Without __call__ Function Inside?"