def __init__(self):
     super(TouchEmbNet2DML, self).__init__()
     self.touch_net = Feat2d(hyp.touch_emb_dim)
     self.num_samples = hyp.emb_2D_touch_num_samples
     assert (self.num_samples >
             0), "num samples should be greater than zero"
     self.batch_k = 2
     self.sampler = utils_misc.DistanceWeightedSampling(
         batch_k=self.batch_k, normalize=False)
     self.criterion = utils_misc.MarginLoss()
     self.beta = 1.2
Exemple #2
0
    def __init__(self):
        super(EmbNet2D, self).__init__()

        print('EmbNet2D...')
        self.batch_k = 2
        self.num_samples = hyp.emb_2D_num_samples
        assert (self.num_samples > 0)
        self.sampler = utils_misc.DistanceWeightedSampling(
            batch_k=self.batch_k, normalize=False)
        self.criterion = utils_misc.MarginLoss(
        )  #margin=args.margin,nu=args.nu)
        self.beta = 1.2
Exemple #3
0
    def __init__(self):
        super(TriNet2D, self).__init__()

        print('TriNet2D...')
        self.batch_k = 2
        self.num_samples = hyp.tri_2D_num_samples
        assert (self.num_samples > 0)
        self.sampler = utils_misc.DistanceWeightedSampling(
            batch_k=self.batch_k, normalize=False)
        self.criterion = utils_misc.MarginLoss(
        )  #margin=args.margin,nu=args.nu)
        self.beta = 1.2

        self.dict_len = 20000
        self.neg_pool = utils_misc.SimplePool(self.dict_len)
        self.ce = torch.nn.CrossEntropyLoss()
Exemple #4
0
    def __init__(self):
        """The idea is here the featnet would be frozen, and using some X number
           of images it will form the features for the object, which will be used
           to get the closeby embeddings to learn metric learning
        """
        super(TouchEmbed2D, self).__init__()
        if hyp.do_feat:
            print('using the visual feat net to generate visual feature tensor')
            self.featnet = FeatNet(input_dim=4)  # passing occXs and occXs * unpXs

        if hyp.do_touch_feat:
            print('using 2d backbone network to generate features from sensor depth image')
            self.backbone_2D = VGGNet.Feat2d(touch_emb_dim=hyp.feat_dim, do_bn=hyp.do_bn)
            # if I need to add the 3d encoder decoder I need to add the next line
            # self.touch_featnet = FeatNet(input_dim=1)  # just passing occRs here

        if hyp.do_touch_forward:
            # now here I need to pass this through the bottle3d architecture to predict
            # 1-d vectors
            print('using context net to turn 3d context grid into 1d feature tensor')
            self.context_net = bottle3D.Bottle3D(in_channel=hyp.feat_dim,\
                pred_dim=hyp.feat_dim)

        if hyp.do_touch_occ:
            print('this should not be turned on')
            from IPython import embed; embed()
            self.touch_occnet = OccNet()

        # if hyp.do_touch_embML:
        #     self.touch_embnet3D = EmbNet3D()  # metric learning for making touch feature tensor same as visual feature tensor

        if hyp.do_freeze_feat:
            print('freezing visual features')
            self.featnet = self.featnet.eval()
            assert self.featnet.training == False, "since I am not training FeatNet it should be false"

        if hyp.do_freeze_touch_feat:
            print('freezing backbone_2D')
            self.backbone_2D = self.backbone_2D.eval()

        if hyp.do_freeze_touch_forward:
            print('freezing context net')
            self.context_net = self.context_net.eval()

        # hyperparams for embedding training not really needed as of now
        if hyp.do_touch_embML:
            print('Instantiating Contrastive ML loss')
            self.num_pos_samples = hyp.emb_3D_num_samples
            self.batch_k = 2
            self.n_negatives = 1
            assert (self.num_pos_samples > 0)
            self.sampler = utils_misc.DistanceWeightedSampling(batch_k=self.batch_k, normalize=False,
                num_neg_samples=self.n_negatives)
            self.criterion = utils_misc.MarginLoss()
            self.beta = 1.2

        if hyp.do_moc or hyp.do_eval_recall:
            print('Instantiating MOC net')
            self.key_touch_featnet = VGGNet.Feat2d(touch_emb_dim=hyp.feat_dim,\
                do_bn=hyp.do_bn)
            key_weights = self.backbone_2D.state_dict()
            self.key_touch_featnet.load_state_dict(key_weights)

            self.key_context_net = bottle3D.Bottle3D(in_channel=hyp.feat_dim,\
                pred_dim=hyp.feat_dim)
            key_context_weights = self.context_net.state_dict()
            self.key_context_net.load_state_dict(key_context_weights)

            # check that the two networks indeed have the same weights
            p1 = get_params(self.backbone_2D)
            p2 = get_params(self.key_touch_featnet)
            assert check_equal(p1, p2),\
                "initially both the touch networks should have same weights"

            cp1 = get_params(self.context_net)
            cp2 = get_params(self.key_context_net)
            assert check_equal(cp1, cp2),\
                "initially both the context networks should have same weights"

            self.moc_ml_net = MOCTrainingTouch(dict_len=hyp.dict_len,\
                num_neg_samples=hyp.num_neg_samples)