Ejemplo n.º 1
0
    def forward(self, data_shot, data_query):
        proto = self.encoder(data_shot)
        if self.args.hyperbolic:
            proto = self.e2p(proto)

            if self.training:
                proto = proto.reshape(self.args.shot, self.args.way, -1)
            else:
                proto = proto.reshape(self.args.shot, self.args.validation_way,
                                      -1)

            proto = poincare_mean(proto, dim=0, c=self.e2p.c)
            data_query = self.e2p(self.encoder(data_query))
            logits = -dist_matrix(data_query, proto,
                                  c=self.e2p.c) / self.args.temperature

        else:
            if self.training:
                proto = proto.reshape(self.args.shot, self.args.way,
                                      -1).mean(dim=0)
            else:
                proto = proto.reshape(self.args.shot, self.args.validation_way,
                                      -1).mean(dim=0)

            logits = euclidean_metric(self.encoder(data_query),
                                      proto) / self.args.temperature
        return logits
Ejemplo n.º 2
0
    def forward(self, data_shot, data_query):
        if self.args.hyperbolic:
            proto = self.encoder(data_shot)

            if self.training:
                proto = proto.reshape(self.args.shot, self.args.way, -1)
            else:
                proto = proto.reshape(self.args.shot, self.args.validation_way,
                                      -1)

            proto = poincare_mean(proto, dim=0, c=self.encoder.get_c())
            data_query = self.encoder(data_query)
            logits = -dist_matrix(data_query, proto, c=self.encoder.get_c()
                                  ) / self.args.temperature

        else:
            print('Does not support non-hyperbolic!')
        return logits