data.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:inverse-compositional-STN 作者: ericlin79119 项目源码 文件源码
def genPerturbations(opt):
    with tf.name_scope("genPerturbations"):
        X = np.tile(opt.canon4pts[:,0],[opt.batchSize,1])
        Y = np.tile(opt.canon4pts[:,1],[opt.batchSize,1])
        dX = tf.random_normal([opt.batchSize,4])*opt.pertScale \
            +tf.random_normal([opt.batchSize,1])*opt.transScale
        dY = tf.random_normal([opt.batchSize,4])*opt.pertScale \
            +tf.random_normal([opt.batchSize,1])*opt.transScale
        O = np.zeros([opt.batchSize,4],dtype=np.float32)
        I = np.ones([opt.batchSize,4],dtype=np.float32)
        # fit warp parameters to generated displacements
        if opt.warpType=="homography":
            A = tf.concat([tf.stack([X,Y,I,O,O,O,-X*(X+dX),-Y*(X+dX)],axis=-1),
                           tf.stack([O,O,O,X,Y,I,-X*(Y+dY),-Y*(Y+dY)],axis=-1)],1)
            b = tf.expand_dims(tf.concat([X+dX,Y+dY],1),-1)
            pPert = tf.matrix_solve(A,b)[:,:,0]
            pPert -= tf.to_float([[1,0,0,0,1,0,0,0]])
        else:
            if opt.warpType=="translation":
                J = np.concatenate([np.stack([I,O],axis=-1),
                                    np.stack([O,I],axis=-1)],axis=1)
            if opt.warpType=="similarity":
                J = np.concatenate([np.stack([X,Y,I,O],axis=-1),
                                    np.stack([-Y,X,O,I],axis=-1)],axis=1)
            if opt.warpType=="affine":
                J = np.concatenate([np.stack([X,Y,I,O,O,O],axis=-1),
                                    np.stack([O,O,O,X,Y,I],axis=-1)],axis=1)
            dXY = tf.expand_dims(tf.concat([dX,dY],1),-1)
            pPert = tf.matrix_solve_ls(J,dXY)[:,:,0]
    return pPert

# make training batch
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号