Пример #1
0
    def _setup(self):
        h, w = self.face_size

        self.x = sm.Tensor()
        self.mask = sm.Tensor()
        self.feat, ho, wo, co = vgg16(self.x, h, w)
        self.embed = facenet_head(self.feat, ho, wo, co)
        self.loss, self.dis = facenet_loss(self.embed, self.alpha, self.mask)
Пример #2
0
def _check_validity():
    """Check the validity of vgg16 in smnet."""
    lr = 1
    epoch = 10000
    alpha = 0.5
    n = 4 * 3
    h, w = 128, 128
    x = sm.Tensor()
    mask = sm.Tensor()
    feat, ho, wo, co = vgg16(x, h, w)
    embed = facenet_head(feat, ho, wo, co)
    loss = facenet_loss(embed, alpha, mask)

    # data in host.
    dataHs, maskHs = [], []
    dataH = np.random.normal(0, 1, (n, h, w, 3))
    maskH = np.zeros([n // 3, 1])
    for _ in range(epoch):
        dataHs.append(dataH)
        maskHs.append(maskH)

    # smnet
    featHs, embedHs, lossHs = [], [], []
    for _ in range(epoch):
        featH, embedH, lossH = sm.forward([feat, embed, loss],
                                          feed_dict={
                                              x: dataHs[_],
                                              mask: maskHs[_]
                                          })
        loss_sum = np.sum(lossH)
        sm.optimize([loss], lr=lr)
        featHs.append(featH)
        embedHs.append(embedH)
        lossHs.append(loss_sum)
        print(_, loss_sum)

    print(featHs)
    print()
    print(embedHs)
    print()
    print(lossHs)
Пример #3
0
 def _setup(self):
     """Prebuild the onet network."""
     self.x = sm.Tensor()
     self.gt_conf = sm.Tensor()
     self.gt_box = sm.Tensor()
     self.gt_landmark = sm.Tensor()
     self.conf_mask = sm.Tensor()
     self.box_mask = sm.Tensor()
     self.landmark_mask = sm.Tensor()
     self.conf, self.box, self.landmark = onet(self.x)
     self.conf_loss, self.box_loss, self.landmark_loss = onet_loss(
         self.conf, self.box, self.landmark, self.gt_conf, self.gt_box,
         self.gt_landmark, self.conf_mask, self.box_mask,
         self.landmark_mask)