Exemplo n.º 1
0
    def test_model(self):
        image_feat_dim = 40
        txt_embedding_dim = 300
        lstm_dim = 512
        hidden_size = 30
        num_of_loc = 5
        batch_size = 16
        num_vocab = 60
        num_ans_candidates = 35
        joint_embedding_dim = 500
        question_len = 13
        batch_first = True
        image_embedding_model = image_embedding(image_feat_dim, lstm_dim, hidden_size)
        question_embedding_model = QuestionEmbeding(
            num_vocab,
            txt_embedding_dim,
            lstm_dim,
            lstm_layer=2,
            dropout=0.1,
            batch_first=batch_first,
        )
        my_classifier = logit_classifier(
            joint_embedding_dim, num_ans_candidates, image_feat_dim, txt_embedding_dim
        )
        loss = torch.nn.CrossEntropyLoss()

        my_model = top_down_bottom_up_model(
            image_embedding_model, question_embedding_model, my_classifier, loss
        )
        image_feat = np.random.rand(batch_size, num_of_loc, image_feat_dim)
        input_txt = Variable(
            torch.rand(batch_size, question_len).type(torch.LongTensor) % num_vocab
        )
        res = my_model(image_feat, input_txt, batch_first)
        self.assertEqual((batch_size, num_ans_candidates), res.shape)
Exemplo n.º 2
0
    def test_classifier_batch_size_1(self):
        batch_size = 1
        joint_embedding_dim = 10
        num_ans_candidates = 20
        text_embeding_dim = 64
        image_embedding_dim = 32

        my_classifier = logit_classifier(joint_embedding_dim,
                                         num_ans_candidates,
                                         image_embedding_dim,
                                         text_embeding_dim)
        joint_embedding = Variable(torch.randn(batch_size,
                                               joint_embedding_dim))
        res = my_classifier(joint_embedding)
        self.assertEqual((1, 20), res.shape)
Exemplo n.º 3
0
    def test_classifier_batch_size_1(self):
        batch_size = 1
        joint_embedding_dim = 10
        num_ans_candidates = 20
        text_embeding_dim = 64
        image_embedding_dim = 32

        my_classifier = logit_classifier(joint_embedding_dim,
                                         num_ans_candidates,
                                         image_embedding_dim,
                                         text_embeding_dim)
        joint_embedding = Variable(torch.randn(batch_size,
                                   joint_embedding_dim))
        res = my_classifier(joint_embedding)
        self.assertEqual((1, 20), res.shape)
Exemplo n.º 4
0
    def test_model(self):
        image_feat_dim = 40
        txt_embedding_dim = 300
        lstm_dim = 512
        hidden_size = 30
        num_of_loc = 5
        batch_size = 16
        num_vocab = 60
        num_ans_candidates = 35
        joint_embedding_dim = 500
        question_len = 13
        batch_first = True
        image_embedding_model = image_embedding(image_feat_dim,
                                                lstm_dim,
                                                hidden_size)
        question_embedding_model = QuestionEmbeding(num_vocab,
                                                    txt_embedding_dim,
                                                    lstm_dim,
                                                    lstm_layer=2,
                                                    dropout=0.1,
                                                    batch_first=batch_first)
        my_classifier = logit_classifier(joint_embedding_dim,
                                         num_ans_candidates,
                                         image_feat_dim,
                                         txt_embedding_dim)
        loss = torch.nn.CrossEntropyLoss()

        my_model = top_down_bottom_up_model(image_embedding_model,
                                            question_embedding_model,
                                            my_classifier, loss)
        image_feat = np.random.rand(batch_size,
                                    num_of_loc,
                                    image_feat_dim)
        input_txt = Variable(torch.rand(batch_size,
                             question_len).type(torch.LongTensor) % num_vocab)
        res = my_model(image_feat, input_txt, batch_first)
        self.assertEqual((batch_size, num_ans_candidates), res.shape)