CPG
CPG copied to clipboard
get predictions for all tasks in single forward pass
Hi!
Is it possible to use model trained on 4 facial-informatic tasks in a way that it can produce predictions for all tasks in single forward pass?
Something like in the following code:
class SphereNetMT(SphereNet):
""" Multi-task version of SphereNet, returns predictions for all classifiers in single forward pass
"""
def forward(self, x, tasks=['gender', 'emotion', 'age0']):
x = self.relu1_1(self.conv1_1(x))
x = x + self.relu1_3(self.conv1_3(self.relu1_2(self.conv1_2(x))))
x = self.relu2_1(self.conv2_1(x))
x = x + self.relu2_3(self.conv2_3(self.relu2_2(self.conv2_2(x))))
x = x + self.relu2_5(self.conv2_5(self.relu2_4(self.conv2_4(x))))
x = self.relu3_1(self.conv3_1(x))
x = x + self.relu3_3(self.conv3_3(self.relu3_2(self.conv3_2(x))))
x = x + self.relu3_5(self.conv3_5(self.relu3_4(self.conv3_4(x))))
x = x + self.relu3_7(self.conv3_7(self.relu3_6(self.conv3_6(x))))
x = x + self.relu3_9(self.conv3_9(self.relu3_8(self.conv3_8(x))))
x = self.relu4_1(self.conv4_1(x))
x = x + self.relu4_3(self.conv4_3(self.relu4_2(self.conv4_2(x))))
x = self.flatten(x)
predictions = {}
for i, task in enumerate(tasks):
predictions[task] = self.classifiers[self.datasets.index(task)](x)
return predictions