Spaces:
Runtime error
Runtime error
File size: 1,389 Bytes
128757a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
from collections import OrderedDict
import torch
from torch import nn
from maskrcnn_benchmark.modeling import registry
from . import bert_model
from . import rnn_model
from . import clip_model
from . import word_utils
@registry.LANGUAGE_BACKBONES.register("bert-base-uncased")
def build_bert_backbone(cfg):
body = bert_model.BertEncoder(cfg)
model = nn.Sequential(OrderedDict([("body", body)]))
return model
@registry.LANGUAGE_BACKBONES.register("roberta-base")
def build_bert_backbone(cfg):
body = bert_model.BertEncoder(cfg)
model = nn.Sequential(OrderedDict([("body", body)]))
return model
@registry.LANGUAGE_BACKBONES.register("rnn")
def build_rnn_backbone(cfg):
body = rnn_model.RNNEnoder(cfg)
model = nn.Sequential(OrderedDict([("body", body)]))
return model
@registry.LANGUAGE_BACKBONES.register("clip")
def build_clip_backbone(cfg):
body = clip_model.CLIPTransformer(cfg)
model = nn.Sequential(OrderedDict([("body", body)]))
return model
def build_backbone(cfg):
assert cfg.MODEL.LANGUAGE_BACKBONE.MODEL_TYPE in registry.LANGUAGE_BACKBONES, \
"cfg.MODEL.LANGUAGE_BACKBONE.TYPE: {} is not registered in registry".format(
cfg.MODEL.LANGUAGE_BACKBONE.MODEL_TYPE
)
return registry.LANGUAGE_BACKBONES[cfg.MODEL.LANGUAGE_BACKBONE.MODEL_TYPE](cfg)
|