chenhsuanlin / spatial-transformer-GAN

ST-GAN: Spatial Transformer Generative Adversarial Networks for Image Compositing :eyeglasses: (CVPR 2018)
MIT License
334 stars 72 forks source link

Please, how to implement PiecewiseAffine. #31

Closed taeubahk closed 4 years ago

taeubahk commented 4 years ago

I want to divide the FG image into 64(or 32) pieces, and perform affine transformation on each piece of the image.

To implement PiecewiseAffine, how do I fix the warp.py and graph.py code?

chenhsuanlin commented 4 years ago

I assume you're talking about warping with a 2D mesh. This would probably involve more than just a couple of lines' change of code, but here's a high-level idea: your p would predict the translation of the number of vertices you have (i.e. dimension of p would be 2N). You probably don't need to change anything in graph.py except for making sure that p is update by dp via addition. In warp.py the transformImage/transformCropImage functions should take the resulting pMtrx's and warp each pixel coordinates according to your defined mesh warps. Tensorflow seems to have its own built-in op for image warping now, so you could also consider replacing my hard-coded image warping functions with that. Hope this helps! Let me know if you have more questions.

taeubahk commented 4 years ago

It is too difficult for me... How about changing lines 30 and 48 of /glasses/graph.py to be the same as below?


for j in range(0, HEIGHT_SIZE, GIRD_SIZE): # GIRD_SIZE is Piese size for i in range(0, WIDTH_SIZE, GIRD_SIZE): cropped = warp.transformImage(opt, imageFG[:, j:j+GIRD_SIZE, i:i+GIRD_SIZE, :], pMtrx, GIRD_SIZE, GIRD_SIZE) tf.assign(imageFGwarp[:, j:j+GIRD_SIZE, i:i+GIRD_SIZE, :], cropped)


Warping each part(gird, piese) of the image using one warp.transformImage It is a method of compositing with a background image.

Of course, it is desirable to learn warp parameters for each grid. In this case, since the number of warp and GAN generators increases proportionally, implementation will be difficult and inefficient.

chenhsuanlin commented 4 years ago

There are ways to parallelize your operation without using for loops, which would involve some smart indexing. Also there should be nothing limiting you from predicting several warp parameters with a single generator.