我创建了两个类:
class Preprocess(): def __init ..... def forward ....class Model (): def __init ..... def forward
我想在将数据传入Model之前先进行Preprocess处理。您能告诉我如何实现吗?
回答:
也可以使用torch.nn.Sequential
,它的优点包括:
- 更易于阅读
- 只需传递
inputs
,无需记住先调用Preprocess
代码如下:
model = torch.nn.Sequential(Preprocess(), Model())