Ejemplo n.º 1
0
    def _init_feature_embeddings(self, attr):
        feature_embeddings_list = []
        num_feature_feat = len(
            getattr(self.config, "{}_feature_encodings".format(attr)))

        self.feature_embeddings_out_dim = 0

        for _ in range(num_feature_feat):
            feature_embeddings = []
            feature_attn_model_list = self.config[attr + "_feature_embeddings"]

            for feature_attn_model_params in feature_attn_model_list:
                feature_embedding = ImageFeatureEmbedding(
                    getattr(self, attr + "_feature_dim"),
                    self.text_embeddings_out_dim, **feature_attn_model_params)
                feature_embeddings.append(feature_embedding)
                self.feature_embeddings_out_dim += feature_embedding.out_dim

            feature_embeddings = nn.ModuleList(feature_embeddings)
            feature_embeddings_list.append(feature_embeddings)

        self.feature_embeddings_out_dim *= getattr(self, attr + "_feature_dim")

        setattr(self, attr + "_feature_embeddings_out_dim",
                self.feature_embeddings_out_dim)
        del self.feature_embeddings_out_dim
        setattr(
            self,
            attr + "_feature_embeddings_list",
            nn.ModuleList(feature_embeddings_list),
        )
Ejemplo n.º 2
0
    def _init_feature_embeddings(self, attr):
        feature_embeddings_list = []
        num_feature_feat = len(
            getattr(self.config, f"{attr}_feature_encodings"))

        # print("num_feature_feat", num_feature_feat)
        # print(getattr(self.config, f"{attr}_feature_encodings"))
        # [{'type': 'finetune_faster_rcnn_fpn_fc7', 'params': {'bias_file': 'models/detectron.defaults/fc7_b.pkl', 'weights_file': 'models/detectron.defaults/fc7_w.pkl', 'model_data_dir': '/media/ubuntu/MyDisk/data_mmf/vg'}}, {'type': 'default', 'params': {'model_data_dir': '/media/ubuntu/MyDisk/data_mmf/vg'}}]

        self.feature_embeddings_out_dim = 0

        for _ in range(num_feature_feat):  #2
            feature_embeddings = []
            feature_attn_model_list = self.config[attr + "_feature_embeddings"]

            # print ("feature_attn_model_list", feature_attn_model_list)
            # # [{'modal_combine': {'type': 'non_linear_element_multiply', 'params': {'dropout': 0, 'hidden_dim': 5000}}, 'normalization': 'softmax', 'transform': {'type': 'linear', 'params': {'out_dim': 1}}}]
            # print("attr_feat_dim", getattr(self, attr + "_feature_dim")) #2048
            # print("text_embeddings_out_dim", self.text_embeddings_out_dim) # 2048

            for feature_attn_model_params in feature_attn_model_list:
                feature_embedding = ImageFeatureEmbedding(
                    getattr(self, attr + "_feature_dim"),  #2048
                    self.text_embeddings_out_dim,
                    **feature_attn_model_params,
                )
                # print ("feature_embedding", feature_embedding) #a embedding model
                feature_embeddings.append(feature_embedding)
                self.feature_embeddings_out_dim += feature_embedding.out_dim

            feature_embeddings = nn.ModuleList(feature_embeddings)
            feature_embeddings_list.append(feature_embeddings)

        self.feature_embeddings_out_dim *= getattr(self, attr + "_feature_dim")

        setattr(self, attr + "_feature_embeddings_out_dim",
                self.feature_embeddings_out_dim)
        del self.feature_embeddings_out_dim
        setattr(
            self,
            attr + "_feature_embeddings_list",
            nn.ModuleList(feature_embeddings_list),
        )