我有大约5种模式,它们各自训练得很好,但我想把它们融合在一起,以便有一个大型号。我正在研究它,因为一个大模型比许多小模型更容易更新(在生产中)--这是我想要实现的目标。
我的问题是,这样做可以吗?有一个人头模型的数据集,我该如何训练整个模型?
发布于 2019-11-24 00:16:47
我的问题是,这样做可以吗?
你当然能做到。这种方法称为多任务学习。取决于您的数据集和您想要做的事情,它甚至可能会提高性能。微软使用多任务模型来实现NLP基准测试的一些好结果,但他们也指出,通过细化每个单独任务的联合模型,可以进一步提高性能。
有一个人头模型的数据集,我该如何训练整个模型?
你所需要的只是火把ModuleList
#please note this is just pseudocode and I'm not well versed with computer vision
#therefore you need to check if resnet50 import is correct and look
#for the imports of the task specific stuff
from torch import nn
from torchvision.models import resnet50
class MultiTaskModel(nn.Module):
def __init__(self):
#shared part
self.resnet50 = resnet50()
#task specific stuff
self.tasks = nn.ModuleList()
self.tasks.add_module('depth', Depth())
self.tasks.add_module('denseflow', Denseflow())
#...
def forward(self, tasktag, ...):
#shared part
resnet_output = self.resnet50(...)
#task specific parts
if tasktag == 'depth':
return self.tasks.depth(resnet_output)
elif tasktag == 'denseflow':
return self.tasks.denseflow(resnet_output)
#...
发布于 2019-11-20 11:04:26
https://stackoverflow.com/questions/58950272
复制相似问题