コード例 #1
0
ファイル: preprocess.py プロジェクト: Chenzhoujia/Graph_hand
    def fn(elem):
        dm, cfg, com = elem[0], elem[1], elem[2]

        zz = tf.squeeze(dm, axis=-1)
        min_depth = com[2] - D_RANGE * 0.5
        max_depth = com[2] + D_RANGE * 0.5
        zz = tf.where(tf.less(zz, -0.99),
                      tf.ones_like(zz) * max_depth,
                      tf.multiply(zz, D_RANGE) + min_depth)

        xx, yy = tf.meshgrid(tf.range(h), tf.range(w))
        xx = tf.to_float(xx)
        yy = tf.to_float(yy)

        w_ratio = cfg[4] / w
        h_ratio = cfg[5] / h
        new_cfg = CameraConfig(cfg[0] / w_ratio, cfg[1] / h_ratio,
                               cfg[2] / w_ratio, cfg[3] / h_ratio, w, h)

        xx = tf.multiply(xx - new_cfg[2], tf.divide(zz, new_cfg[0]))
        yy = tf.multiply(yy - new_cfg[3], tf.divide(zz, new_cfg[1]))

        # renormalize the points as normalizing the pose
        xx = tf.divide(xx - com[0], POSE_NORM_RATIO)
        yy = tf.divide(yy - com[1], POSE_NORM_RATIO)
        zz = tf.divide(zz - com[2], POSE_NORM_RATIO)

        xyz = tf.stack([xx, yy, zz], axis=-1)
        return [xyz, cfg, com]
コード例 #2
0
 def to_uvd_fn(elem):
     xyz_pt, cfg = elem[0], elem[1]
     return [
         data.util.xyz2uvd_op(xyz_pt,
                              CameraConfig(*tf.unstack(cfg, axis=0))),
         cfg
     ]
コード例 #3
0
        def fn(elems):
            xyz_pose, cfg = elems[0], elems[1]

            w_ratio = cfg[4] / out_w
            h_ratio = cfg[5] / out_h
            new_cfg = CameraConfig(cfg[0] / w_ratio, cfg[1] / h_ratio,
                                   cfg[2] / w_ratio, cfg[3] / h_ratio, out_w,
                                   out_h)

            xx, yy = tf.meshgrid(tf.range(out_h), tf.range(out_w))
            xx, yy = tf.cast(xx, tf.float32), tf.cast(yy, tf.float32)
            xx = tf.tile(tf.expand_dims(xx, axis=-1), [1, 1, self._jnt_num])
            yy = tf.tile(tf.expand_dims(yy, axis=-1), [1, 1, self._jnt_num])

            uvd_pose = tf.reshape(data.util.xyz2uvd_op(xyz_pose, new_cfg),
                                  (-1, 3))
            [uu, vv, dd] = tf.unstack(uvd_pose, axis=-1)
            uu = tf.reshape(uu, (1, 1, -1))
            vv = tf.reshape(vv, (1, 1, -1))

            hm = tf.maximum(
                self.max_dist_2d -
                tf.sqrt(tf.square(xx - uu) + tf.square(yy - vv)),
                tf.zeros_like(xx)) / self.max_dist_2d
            return [hm, cfg]
コード例 #4
0
        def fn(elems):
            xyz_pt, com, cfg, hm, dm = elems[0], elems[1], elems[2], elems[
                3], elems[4]

            xx, yy, zz = tf.unstack(tf.reshape(xyz_pt, (-1, 3)), axis=-1)
            xyz_pt = tf.reshape(xyz_pt, (-1, ))

            xyz_pt = tf.multiply(xyz_pt,
                                 data.preprocess.POSE_NORM_RATIO) + tf.tile(
                                     com, [jnt_num * pnt_num])
            xyz_pt = tf.reshape(xyz_pt, (-1, 3))

            w_ratio = cfg[4] / out_w
            h_ratio = cfg[5] / out_h
            new_cfg = CameraConfig(cfg[0] / w_ratio, cfg[1] / h_ratio,
                                   cfg[2] / w_ratio, cfg[3] / h_ratio, out_w,
                                   out_h)
            uvd_pt = xyz2uvd_op(xyz_pt, new_cfg)
            uvd_pt = tf.reshape(uvd_pt, (-1, 3))
            uu, vv, dd = tf.unstack(uvd_pt, axis=-1)
            uu = tf.to_int32(uu + 0.5)
            vv = tf.to_int32(vv + 0.5)
            jj = tf.tile(tf.expand_dims(tf.range(jnt_num), axis=-1),
                         [1, pnt_num])
            jj = tf.reshape(jj, (-1, ))

            indices = tf.stack([vv, uu, jj], axis=-1)
            weights = tf.gather_nd(hm, indices)
            weights = tf.reshape(weights, (jnt_num, pnt_num, 1))

            #we also clip the values of depth
            dm = tf.squeeze(dm)
            dm = tf.divide(
                dm * data.preprocess.D_RANGE - data.preprocess.D_RANGE * 0.5,
                data.preprocess.POSE_NORM_RATIO)
            indices = tf.stack([vv, uu], axis=-1)
            od = tf.gather_nd(dm, indices)
            zz = tf.maximum(zz, od)
            xyz_pt = tf.stack([xx, yy, zz], axis=-1)
            xyz_pt = tf.reshape(xyz_pt, (jnt_num, pnt_num, 3))

            return [weights, xyz_pt, cfg, hm, dm]